Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Can this be done?

 [1/3] from: Steven::White::ci::bloomington::mn::us at: 23-Apr-2003 10:01


I see a deficiency in the REBOL documenatation. It is possible to find out what a given function does, but it is hard to go in reverse, to find out which function to use to execute a given idea. I want to write a function that will pop up an alert box with text based on a message number that is passed to the function. The "alert" function will take a data name that identifies its text, but it does not seem to take a data name which identifies the NAME of the text--sort of like double indirect addressing. I have enclosed a sample script that shows what I want to do. The key statement is the "alert" statement. I am wondering if there is some function that can be applied to MSG-ID so that REBOL will evaluate MSG-ID to get the name of the message, and then evaluate the name of the message to get the actual message. Thank you. ##################################### This is a test program to find out how to make an alert box with a variable message. REBOL [ ] ; -- These are the possible message texts that can go ; -- in the alert box. Each is identified by a name ; -- that consists of a literal "MSG-" followed by ; -- a unique three-digit number. ; MSG-001: "This is message number one" MSG-002: "This is message number two" ; -- This function displays an alert box with message ; -- text based on a three-digit number passed to the ; -- function. The function uses the three-digit number ; -- to create a name for the message text, and then ; -- uses that name to get the message text. ; -- (At least, that is the plan, since this does not ; -- work.) SHOWALERT: func [ ; ; -- description of the function and its parameters -- ; "Display alert box with message based on passed message number" MSG-NUMBER [string!] "Message number as three-byte string" ][ ; ; -- the "code" for the function -- ; ; -- Generate the word whose value is the NAME of the desired text ; MSG-ID: append "MSG-" MSG-NUMBER ; ; -- Pop up an alert box containing the desired text. ; -- MSG-ID will evaluate to MSG-nnn where nnn is the message ; -- number. We would like the value of MSG-ID to be evaluated ; -- AGAIN to obtain the text that is the value of the word ; -- that is the value of MSG-ID--a bit of double indirect ; -- addressing. ; alert [ MSG-ID "CLEAR" ] ] SHOWALERT "001" print "Returned from SHOWALERT function" ;###### end of sample script ############## Steven White City of Bloomington 2215 W Old Shakopee Rd Bloomington MN 55431-3096 USA 952-563-4882 (voice) 952-563-4672 (fax) [swhite--ci--bloomington--mn--us]

 [2/3] from: antonr:iinet:au at: 24-Apr-2003 3:05


Try this out:
>> get MSG-ID: to-word append "MSG-" "002"
== "This is message number two" then alert [ get MSG-ID "CLEAR" ] You will need to do your own zero padding. But why not convert the id string to an integer? Can't you put all messages in a block?: id: to-integer "002" msg: [ "message one" "message two" ] alert reduce [pick msg id "clear"] or maybe
>> msg: [001 "message one" 002 "message two"]
== [1 "message one" 2 "message two"]
>> select msg to-integer "002"
== "message two" Anton Rolls.

 [3/3] from: greggirwin:mindspring at: 23-Apr-2003 11:34


Hi Steven, You're close! I stripped out the comments for brevity. You need to turn the string into a word so REBOL can find its value, then use GET to retrieve the value. MSG-001: "This is message number one" MSG-002: "This is message number two" SHOWALERT: func [ "Display alert box with message based on passed message number" MSG-NUMBER [string!] "Message number as three-byte string" ][ MSG-ID: to word! join "MSG-" MSG-NUMBER alert reduce [ rejoin [MSG-ID " - " get msg-id] "CLEAR" ] ] SHOWALERT "001" -- Gregg