Re: Variable substitution
- Posted by Mike <vulcan at w?n.co?nz> Dec 12, 2007
- 558 views
Mike777 wrote: > > I have read a few threads on variable substitution, but they all seem to > predate > v3.1.1. Has the ability been added? If not, is there a common way to > implement > it? > > I'm trying to develop of database driven windowing system. That means I read > from my database the information I need in order to build windows and widgets. > > A simple example might be that I go to the database to find that I want to > build > a combo box and that the name of the combo box should be "Combo1". > > If I was positioning the combo myself in the IDE, it might generate the > following: > > global constant Combo1 = createEx( Combo, "", Window1, 432, 76, 588, 28*6, > PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, > 0 ) > > After I read the database, I have two variables, say TYPEOFWIDGETTOBUILD, > which > has the value "Combo" and NUMBEROFWIDGETTOBUILD, which has the value "1" > > Is there any way to write something like: > > global constant &TYPEOFCOMOBOTOBUILD&NAMEOFWIDGETTOBUILD = createEx( Combo, > "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) > > If that can't be done, can somebody suggest a workaround? > > Thanks > > Mike What you seem to be trying to do will entail building a file that contains the correct text. You need to output a text string having the desired values. Eg,
sequence text text = "global constant " & TYPEOFCOMOBOTOBUILD&NUMBEROFWIDGETTOBUILD This (as you know) evaluates to "global constant Combo1" You can use a function like sprintf() to format certain values (such as control dimensions etc..), eg: constant height = 100, width = 200 text = sprintf( "Window, %d, %d" {width, height}) ..becomes "Window, 200, 100" Another example: text = sprintf( "global constant %s%s = create( %s, \"\", Window1, %d, %d)", {TYPEOFCOMOBOTOBUILD, NUMBEROFWIDGETTOBUILD, TYPEOFCOMOBOTOBUILD, width, height} ) text is now "global constant Combo1 = create( Combo, "", Window1, 200, 100)" And then there is printf() which is the same as sprintf() but also outputs the string to a file. If you create the text string separately you can use puts() to output it to a file, eg: puts(file_id, text) Dont forget the line terminator, eg: puts(file_id, text & '\n')
HTH, Mike