|
-
Oct 8th, 2006, 06:19 AM
#1
Thread Starter
Fanatic Member
Arrays
Take a look in my first image named a.jpg ... there is my question ....
And This is my second question realting in my second image named b.jpg
what statement should i use to determine if a number is ( - ) negative go to the next cotrol array ... i mean ... like in my image b.jpg .... as you can see there is a numbers appear in my control array ... what statement should i use finding a positive number ... like this ... uhm ... the program must test if number of txtA(0) = ( - ) negative go to the next array which is txtA(1) if txtA(1) = still a ( - ) negative number go to next array which is txtA(2) if txtA(2) is not a negative number stop ... sorry in my english ... thank you in advance
txtA(0) = -1
txtA(1) = -1
txtA(2) = 2
Last edited by Loraine; Oct 8th, 2006 at 07:06 AM.
-
Oct 8th, 2006, 06:23 AM
#2
Re: Arrays
Try
VB Code:
Dim pos As Long
pos = LBound(txtA)
'Do Until (Val(txtA(pos)) >= 0 Or pos > Ubound(txtA))
'my bad an error can occur since Val(txtA(pos)) can't be tested when pos > Ubound(txtA)
Do Until pos > UBound(txtA) 'updated
If Val(txtA(pos)) >= 0 Then Exit Do
pos = pos + 1
Loop
If pos <= Ubound(txtA) Then Msgbox "stopped at txtA(" & pos & ") "
Last edited by leinad31; Oct 8th, 2006 at 06:32 AM.
-
Oct 8th, 2006, 06:27 AM
#3
Re: Arrays
BTW, where are the images?
-
Oct 8th, 2006, 08:42 AM
#4
Thread Starter
Fanatic Member
-
Oct 8th, 2006, 09:03 AM
#5
Re: Arrays
Ahhh I see its a control array. To add
VB Code:
Dim cnt As Integer
Dim Sum As Double
Sum = 0
For cnt = txtA.LBound To txtA.UBound
Sum = Sum + Val(txtA(cnt).Text)
Next
Text1.Text = Sum
Code in previous post for your 2nd question needs to be updated... it had assumed a string array but your using a control array. I'll leave the research on that (compare with recent code) to you.
Pretty avatar
-
Oct 8th, 2006, 09:08 AM
#6
Thread Starter
Fanatic Member
Re: Arrays
In my second question is this right ?
Dim pos As Long
Dim arr(4) As Integer
Dim i As Integer
pos = LBound(arr)
'Do Until (Val(txtA(pos)) >= 0 Or pos > Ubound(txtA))
'my bad an error can occur since Val(txtA(pos)) can't be tested when pos > Ubound(txtA)
Do Until pos > UBound(arr) 'updated
If Val(txtA(pos)) >= 0 Then Exit Do
pos = pos + 1
Loop
If pos <= UBound(arr) Then
Text1.Text = Val(txtA(i).Text) + Val(txtA(i).Text)
End If
-
Oct 8th, 2006, 09:16 AM
#7
Re: Arrays
You don't need arr() since your using txtA control array as list source.
pos = txtA.LBound
Ubound(txtA) should be txtA.UBound
The last statement (Text1.Text = ... ) is confusing cause you never mentioned you needed a sum, you said you only needed to determine which control array textbox has a positive number.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|