Hello everyone,
I have written a Visual Basic Application that is pulling data from the Sequel Server into an Array. The Array is used to load data into different pages of a Form. The user enters data isome of into two blank fields on the form. I need to write the data placed in the forms loaded by the array and entered by the user into a TextFile so that I can read the TextFile back in as another Array.
Being new to VB I am having a hard time understanding some of the error messages I ma getting. My array that loads the pages of the form has some Fields 0,8, 0,9, 010, 011, and 012 with Nothing in them. I am trying to enter coding to handle the null data by populating the Nothing Array Fields with Zero.
Please see my coding below:
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
For iRow = iStart To iFinish ' put data from the column five and six 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
Next
Next
Return MyArray ' return the array MyArray to the routine that called it
I ma trying to write coding to check for Nothing in the Blank Array Fields and put Zero there when this occurs so that the coding in my File Control.vb works and continues to write out to the textfile.
See this coding:
Public Class FileControl
Public Sub WriteTextFile(ByVal D2Array As Array, ByVal FileName As String, ByVal Extension As String, ByVal Delimiter As String)
' writes array data to a delimited file
Dim k As Integer = InStrRev(FileName, ".") - 1
Dim l As Integer = Len(FileName)
If k < 1 Then
k = l
End If
Dim sFile As String = FileName.Substring(0, k) & "." & Extension
Dim i, j As Integer
Dim sLine As String = ""
Dim iLsize As Integer = D2Array.GetUpperBound(0)
If System.IO.File.Exists(sFile) Then
System.IO.File.Delete(sFile)
End If
Dim sw As New System.IO.StreamWriter(sFile)
For i = 0 To iLsize
sLine = ""
For j = 0 To D2Array.GetUpperBound(1)
sLine = sLine & D2Array(i, j).ToString & Delimiter
Next j
sw.WriteLine(sLine.Substring(0, Len(sLine) - 1))
Next i
sw.Flush()
sw.Close()
sw.Dispose()
End Sub
A Object Instance Error Occurs on the Line: sLine = sLine & D2Array(i, j).ToString & Delimiter ABOVE
because the ARRAY has Nothing in 0,8, 0,9, 010, 011, and 012.
How can I populate the fields with Zero so my data can finally be written out as a Text File?
I tried to do this with this coding, but I believe I am writing something incorrectly for IsNullorEmpty.
This coding:
Return MyArray ' return the array MyArray to the routine that called it
If MyArray(iRow, 8).IsNullOrEmpty Then
MyArray(iRow, 8) = 0
End If
If MyArray(iRow, 9) = Nothing Then
MyArray(iRow, 9) = 0
End If
If MyArray(iRow, 10) = Nothing Then
MyArray(iRow, 10) = 0
End If
If MyArray(iRow, 11) = Nothing Then
MyArray(iRow, 11) = 0
End If
If MyArray(iRow, 12) = Nothing Then
MyArray(iRow, 12) = 0
End If
IS NOT WORKING!!!
The coding I believe has something missing!
Any help out there is appreciated.
DataMan
I have written a Visual Basic Application that is pulling data from the Sequel Server into an Array. The Array is used to load data into different pages of a Form. The user enters data isome of into two blank fields on the form. I need to write the data placed in the forms loaded by the array and entered by the user into a TextFile so that I can read the TextFile back in as another Array.
Being new to VB I am having a hard time understanding some of the error messages I ma getting. My array that loads the pages of the form has some Fields 0,8, 0,9, 010, 011, and 012 with Nothing in them. I am trying to enter coding to handle the null data by populating the Nothing Array Fields with Zero.
Please see my coding below:
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
For iRow = iStart To iFinish ' put data from the column five and six 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
Next
Next
Return MyArray ' return the array MyArray to the routine that called it
I ma trying to write coding to check for Nothing in the Blank Array Fields and put Zero there when this occurs so that the coding in my File Control.vb works and continues to write out to the textfile.
See this coding:
Public Class FileControl
Public Sub WriteTextFile(ByVal D2Array As Array, ByVal FileName As String, ByVal Extension As String, ByVal Delimiter As String)
' writes array data to a delimited file
Dim k As Integer = InStrRev(FileName, ".") - 1
Dim l As Integer = Len(FileName)
If k < 1 Then
k = l
End If
Dim sFile As String = FileName.Substring(0, k) & "." & Extension
Dim i, j As Integer
Dim sLine As String = ""
Dim iLsize As Integer = D2Array.GetUpperBound(0)
If System.IO.File.Exists(sFile) Then
System.IO.File.Delete(sFile)
End If
Dim sw As New System.IO.StreamWriter(sFile)
For i = 0 To iLsize
sLine = ""
For j = 0 To D2Array.GetUpperBound(1)
sLine = sLine & D2Array(i, j).ToString & Delimiter
Next j
sw.WriteLine(sLine.Substring(0, Len(sLine) - 1))
Next i
sw.Flush()
sw.Close()
sw.Dispose()
End Sub
A Object Instance Error Occurs on the Line: sLine = sLine & D2Array(i, j).ToString & Delimiter ABOVE
because the ARRAY has Nothing in 0,8, 0,9, 010, 011, and 012.
How can I populate the fields with Zero so my data can finally be written out as a Text File?
I tried to do this with this coding, but I believe I am writing something incorrectly for IsNullorEmpty.
This coding:
Return MyArray ' return the array MyArray to the routine that called it
If MyArray(iRow, 8).IsNullOrEmpty Then
MyArray(iRow, 8) = 0
End If
If MyArray(iRow, 9) = Nothing Then
MyArray(iRow, 9) = 0
End If
If MyArray(iRow, 10) = Nothing Then
MyArray(iRow, 10) = 0
End If
If MyArray(iRow, 11) = Nothing Then
MyArray(iRow, 11) = 0
End If
If MyArray(iRow, 12) = Nothing Then
MyArray(iRow, 12) = 0
End If
IS NOT WORKING!!!
The coding I believe has something missing!
Any help out there is appreciated.
DataMan