' Visual Basic 2008 9.0 .NET Examples - Dynamical Arrays - Arrays : Module Example1 Sub Main() Dim row() As Integer Dim matrix(,) As Integer ' (1) ' 'row(5) = 5 ' (2) impossible, no array instance 'matrix(5, 5) = 5 ' (3) impossible, no array instance ' ReDim row(9) ' (4) ReDim matrix(9, 9) ' (5) ' row(5) = 5 matrix(5, 5) = 5 ' Console.WriteLine(row(5)) Console.WriteLine(matrix(5, 5)) ' Console.ReadLine() End Sub End Module Module Example2 Sub Main() Dim matrix(2, 3) As Integer ' matrix(1, 1) = 10 Console.WriteLine(matrix(1, 1)) ' ReDim matrix(5, 9) Console.WriteLine(matrix(1, 1)) ' (1) ' Console.ReadLine() End Sub End Module Module Example3 Sub Main() Dim matrix(2, 3) As Integer ' matrix(1, 1) = 10 Console.WriteLine(matrix(1, 1)) ' ReDim Preserve matrix(2, 9) ' (1) Console.WriteLine(matrix(1, 1)) ' (2) ' ReDim Preserve matrix(5, 9) ' (3) ' Console.ReadLine() End Sub End Module Module Exercise1Solution Sub Main() Dim menu As Char Dim employees As String(,) Dim count As Integer Dim index As Integer Do Until menu = "x"c OrElse menu = "X"c If count > 0 Then Console.WriteLine("Employees Overview :") For index = 0 To count - 1 Console.WriteLine(employees(0, index) & _ " (" & employees(1, index) & ")") Next Else Console.WriteLine("No Employees.") End If Console.Write("MENU : Add Employee / " & _ " Remove Last Employee / " & _ " Exit : ") menu = Console.ReadLine() Select Case menu Case "a"c, "A"c ReDim Preserve employees(1, count) Console.Write("Name : ") employees(0, count) = Console.ReadLine() Console.Write("Department : ") employees(1, count) = Console.ReadLine() count += 1 Case "r"c, "R"c If count > 0 Then ReDim Preserve employees(1, count - 1) count -= 1 End If Case "x"c, "X"c ' doe niets End Select Loop End Sub End Module Module Example4 Sub Main() Dim capacity As Integer = 2 Dim count As Integer Dim numbers(capacity - 1) As Integer ' Do Dim index As Integer Console.Write("Numbers ( capacity " & capacity & _ ", count " & count & " ) : ") For index = 0 To count - 1 Console.Write(numbers(index) & " ") Next Console.WriteLine() Console.Write("Number ? : ") Dim number As Integer = Console.ReadLine() count += 1 If count > capacity Then capacity *= 2 ReDim Preserve numbers(capacity - 1) End If numbers(count - 1) = number Loop End Sub End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.