Showing posts with label For. Show all posts
Showing posts with label For. Show all posts

Wednesday, 23 January 2013

VB.Net Arrays & Booleans

VB.Net Arrays & Booleans

Getting Started with Arrays. Simple Arrays:

Dim TempStringArray() As String = Split("Name1,Name2,Name3", ",")

' Result, TempStringArray(0) = "Name1", TempStringArray(1) = "Name2", TempStringArray(2) = "Name3".

Arrays start at 0 so a array of (Arrays(3)) Length is 4...

Booleans are very helpful.

Boolean can have 3 responses (True, False, Nothting(Null) or VbNull)

you can have an Array of any Object Types... etc

Dim TempIntArray(9) As Integer

' Getting the Length of a Array, there are to ways, Ubound() = the Length - 1
' Or TempIntArray.Length = 10
' Example:

' Ubound(TempIntArray) = 9
' TempIntArray.Length = 10

etc...

For I As Long = 0 To Ubound(TempIntArray)
TempIntArray(i) = i
Next

Vb.net For Statements & Loops

For Statements:

The Basic For Statement Looks like this:

Dim i As Long = 0
Dim x As Long = 0

For i = 0 To 10
x +=2
Next

MsgBox(x.ToString)

While Statements

Dim i As Long = 0
Dim ExitMe As Boolean = False

While ExitMe = False
i +=1
If i = 10 Then
ExitMe = True
End If
End While

Do Until

Dim i As Long = 10
Do Until (i < 0)
i-=1
loop