Hi,
I am using the following code to open a new form...
There is an Opendialogue box that opens a file.. a sub reads the file and if an error is detected it opens a new form.
If I click on a save function on the new form the app crashed with the above error or if I close it normally and then click on the Open button on the main form again it causes the same error. Any Ideas?
Many Thanks,
Josh
Code:
Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
Dim Item As String
Dim diag As New OpenFileDialog
Try
diag.Filter = "All files (*.*)|*.*|Comman Seperate Vaules (*.csv)|*.csv|Text Files (*.txt)|*.txt"
diag.FilterIndex = 2
diag.Multiselect = True
diag.ShowDialog()
For Each Item In diag.FileNames
If InStr(Item.ToLower, ".csv") > 0 Then
AddCSV(Item)
ElseIf InStr(Item.ToLower, ".txt") > 0 Then
AddTxt(Item)
End If
Next
diag.Dispose()
diag = Nothing
Catch ex As Exception
MsgBox("Error!!!: " & ex.ToString, MsgBoxStyle.Critical, "Error")
End Try
SetCountLabel(lblCountImpo
rt, lstUsers, False)
End Sub
Function AddCSV(ByVal Item As String) As Boolean
Dim arrFile() As String
Dim FileReader As StreamReader
Dim Readline As String = String.Empty
Dim arrReadline() As String
Dim oLocation As New Locations
Dim UserLocation As String
Dim GroupLocation As String
Dim ErrorArraylist As New ArrayList
Dim ErrLocation As Boolean = False
Dim Results As String
Dim i As Integer
Try
arrFile = Item.Split(CChar("\"))
If sLogFilename.Length = 0 Then
sLogFilename = arrFile(UBound(arrFile))
Else
sLogFilename = sLogFilename & " - " & arrFile(UBound(arrFile))
End If
sLogFilename = sLogFilename.Replace(".csv
", "")
FileReader = New StreamReader(Item)
Do
Readline = FileReader.ReadLine
If Not (Readline Is Nothing) Then
lstUsers.Items.Add(Readlin
e)
arrReadline = Readline.ToUpper.Split(CCh
ar(","))
UserLocation = oLocation.SetUserLocation(
arrReadlin
e(0))
GroupLocation = oLocation.SetUserLocation(
arrReadlin
e(1))
If UserLocation <> GroupLocation Then
ErrLocation = True
ErrorArraylist.Add(Readlin
e)
End If
End If
Loop Until (Readline Is Nothing)
If Not (FileReader Is Nothing) Then
FileReader.Close()
End If
If ErrLocation Then
Dim fError As New _Error
fError.Show()
End If
Catch ex As Exception
CreateDebugLog("OpenDialog
" & vbCrLf & ex.ToString & vbCrLf & "-------------------------
---" & vbCrLf)
End Try
End Function
Start Free Trial