For "i" am loopy 
Author Message
 For "i" am loopy

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



Sun, 19 Sep 2004 00:28:24 GMT  
 For "i" am loopy


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.


Sun, 19 Sep 2004 11:26:14 GMT  
 For "i" am loopy

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.



Mon, 20 Sep 2004 01:43:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. "Where am I?" in VB

2. datepart("h", mytime), problem with AM and PM

3. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

4. GetObject("","InternetExplorer.Application") fails in Excel VBA

5. SysCmd 603, "path","path"

6. Disabling "BACK"/"FORWARD" buttons

7. Loop print "VARIABLE", "VARIABLE"

8. DLL or something like "#"#ยค#"!"#

9. Disabling "BACK"/"FORWARD" buttons

10. CreateObject("Excel","//server"), MsgBox output

11. Problem With "window.showmodaldialog("")"

12. CreateObject("Excel","//server"), MsgBox output

 

 
Powered by phpBB® Forum Software