|
-
Nov 1st, 2000, 07:41 AM
#1
Thread Starter
New Member
Friend's,
Please help me work's array in VB, how declarations variables array???
Tnk's
-
Nov 1st, 2000, 07:59 AM
#2
Well ...
For starters, here is how you declare arrays:
Code:
Dim strArray() as string
dim numArray() as integer
dim varArray() as variant
The above statements create empty arrays of the specified types. You can later resize them. If you want to declare the size of the arrays, you can use:
Code:
dim strArray(3) as string 'Array to hold 3 strings
dim numArray(4,5) as integer 'Array to hold 4x5 integers, 4 rows and 5 columns
There are various topics associated with arrays like the Base index, resizing the arrays etc. Either check out MSDN, get hold of a good VB book or come back to the forum for further clarifications.
-
Nov 1st, 2000, 07:59 AM
#3
Arrays speed up the process a bit.
Code:
Private Sub Command1_Click()
Dim x(12) As String
x(0) = "M"
x(1) = "a"
x(2) = "t"
x(3) = "t"
x(4) = "h"
x(5) = "e"
x(6) = "w"
x(7) = " "
x(8) = "G"
x(9) = "a"
x(10) = "t"
x(11) = "e"
x(12) = "s"
For I = LBound(x) To UBound(x)
Print x(I)
Next I
End Sub
-
Nov 1st, 2000, 08:51 AM
#4
_______
<?>
If you don't know the size of an array on declaring it your declare it as so:
In a bas module
Code:
Option Explicit
Public MyArr()
Then later in your code, lets say you are reading a file using line input and then you want to store the lines in an array your would do this:
Option Explicit
'some event on the form
Dim i As Integer, myVar as String
Open ("C:\myfile.txt") for Input as #1
While Not EOF(#1)
ReDim Preserve MyArr(i)
Input #1, myVar
myArr(i) = myVar
i = i + 1
Loop
Close #1
To read the array into a list box
For i = lBound(myArr) to Ubound(myArr)
list1.addditem myArr(i)
next i
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 01:06 PM
#5
hmm, does microsoft produce VB in different countries' languages? ie french or german, instead of using english words such as Select Case... or If-then-else
just a thought.
-
Nov 1st, 2000, 01:11 PM
#6
_______
<?>
wossname
How in anyone's name does that tie into Arrays?

bty
Do you know why a chair is called a chair and not a table?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 04:00 PM
#7
Frenzied Member
VbWorld.net Has an excellent article about arrays, read it here:
http://www.vb-world.net/articles/arrays/
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 1st, 2000, 11:02 PM
#8
Hyperactive Member
If you want to make a cycle into the array try this:
dim int_I as integer
dim int_J as integer
dim a() as integer
...
...
...
int_J=6
redim a(int_J)
for int_I=lbound(a) to ubound(a)
...
...
next int_I
By the way, if you´re using the preserve keyword, it can be done on the last dimension of the array.
-
Nov 1st, 2000, 11:17 PM
#9
Well ...
Matthew,
On reading your reply I thought there was a mistake in the code. You declared the array of string with a dimension of 12. I took it to be the total number of elements in the array. Actually it is not so.
This is another point of the arrays which I had failed to notice. And this is specific to VB.
In all programming languages, when you declare an array you define the size of the array, i.e. the total number of elements in the array. But in VB you declare the Upper Bound of the array, i.e. the index of the last element in the array.
Another interesting point is in this case the Option Base statement decides how many elements your array can hold. For e.g. in Matthew's example, Option Base 0 will store 13 elements in the array (Index 0 to Index 12) while Option Base 1 will store only 12 elements (Index 1 to Index 12).
Are my observations correct?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|