View previous topic :: View next topic |
Author |
Message |
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Wed Mar 14, 2018 8:54 am Post subject: How to read/write in the combobox? |
|
|
How to read from address to CEComboBox1? For example:
3 items in the CEComboBox1:
None
Sadness
Fury
If value in the address == 0x00, then first item "None" must be selected.
If value in the address == 0x10, then second item "Sadness" must be selected.
If value in the address == 0x20, then third item "Fury" must be selected.
Second question: How to write to address from CEComboBox1? For example:
If first item "None" selected in the CEComboBox1, then write value 0x00 to the address.
If second item "Sadness" selected in the CEComboBox1, then write value 0x10 to the address.
If third item "Fury" selected in the CEComboBox1, then write value 0x20 to the address.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Wed Mar 14, 2018 1:40 pm Post subject: |
|
|
something like
Code: | -- create for example
UDF1 = CreateForm()
CEComboBox1 = createComboBox(UDF1)
CEComboBox1.clear()
CEComboBox1.Items.Add('None')
CEComboBox1.Items.Add('Sadness')
CEComboBox1.Items.Add('Fury')
-- prepend formname. for non-code generated forms
-- eg CETrainer.CEComboBox1...
local addr = 0x400290
-- reads once, need in timer if you want to continuously read
local val = readInteger(addr)
if val == 0 then
CEComboBox1.ItemIndex = 0
elseif val == 0x10 then
CEComboBox1.ItemIndex = 1
else
CEComboBox1.ItemIndex = 2
end
-- setup event handler to write whenever combobox changes
CEComboBox1.OnChange = function(sender)
local values = {[0]=0, [1]=0x10, [2]=0x20}
--fullAccess(addr,4) -- if readonly, make writable
writeInteger(addr, values[sender.ItemIndex])
-- more generically, works for any type not just 4 byte
--getAddressList().getMemoryRecordByDescription('the desc.').Value = values[sender.ItemIndex]
end |
_________________
|
|
Back to top |
|
|
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Wed Mar 14, 2018 3:30 pm Post subject: |
|
|
FreeER wrote: | something like |
If write, whenever combobox changes, by method:
Code: | UDF1.CEComboBox1.onChange = function(sender)
local _value = { 0x00, 0x10, 0x20 }
writeInteger('addr',_value[sender.ItemIndex])
end |
Then, how to read by similar method? Without using "If" and with using table "local _value = { 0x00, 0x10, 0x20 }".
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Wed Mar 14, 2018 6:54 pm Post subject: |
|
|
To constantly read from the address and update the combobox you'd need a timer (or use the OnGetDisplayValue "event" on a memory record but without a memory record that's not an option) eg.
Code: | local t = createTimer()
t.Interval = 100 -- 1/10th of a second
t.OnTimer = function(timer)
--need in timer if you want to continuously read
local val = readInteger(addr)
if val == 0 then
CEComboBox1.ItemIndex = 0
elseif val == 0x10 then
CEComboBox1.ItemIndex = 1
else
CEComboBox1.ItemIndex = 2
end
end
|
Though you could also use a table there eg.
Code: | local values = {[0x0]=0, [0x10]=1, [0x20]=2}
-- defaults to last if not in table
CEComboBox1.ItemIndex = values[val] or CEComboBox1.Items.Count-1
|
Though with these specific value you could also simply divide by 0x10
_________________
|
|
Back to top |
|
|
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Thu Mar 15, 2018 10:44 am Post subject: |
|
|
Thanks for the help.
|
|
Back to top |
|
|
|