Option Menu with Database - view description but save id

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
LAZ
Posts: 6
Joined: Mon Jan 21, 2008 4:45 pm

Option Menu with Database - view description but save id

Post by LAZ » Mon Jan 21, 2008 5:13 pm

Your starter for ten :) :
I have an Option Menu (on a card holding product data) and I have scripted the 'description' field from a database table to appear in it so that the user gets a list of (in this case) colours. When the user saves the product, I want to save the id for the colour they have chosen, NOT the description they saw. At the moment I achieve this by reading the database to populate the colour descriptions, then taking the colour selected by the user and finding it in the colours database table (again), then saving the associated id. Q. Is there a cleaner way of doing this to avoid this extra read of the database?

Many thanks in advance for any suggestions.
P.S. Be gentle with me as I am but a tender Revolution Newbie :)

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Thu Jan 24, 2008 8:15 pm

When you read the data from the database table create two CR delimited lists. One for the color names and one for the color ids.

Some psuedo code to illustrate:

Code: Select all

repeat for each record theRecord in the cursor
    put the colorName of theRecord & CR after theColors
    put the colorID of theRecord & CR after theIDs
end repeat
delete the last char of theColors
delete the last char of theIDs
Now assign the colors to the text of the option menu (like you are already doing) and assign the ids to a custom property of the option menu.

Code: Select all

set the text of button "MyOptionMenu" to theColors
set the uColorIDs of button "MyOptionMenu" to theIDs
At this point you can now determine the id of the selected color by using the menuhistory property of the button.

put the menuhistory of button "MyOptionMenu" into theSelectedLine
put line theSelectedLine of the uColorIDs of button "MyOptionMenu" into theSelectedID.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LAZ
Posts: 6
Joined: Mon Jan 21, 2008 4:45 pm

Post by LAZ » Fri Jan 25, 2008 6:00 pm

:D
Many thanks Trevor ..... that hit the nail right on the head and worked an absolute treat.
Cheers
LAZ
(If you listen carefully, you can hear the soft purring sound of a contented Revolution Newbie)

Post Reply