DIM an array, making sure it is big enough to hold the items. Use a counter set to zero. Then read in the file, increase the counter by one and put the read in line in the array.
Then in the CREATE (of course I'd use DIM instead) use a loop (for x = 1 to the counter) to add the items from the array.
I regard ANY action needed to set up a form as not deserving a SUB, so after the required definitions (for the SetFocus API call and such) I always start with a bit that reads in needed data. I tend to DIM the form, then a QRichedit to buffer file data, then one by one read files into the rich edit and analyze them.
Only then do I DIM the other form elements (I hate the CREATE method as it doesn't cater for arrays of elements)
Of course I also always add an item index to the start of any file so that I do not need While .... Wend loops.
An example;
DIM RiEd AS QRICHEDIT
RiEd.plaintext = 1
RiEd.visible = 0
RiEd.PARENT = Form
f$ = "filename.extension"
RiEd.Clear
RiEd.LoadFromFile(f$)
a$ = RiEd.Text
NumberOfItems = VAL(MID$(a$,9,8))
DIM ItemName$(NumberOfItems)
ItemName$(0)="--------"
FOR x=1 TO NumberOfItems
beg = x * 33 - 15
ItemName$(x) = MID$(a$,beg,7)
NEXT x
|