Solved

Creting Arrays

Posted on 2003-12-03
9
210 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
9 Comments
 
LVL 10

Accepted Solution

by:
ADSaunders earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Expert Comment

by:Moglor
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
No split, mind you 20 points is hardly enough to split anyway so don't worry about it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
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…
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now