cdb424ttm
asked on
Array Question
Hi all,
I have code that looks like this.
Let result = term1+term2+term3+term4+te rm5
Print result
My question is this, how would I setup
An array to do the same thing?
Thanks
I have code that looks like this.
Let result = term1+term2+term3+term4+te
Print result
My question is this, how would I setup
An array to do the same thing?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sirbounty
the data is pulled from 5 text boxes but not all the boxes are filled with some thing.
so I want it to loop Through the boxes and count only the ones that have data and pull their value.
the data is pulled from 5 text boxes but not all the boxes are filled with some thing.
so I want it to loop Through the boxes and count only the ones that have data and pull their value.
ASKER
not sure how to set it up to your syntax Eddykt.
I'm somewhat new to arrays
I'm somewhat new to arrays
Take text box 1 and copy paste it to create a control array...
Text1(0) thru Text1(4)
For x = 0 to 4
if text1(x) <> "" then strResults=val(text1(x).te xt) + strResults
next x
msgbox "Answer is " & strResults
Text1(0) thru Text1(4)
For x = 0 to 4
if text1(x) <> "" then strResults=val(text1(x).te
next x
msgbox "Answer is " & strResults
ASKER
Sirbounty,
How would I set a counter to go and loop through and count the number of boxes on the form.
I'm guessing something like this?
for x = 1 to text1(count)
next x
How would I set a counter to go and loop through and count the number of boxes on the form.
I'm guessing something like this?
for x = 1 to text1(count)
next x
for x = 0 to ubound(text1)
OK cdb424ttm, this code might help you.The assumption in this code is that all textboxes on Form1 may contain values. So the code below checks all textboxes on Form1
Dim x As Control
Dim y As Integer
For Each x In Form1
If TypeOf x Is TextBox And Not IsNull(x.Text) Then
Arr(y)= Val(x.Text)
y=y+1
End If
Next x
Regards,
Pi7
Dim x As Control
Dim y As Integer
For Each x In Form1
If TypeOf x Is TextBox And Not IsNull(x.Text) Then
Arr(y)= Val(x.Text)
y=y+1
End If
Next x
Regards,
Pi7
My mistake...
for x = 1 text1.count
or
for x = 0 to text1.count - 1
for x = 1 text1.count
or
for x = 0 to text1.count - 1
Thanx.
ASKER
sirbounty,
your last reply; what is the differents between them
your last reply; what is the differents between them
Sorry for the delayed response...
When you create an array - it uses cardinal-ordered arrays (meaning leading index is 0).
Thus text1.count = 5 (0,1,2,3,4)
But if you reference a loop from 1 to 5, you need to adjust it
The above should read
for x = 0 to text1.count -1
text1.count is 5, so we subtract 1 from it to have our loop stop with the fifth element (#4)
Hope that helps explain it better.
Thanx.
When you create an array - it uses cardinal-ordered arrays (meaning leading index is 0).
Thus text1.count = 5 (0,1,2,3,4)
But if you reference a loop from 1 to 5, you need to adjust it
The above should read
for x = 0 to text1.count -1
text1.count is 5, so we subtract 1 from it to have our loop stop with the fifth element (#4)
Hope that helps explain it better.
Thanx.
let result = join(arr, "")