Closed Thread Icon

Preserved Topic: Loop and array problem(vb6) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13089" title="Pages that link to Preserved Topic: Loop and array problem(vb6) (Page 1 of 1)" rel="nofollow" >Preserved Topic: Loop and array problem(vb6) <span class="small">(Page 1 of 1)</span>\

 
mtjan
Nervous Wreck (II) Inmate

From:
Insane since: Mar 2004

posted posted 03-16-2004 01:57

Hi, I am nubie, guys. Big hi for everybody.
I have just started learning vb6.
I have got a little problem but I cannot get the solution.
Please help me.

I have 5 text box in the form. I made them array(i). There are 5 text boxes. I want to multiplie all the text box and
want to get the answer into label. What I did is below.

Private Sub Command1_Click()
Dim i As Single
Dim a(4) As Single
Dim ans As Single

For i = 0 To 4

a(i) = Val(Text1(i).Text)
'ans = ans + a(i)

ans = ans * a(i)

Next

Label1.Caption = CStr(ans)
End Sub

But some reason, all the time showing 0 into answer box.
I dont know why. I got right when I add like

ans = ans + a(i)

please help me.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-16-2004 02:16

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

mtjan
Nervous Wreck (II) Inmate

From:
Insane since: Mar 2004

posted posted 03-16-2004 03:13

Hi, InI. Many thanks.
I have just figured it out.
Have a good day.
Matane.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-16-2004 03:19

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

mtjan
Nervous Wreck (II) Inmate

From:
Insane since: Mar 2004

posted posted 03-16-2004 03:36

Hi, again. it is middle of the night? I envy you cuz I want to sleep more.
Anway, can I ask a&#12288;bit more, please?
I want user to enter all the array text box. If there is empty box, I want to show massage box like:
Please enter all the boxes.
I wrote the code like below:

Private Sub Command1_Click()
Dim i As Single
Dim a(4) As Single
Dim ans As Single


ans = 1
For i = 0 To 4

a(i) = Val(Text1(i).Text)

If Text1(i).Text = "" Then

MsgBox " Enter the number"

End If

ans = ans * a(i)

Debug.Print a(i)

Next

End Sub

But of course my if statement runs 5 time cuz it is inside of the loop. But if I write if statement to outside of the loop, counter i does not run. Do you know what I mean? How can I solve this pro? Can you give me a clue, please???

Tasuke, Motomu.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-16-2004 09:15

not knowing much vb,
you should dim a boolean outside the loop,
set it to true.
then check all the textboxes in the loop, set the boolean to false if one isn't filled in (You could use the boolean and operator for that... but I feel you're not that far yet).
After the loop, you'll need to do a 'if not myBoolean then showErrorDialog'.

mtjan
Nervous Wreck (II) Inmate

From:
Insane since: Mar 2004

posted posted 03-17-2004 01:18

Hi, glad to hear from you.
Yes. I got it.
Thanks.

« BackwardsOnwards »

Show Forum Drop Down Menu