1. Re: creating a varible number of objects
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Apr 22, 2004
- 439 views
On Thu, 22 Apr 2004 13:37:45 -0400, michellerogers at bellsouth.net wrote: >I am creating a program in which I want to ask users how many fields they would >like to create. Then, I want to create a text label and an entry box for each >field. I have "racked my brain" and cannot figure out how to make a variable >number of objects. I can easily figure out how to name the objects.. > This is just a cut and paste from my print preview demo. I create 12 buttons in a loop, nicely spaced with a bitmap and caption for each and set up a few sequences for later controlling them. It is not complete or runnable in this format, but it should give you the basic idea: constant WM_HELP = 83, btext= {{"&Tutorial","An automated demonstration of layout creation and print preview"}, {"&Edit Dictionary","Opens datadict.txt using the editor associated with .exw "& "files, or wordpad"}, {"&Load Dictionary","Loads datadict.txt into layouts.edb"}, {"Read The &Manual","Opens printpreview.txt using the editor associated with .exw "& "files, or wordpad"}, {"Report Layout &Designer","Edits \"test\" or selected layout"}, {"&Record Dump","Shows dump of an OH record, see sample datadict.txt"}, {"List Bitmaps &Used","Check all required bitmaps are included in the release, "& "and no absolute pathnames are used."}, {"List Calculated &Fields","Prints a reference sheet of the calculations used."}, {"&Plain Text Print","Prints the source file pptest.exw"}, {"&Column Print","Prints like newspaper columns"}, {"&Booklet Print","Shows the use of pageSequenceHook()"}, {"&Invoice Print","Shows advanced features of the report generator"}}, bitmaps={"tutorial.bmp","dict.bmp","load.bmp","manual.bmp", "design.bmp","dump.bmp","bitmaps.bmp","calc.bmp", "plain.bmp","column.bmp","booklet.bmp","invoice.bmp"}, blen=length(btext) global sequence buttons buttons=repeat(0,blen) global sequence labels labels=repeat(0,blen) sequence bpos bpos=repeat(0,blen) integer xpos, ypos for i=1 to length(buttons) do xpos=floor((i-1)/4)*155+60 -- 60, 215, 370 ypos=remainder(i-1,4)*80+10 -- 10, 90, 170, 250 buttons[i]=create(PictureButton,"",Main,xpos,ypos,55,55,0) bpos[i]={xpos,ypos} setBitmap(buttons[i],spprgdir&"demo\\bitmaps\\"&bitmaps[i]) labels[i]=create(CText,btext[i],Main,xpos-55,ypos+55,160,20,0) end for >for x=1 to NumberOfObjects do > object&sprint(x)=value >end for > >but then again..now that I think about it...that might not work either..can I >make a variable name for a variable like that? heh.. No, you can't do that. Just use a sequence, or several, ie a sequence of ids for the text labels, another for the input field-ids, another for the values, etc. Pete