Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TuT] Using Arrays in VB 2008.

Lets start witha defination.
An array has a single name that all members of the array share, but each member has its own unique index number. This is used to refer to each item of data numerically, instead of that shitload of different text names.

Here's a nice & neat array:
Code
Option Strict Off
Option Explicit On


Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As

        arrQuestions(0) = "Do you think that bitch is fat?"

        arrQuestions(1) = "Do you even have her number?"

        arrQuestions(2) = "This chick looks 35 are you sure shes 17?"

        MsgBox(arrQuestions(1))

         End
   End Sub
End Class

Here is a comparsion of a using an array, and not using one. First the ladder (second).

Code
Option Strict Off
          Option Explicit On

          Public Class Form1
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.eventArgs)  Handles Mybase.Load

           Dim Total

           Dim JanFood = 90
           Dim FebFood = 122
           Dim MarFood = 125
           Dim AprFood = 78
           Dim MayFood =  132
           Dim JunFood = 123
           Dim JulFood = 143
           Dim AugFood = 112
           Dim SeptFood = 167
           Dim OctFood = 123
           Dim NovFood = 132
           Dim DecFood =125

Total =  JanFood + FebFood + MarFood + AprFood + MayFood + JunFood + JulFood + AugFood + SeptFood + OctFood + NovFood + DecFood

MsgBox(Total)

End

   End Sub
End Class

Or you can make your program sweet and less time consuming like this:

Code
Option Strict Off
          Option Explicit On

          Public Class Form1
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)  Handles Mybase.Load


            Dim arrMonthFoodBill(11)
            Dim Total


            arrMonthFoodBill(0) =
            arrMonthFoodBill(1) =
            arrMonthFoodBill(2) =
            arrMonthFoodBill(3) =
            arrMonthFoodBill(4) =
            arrMonthFoodBill(5) =
            arrMonthFoodBill(6) =
            arrMonthFoodBill(7) =
            arrMonthFoodBill(8) =
            arrMonthFoodBill(9) =
            arrMonthFoodBill(10) =
            arrMonthFoodBill(11) =

             For i = 0 To 11
                  Total = Total + arrMonthFoodBill(i)
             Next i

             MsgBox(Total)

   End Sub
EndClass

Now also remember this, it's called the 'Zero Effect'. When declaring elements in an array, ALWAYS START WITH ZERO.
For example, if your array consists of 15 elements, you would type 14, since you need to start at 0.

Code
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

arrBitchesIHave(14)



Thank you for reading.
Simple, and easy to understand. Nice job.
Good post.Nice job brother.
Thread has been updated too.
Only 13 views come on guys this took a while...
For example, if your array consists of 15 elements, you would type 14, since you need to start at 0.

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

arrBitchesIHave(14)
(Mar 27, 2010 03:29 PM)cybr Wrote:  For example, if your array consists of 15 elements, you would type 14, since you need to start at 0.

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

arrBitchesIHave(14)

I'll add that thanks.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pzychonautJun 8, 2023 05:03 PM 5 173 Jun 8, 2023 05:03 PM
Last Post: padrino
[C] by EmacsSucksButILikeItJun 4, 2022 11:03 PM 1 220 Jun 4, 2022 11:03 PM
Last Post: unazed
[Java] by PsychoJul 3, 2021 11:15 PM 24 1,973 Jul 3, 2021 11:15 PM
Last Post: Lookdadon