Solved

Array Question

Posted on 2004-03-30
12
233 Views
Last Modified: 2010-05-02
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
Comment
Question by:cdb424ttm
12 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
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

by:EDDYKT
Comment Utility
just

let result = join(arr, "")
0
 

Author Comment

by:cdb424ttm
Comment Utility
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

by:cdb424ttm
Comment Utility
not sure how to set it up to your syntax Eddykt.
I'm somewhat new to arrays
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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

by:cdb424ttm
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
for x = 0 to ubound(text1)
0
 
LVL 5

Expert Comment

by:Pi7
Comment Utility
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

by:sirbounty
Comment Utility
My mistake...

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

Expert Comment

by:sirbounty
Comment Utility
Thanx.
0
 

Author Comment

by:cdb424ttm
Comment Utility
sirbounty,

your last reply; what is the differents between them
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now