PDA

View Full Version : Combobox problems? doh!



mrdude
03-02-2010, 02:08 PM
Ok sorry about this noob question but it's been a long time since I used apms.

I have a combo box with 15 items and the item data is numbered 1,2,3 etc.

this code is not working for me:



result = ComboBox.GetSelected("ComboBox1");
data = ComboBox.GetItemData("ComboBox1", result);

if data == 1 then
result = Dialog.Message("Notice", "Your message here1.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif == 2 then
result = Dialog.Message("Notice", "Your message here2.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end

Any idea why it's not working? - obviously i have missed out 3-15 but you get the gist.

RizlaUK
03-02-2010, 02:54 PM
maybe ?


result = ComboBox.GetSelected("ComboBox1");
data = ComboBox.GetItemData("ComboBox1", result);

if data == 1 then
result = Dialog.Message("Notice", "Your message here1.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif data == 2 then
result = Dialog.Message("Notice", "Your message here2.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end

Scriptonite
03-02-2010, 03:00 PM
well unless your data is numbers, you would want




result = ComboBox.GetSelected("ComboBox1");
data = ComboBox.GetItemData("ComboBox1", result);

if result == 1 then
result = Dialog.Message("Notice", "Your message here1.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif result == 2 then
result = Dialog.Message("Notice", "Your message here2.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end



If your data is numbers you need:




result = ComboBox.GetSelected("ComboBox1");
data = ComboBox.GetItemData("ComboBox1", result);

if result == "1" then
result = Dialog.Message("Notice", "Your message here1.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif result == "2" then
result = Dialog.Message("Notice", "Your message here2.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end



AMS returns the data as a string, it doesn't know it's a number. You can use the String.ToNumber() function as well.

RizlaUK
03-02-2010, 04:23 PM
Doh, how did i miss that, im slipping!

this WILL work (apply some lua)

result = ComboBox.GetSelected("ComboBox1");
data = tonumber(ComboBox.GetItemData("ComboBox1", result));

if data == 1 then
result = Dialog.Message("Notice", "Your message here1.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif data == 2 then
result = Dialog.Message("Notice", "Your message here2.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end

mrdude
03-03-2010, 02:11 PM
Thanks for the information guys, I'll give those a try.

Cheers. :yes