how to: insert items into a drop-down box using transcript
Jeanne A. E. DeVoto
revolution at jaedworks.com
Fri May 13 01:39:14 EDT 2005
At 3:56 PM -0600 5/12/05, Emilio Gagliardi wrote:
>Greetings revolution programmers,
>I hope that someone can point me in the right direction of some
>examples or tutorials that demonstrate how to use transcript to add
>items to a drop down list based on some variable. For example, on
>PreOpenCard reads the directories where the application is currently
>loaded and then generates a drop-down list with items that match the
>available directories.
>
>I've flipped through Dan's book, the documentation (which appears to
>not have any code examples), the online tutorials, and google and
>not found anything. Any help is greatly appreciated.
(Quoting here):
----------
How to change the items in a button menu:
You change the menu items in a button menu by changing the contents
of the button associated with the menu. Each line in the button's
contents is used as a menu item in the menu.
You can either use the put command in a handler or the message box,
or use the Basic Properties pane in the button's property inspector
to change the button's contents. The following statement changes a
button's contents to give it two menu items:
put "First" & return & "Last" into button "My Menu"
Tip: You can also set the button's text property: setting the text
of a button to a string is equivalent to putting the string into the
button.
How to get the contents of a folder:
You get the contents of a folder from within a handler using the
files and folders functions.
The files function returns a list of files in the defaultFolder,
while the folders function returns a list of folders in the
defaultFolder. The combination of these lists is the contents of the
defaultFolder.
First, set the defaultFolder to the pathname of the folder whose
contents you want to list. Then use the files and folders functions
to get the list:
set the defaultFolder to "/Hard Disk/My Folder/"
put the files & return & the folders into myContents
----------
To sum up:
on preOpenCard
put the folders into button "My Menu"
end preOpenCard
should do what you want, assuming your option menu's name is "My
Menu". (There are some nuances on OS X systems because of the way
applications are bundled as folders; basically, if you're on OS X you
need to 'set the defaultFolder to "../"' sometime before calling the
folders function.)
--
jeanne a. e. devoto ~ revolution at jaedworks.com
http://www.jaedworks.com
More information about the use-livecode
mailing list