Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,059 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,560 people online right now. Registration is fast and FREE... Join Now!




Arrays

 
Reply to this topicStart new topic

> Arrays, Arrays Made Simple

AdamSpeight2008
Group Icon



post 28 Jul, 2008 - 10:02 PM
Post #1


Single Dimension
vb

Dim TheArray(9) As Integer

This defines a fixed size array of Integers containing 10 elements. The first one is element Zero and the last element Nine
The elements can accessed
vb

For i As Integer=0 To 9
TheArray(i)=i
Next i


It is also possible to define an array which can be resized
vb

Dim TheArray() As Integer

To create an array containing 10 elements.
vb

ReDim TheArray(9)
For i As Integer=0 To 9
TheArray(i)=i
Next i


Note using ReDim this way will clear all of the contains previously stored in the array.

Now suppose we want to resize the array to contain 20 items without clearing the contents
vb

ReDim Preserve TheArray(20)


Two Dimension
Imagine you want to recreate the multiplication table.
vb

Dim TheArray(9,9) As Integer
For x As Integer=0 To 9
For y As Integer=0 To 9
TheArray(x,y)=x*y
Next y
Next x

It is also possible to use a resizable array.
vb

Dim TheArray(,)
ReDim TheArray(9,9)
For x As Integer=0 To 9
For y As Integer=0 To 9
TheArray(x,y)=x*y
Next y
Next x


Three Dimensions
A Fixed Size array.
vb

Dim TheArray(9,9,9) As Integer
For x As Integer=0 To 9
For y As Integer=0 To 9
For z As Integer=0 To 9
TheArray(x,y)=x*y*z
Next z
Next y
Next x

It is also possible to use a resizable array.
vb

Dim TheArray(,,)
ReDim TheArray(9,9,9)
For x As Integer=0 To 9
For y As Integer=0 To 9
For z As Integer=0 To 9
TheArray(x,y)=x*y*z
Next z
Next y
Next x



Note If you use ReDim with Preserve on arrays with multiple dimenstions.
You can only resize the right-most dimension,
vb

ReDim Preserve TheArray(1,2,3)


Higher Dimension
You can extend the number up to any number provided the array fits in memory.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 12/1/08 06:14PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month