I am very new to VB and trying to understand Array's. I am having trouble referencing the contents of the Array in other areas of my application and I ma getting object Reference Errors and the contents of the Array appear as Nothing and I get a null reference error.
The Array is being loaded from the Sequel Server and I am adding two columns to the Array to add data. I am getting all of my Array in the Return Array, however I acm unable to reference contents of the Array and write out the contents. I need to reference the contents.
The Array is called MyArray, and I need to reference each part of the Array as MyArray(irow,1) for example. The irow will always vary but I will always have 10 columns.
How can I reference the Array in other parts of the application? I tried dimensioning the array at the Class Level, but the array shows nothing in it.
My Code here works and the Array Returns with all of my data that I need all ten columns, but I can't reference the pieces of it elsewhere in the application in another button event in a Private Sub or Public Sub.
The Coding as a Private Function:
Private Function BuildArray() As Array
Dim i As Int32 = CType(Me.Name.Substring(1, 1), Int32)
Dim iFinish, iPage, iRow, iStart As Int32
Dim MyArray(,) As String = CType(_sData, String(,))
For iPage = i To 1 Step -1 ' start with the current and back thru the forms to 1
Dim frm As String = "f" & iPage
If iPage = i Then ' last page has variable number of rows
iStart = _sta
iFinish = _fin
Else
iStart = (12 * iPage) - 12 ' not last page has fixed number of rows
iFinish = iStart + 11
End If
If MyArray(iRow, 8) Is Nothing Then
MyArray(iRow, 8) = 0
End If
For iRow = iStart To iFinish ' put data from the column nine and ten textboxes into the array
'MyArray(iRow, 0) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "0").Text.ToString
'MyArray(iRow, 1) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "1").Text.ToString
'MyArray(iRow, 2) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "2").Text.ToString
'MyArray(iRow, 3) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "3").Text.ToString
'MyArray(iRow, 4) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "4").Text.ToString
'MyArray(iRow, 5) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "5").Text.ToString
'MyArray(iRow, 6) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "6").Text.ToString
'MyArray(iRow, 7) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "7").Text.ToString
'MyArray(iRow, 8) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "8").Text.ToString
MyArray(iRow, 9) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "9").Text.ToString
MyArray(iRow, 10) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "10").Text.ToString
Next
Next
Return MyArray ' return the array MyArray to the routine that called it
Any help is truly appreciated!
DataMan86
End Function
The Array is being loaded from the Sequel Server and I am adding two columns to the Array to add data. I am getting all of my Array in the Return Array, however I acm unable to reference contents of the Array and write out the contents. I need to reference the contents.
The Array is called MyArray, and I need to reference each part of the Array as MyArray(irow,1) for example. The irow will always vary but I will always have 10 columns.
How can I reference the Array in other parts of the application? I tried dimensioning the array at the Class Level, but the array shows nothing in it.
My Code here works and the Array Returns with all of my data that I need all ten columns, but I can't reference the pieces of it elsewhere in the application in another button event in a Private Sub or Public Sub.
The Coding as a Private Function:
Private Function BuildArray() As Array
Dim i As Int32 = CType(Me.Name.Substring(1, 1), Int32)
Dim iFinish, iPage, iRow, iStart As Int32
Dim MyArray(,) As String = CType(_sData, String(,))
For iPage = i To 1 Step -1 ' start with the current and back thru the forms to 1
Dim frm As String = "f" & iPage
If iPage = i Then ' last page has variable number of rows
iStart = _sta
iFinish = _fin
Else
iStart = (12 * iPage) - 12 ' not last page has fixed number of rows
iFinish = iStart + 11
End If
If MyArray(iRow, 8) Is Nothing Then
MyArray(iRow, 8) = 0
End If
For iRow = iStart To iFinish ' put data from the column nine and ten textboxes into the array
'MyArray(iRow, 0) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "0").Text.ToString
'MyArray(iRow, 1) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "1").Text.ToString
'MyArray(iRow, 2) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "2").Text.ToString
'MyArray(iRow, 3) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "3").Text.ToString
'MyArray(iRow, 4) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "4").Text.ToString
'MyArray(iRow, 5) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "5").Text.ToString
'MyArray(iRow, 6) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "6").Text.ToString
'MyArray(iRow, 7) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "7").Text.ToString
'MyArray(iRow, 8) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "8").Text.ToString
MyArray(iRow, 9) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "9").Text.ToString
MyArray(iRow, 10) = My.Application.OpenForms.Item(frm).Controls("TextBox" & iRow & "10").Text.ToString
Next
Next
Return MyArray ' return the array MyArray to the routine that called it
Any help is truly appreciated!
DataMan86
End Function