Good day to you, im a junior here, i wonder if someone could help me about arrays.... i just need a brief instruction of what an array is and its uses, i already have several books but it dont say much about it i have samples but it's quite hard to anlyze it thanks guys.... i really need this, im having my midterm exams soon ... thanks a lot,
bamos!, can someone help me with arrays....PLz.........
Collapse
X
-
Ola!
Let's start small, I will be referring to books I have here to make sure it makes sense:
You can look at an array as a street name with a number of houses on that street. Say it were Text1, as the name of your street and there are 4 houses on Text1, the four houses are therefore elements of Text1 (part of Text1) where Text1 is a container that holds 4 houses
These houses are numbered as 0, 1, 2, 3, thus House number 0 is part of Text1, number 1, and so on all part of Text1...
Each house however is unique, they do not have the same number
numbers 0, 1, 2, and 3
In other to distinguish between these Text1 houses, you would need to go by their number.
VB has a wonderful way of asking you if you need to create an array...If you are creating a TextBox array, your array namely, Text1, you can drag Text1 to your form and copy that TextBox. When you attempt to paste, VB will ask you if you need this as an array, say Yes, then paste 3 additional TextBoxes to your form. They should be available to your upper Left corner, on top of one another, just drag an position where you need them. They should be named as the following:
Text1(0) 'for house number 1
Text1(1) 'for house number 2
Text1(2) 'for house number 3
Text1(3) 'for house number 4
Because VB considers 0 as a variable, it too must be counted, thus calcultated as first position. You can change Text1(0) to Text1(1), if you prefer and to keep it simple:
Text1(1) 'for house number 1
Text1(2) 'for house number 2
Text1(3) 'for house number 3
Text1(4) 'for house number 4
Hopefully you get it from here, if not please write again.
Dököll -
I'll attempt a slightly simpler explanation, just in case you didn't quite get it from that one.
I'll assume you have encountered variables, and have some idea of what they are for.
Let's say you have a hundred variables, holding the same piece of information about a hundred objects. You decide that for whatever reason, you need to add 1 to each of them.
Using individual variables, you would have to write a hundred lines of code.Code:Variable1 = Variable1 + 1 Variable2 = Variable2 + 1 Variable3 = Variable3 + 1 . . . Variable100 = Variable100 + 1
An array, on the other hand, looks kind of like one variable, but you use an index to refer to multiple "instances" of it, which can hold different values. That means you can do neat things like using loops. To take the same example of modifying 100 objects from above...Code:For [B]Index[/B] = 1 To 100 ArrayVariable([B]Index[/B]) = ArrayVariable([B]Index[/B]) + 1 Next
Comment
Comment