?
Solved

Creting Arrays

Posted on 2003-12-03
9
Medium Priority
?
215 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:digi_mind
[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
9 Comments
 
LVL 10

Accepted Solution

by:
ADSaunders earned 80 total points
ID: 9865615
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
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9865621
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"

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 10

Expert Comment

by:ADSaunders
ID: 9865660
Sorry, submitted before I meant to!


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

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

 .. Alan
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:Moglor
ID: 9867242
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

0
 

Expert Comment

by:icode4food
ID: 9869354
>>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.

0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10212274
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 10269505
No split, mind you 20 points is hardly enough to split anyway so don't worry about it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

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