Creting Arrays

I know C++, and using it allows me to create arrays.

Is it possible to create arrays in VB and please give me a simple code so I can create an array with 10 string elements.

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi digi_mind,
Dim MyArray(10) As String
DIm i As Integer
MyArray(0) = "String0"
MyArray(1) = "String1"
MyArray(2) = "String2"
MyArray(3) = "String3"
MyArray(4) = "String4"
MyArray(5) = "String5"
MyArray(6) = "String6"
MyArray(7) = "String7"
MyArray(8) = "String8"
MyArray(9) = "String9"

(could be done in a for next loop)
for i = 0 to 9

Regards .. Alan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimCotteeHead of Software ServicesCommented:
Hi digi_mind,

Dim aryMyArray(10) As String

You then have an array with ten elements (0 - 9) that you can refer to like this:

aryMyArray(0) = "Hello"
aryMyArray(7) = "Goodbye"

Brainbench MVP for Visual Basic
Sorry, submitted before I meant to!

(could be done in a for next loop)
for i = 0 to 9
    MyArray(i) = Some Data

or even
Dim MyArray
Myarray = Array("String0", "String1","String2","String3","String4","String5")
Dim i
For i = 0 To 5
msgbox Myarray(i)

 .. Alan
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

you can also create dynamic arrays:

dim MyArray() as string

'then you can redim it later on

Redim MyArray(10)

For i = 0 to 10
    MyArray(i) = "Hello"
Next i

'then if you want to add a few more...

Redim Preserve MyArray(20)

For i = 11 to 20
    MyArray(i) = "Good Bye"
Next i

>>Dim aryMyArray(10) As String
>>You then have an array with ten elements (0 - 9) that you can refer to like this:

That is NOT correct. That gives you eleven elements (0-10).

As stated in the MSDN Library:
Dim Counters(14) As Integer
Dim Sums(20) As Double

The first declaration creates an array with 15 elements, with index numbers running from 0 to 14. The second creates an array with 21 elements, with index numbers running from 0 to 20. The default lower bound is 0.

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split ADSaunders, TimCottee
Please leave any comments here within the next seven days.


EE Cleanup Volunteer
TimCotteeHead of Software ServicesCommented:
No split, mind you 20 points is hardly enough to split anyway so don't worry about it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.