Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creting Arrays

Posted on 2003-12-03
9
Medium Priority
?
217 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses

636 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