Quote:
> > How do I write a For loop so I can retrieve a new value from the user on
> > each iteration without using an input box? The user has to answer several
> > questions and I would like the input to be via a text box on the form.
> > Many thanks,
> > Kevin
> I don't think I would use a for loop. If you want to use the same form and
> the same textbox and label you could declare a static variable as a counter
> and change the label each time the user pressed the enter button and store
> the answers in a static array(mmmmhhh I've never tried a static array
> before, it might not work!)Of course, the easiest thing to do would be to
> make labels and textboxes for each question, but I'm sure you've thought of
> that already.
set up form with a Label a textbox and a command button
dim command_button as boolean ' in declarations section
sub run_questions()
dim myquestion(10) as string ' dim array of 10 elements each a string
dim myanswer(10) as string ' array for answers
for q = 1 to 10
commandbutton = false
label1.caption = myquestion(q) ' display new question and clear answer
box
label1.refresh
text1.text = ""
text1.refresh
do with events until commandbutton ' loop until command_click event
loop
myanswer(q) = text1.text
next
end sub
sub command_click
commandbutton = true
end sub
You will need to check the exact syntax for all of this.
There are better ways.
for example
in declarations section define counter and arrays
dim qnum as integer
dim myquestion(10) as string ' dim array of 10 elements each a string
dim myanswer(10) as string ' array for answers
sub form_load()
qnum = 1
label1.caption = myquestion(qnum)
text1.text = ""
end sub
sub command_click()
myanswer(qnum) = text1.text
qnum = qnum +1
label1.caption = myquestion(qnum)
text1.text = "" ' clear answer box
end sub
if you want a more general test program put your questions into a file
, setup an answer file - give each user an id code to enter at the
start, and write the answers to a file (append).
Then you can test for end-of-file to terminate the testing.