?
Solved

Question is apparently to simple to find an answer to (Proper Array Syntax)

Posted on 2003-02-26
5
Medium Priority
?
127 Views
Last Modified: 2010-05-01
I just need to know the proper array syntax. Make me an array, call it myArray and I'll know the rest. I can make an array in other languages, but when I SEARCH for array at msdn I can't find proper syntax for Visual Basic. SO.. please, just write a small array with a few elements... 3 or 4. Thanks.
0
Comment
Question by:lionheart620
[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
  • Learn & ask questions
5 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8029102
Dim myArray(10) as String



0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8029115
Or

Dim myArray() as Object

ReDim myArray(10)

btw:

you can also do something like
Dim myArray(1 to 10) as String

for multidimensional
Dim myArray(5, 10) as String



0
 
LVL 2

Accepted Solution

by:
Jacamar earned 120 total points
ID: 8029118
dim myarray() as single
dim inI as integer
dim inJ as integer

inI = 5

Redim myarray(1 to inI) as single

For inJ = 1 to 5
  myarray(inJ) = inJ
Next inJ



This will give you an array with 5 elements that will be
1
2
3
4
5

is this what you were after?
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 8029152
One last thing That may come in handy

        Dim myArray() as integer

        For a = 0 to 10
            Redim Preserve myArray(a)
            myArray(a) = a
        Next a

This will increase the size of the Array while preserving the previous values

one thing, it will only work on the outer most dimension
        For a = 0 to 10
            Redim Preserve myArray(2,a)
            myArray(0,a) = a
            myArray(1,a) = a + 1
            myArray(2,a) = a + 2
        Next a

0
 
LVL 3

Expert Comment

by:leojl
ID: 8029629
hi lion,
Here is an example of a 2 diminsional array

Private Sub Form_DblClick()
Dim MyArray(1 To 3, 1 To 4) As Integer ' default is Variant
'to populate
For i = 1 To 3
For j = 1 To 4
MyArray(i, j) = i * j
Next
Next
'to see the result
For n = 1 To 3
Print MyArray(n, 1), MyArray(n, 2), MyArray(n, 3), MyArray(n, 4)
Next
End Sub

sincerely   leo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…
Suggested Courses
Course of the Month13 days, left to enroll

777 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