[2 days left] Whatâ€™s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Array Question

Posted on 2004-03-30
Medium Priority
242 Views
Hi all,
I have code that looks like this.
Let result = term1+term2+term3+term4+term5
Print result
My question is this, how would I setup
An array to do the same thing?

Thanks
0
Question by:cdb424ttm
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 67

Accepted Solution

sirbounty earned 2000 total points
ID: 10712954
Greetings cdb424ttm,
Dim term() as integer '?

How are you getting the data for term?
You would need to fill each one by:
term(1)=n
term(2)=n

'etc

Then result could equal
for x=1 to 5 ' also can use lbound(term), ubound(term)
result=term(x) + result
next x

~sirbounty
0

LVL 26

Expert Comment

ID: 10712962
just

let result = join(arr, "")
0

Author Comment

ID: 10713003
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.
0

Author Comment

ID: 10713010
not sure how to set it up to your syntax Eddykt.
I'm somewhat new to arrays
0

LVL 67

Expert Comment

ID: 10713039
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).text) + strResults
next x

msgbox "Answer is " & strResults

0

Author Comment

ID: 10713094
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

0

LVL 67

Expert Comment

ID: 10713105
for x = 0 to ubound(text1)
0

LVL 5

Expert Comment

ID: 10713107
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
0

LVL 67

Expert Comment

ID: 10713120
My mistake...

for x = 1 text1.count
or
for x = 0 to text1.count - 1
0

LVL 67

Expert Comment

ID: 10713159
Thanx.
0

Author Comment

ID: 10713316
sirbounty,

0

LVL 67

Expert Comment

ID: 10715717
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

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.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code thatâ€¦
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). Uâ€¦
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This lâ€¦
###### Suggested Courses
Course of the Month14 days, 5 hours left to enroll