Get unhandled exception of type'System.Argument Exception'

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 3
Reputation: michael0101 is an unknown quantity at this point 
Solved Threads: 0
michael0101 michael0101 is offline Offline
Newbie Poster

Get unhandled exception of type'System.Argument Exception'

 
0
  #1
Jul 31st, 2008
Hi everyone,
I am still stuck and please help anyone!!!
I want to save and load a listbox with 2 arrays in a .txt(file), but i am getting an unhandled exception of type 'System.ArgumentException' in microsoft.visualbasic.dll.
Additional information:File I/Owithtype 'ObjectCollection' is not valid.
Please help anyone, my tutor is on holiday(home-learning) and my books don't give me the push in the right direction.I am using VB.NET 2003
I attach my code
[ Dim noCustomerRecords As Integer
Dim arrData(364) As String
Dim arrDate(364) As String


Private Sub frmCustomerStatistic_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblDate.Text = Format(Now, "ddd dd MMMM yyyy".ToString)
btnEnterCustomerNumber.Focus()
btnAddToList.Enabled = False
Call OpenFile()
End Sub

Private Sub OpenFile()
Dim i As Integer
'OPen the file and read the data
Try
Call FillListBox()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
FileClose(1)
End Try
End Sub

Private Sub FillListBox()
'Enter array list in the list box
Dim i As Integer
lstCustomerStatistic.Items.Clear()
For i = 0 To noCustomerRecords - 1
lstCustomerStatistic.Items.Add(CDate(arrDate(i)).ToLongDateString & " = " & arrData(i).ToString)
Next i
End Sub

Private Sub txtCustomerNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
Dim KeyAscii As Integer
KeyAscii = Asc(e.KeyChar)
'only allow numbers, backspace or enter
Select Case KeyAscii
Case Asc("0") To Asc("9"), Asc(ControlChars.Back)
'acceptable keystrokes
e.Handled = False
btnAddToList.Enabled = True
Case Asc(ControlChars.Cr)
'enter key or click on Add To List Button
btnAddToList.Enabled = False
Case Else
e.Handled = True
MsgBox("Please enter only Customer numbers!", , "Error")
txtCustomerNumber.Focus()
btnAddToList.Enabled = False

End Select

End Sub

Private Sub btnEnterCustomerNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterCustomerNumber.Click
btnEnterCustomerNumber.Enabled = True
txtCustomerNumber.Focus()


End Sub

Private Sub btnAddToList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddToList.Click
'Add Date and Customer number to the List
lstCustomerStatistic.Items.Add((lblDate.Text) + (" ") + (txtCustomerNumber.Text))
mnuFileSave.Enabled = True
btnClearEntry.Enabled = True
'test if customer entry is already made
If lstCustomerStatistic.Items.Count = +1 Then
btnAddToList.Enabled = False
End If


End Sub

Private Sub btnClearEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearEntry.Click
Dim Ind As Integer
'Get Index
Ind = lstCustomerStatistic.SelectedIndex
'Make sure list item is selected
If Ind >= 0 Then
'Remove it from list box
lstCustomerStatistic.Items.Remove(Ind)
End If
If btnClearEntry.Enabled = True Then
btnAddToList.Enabled = False
lstCustomerStatistic.Items.Clear()
'Clear text box
txtCustomerNumber.Text = ""
'Show message to enter data
MsgBox("Please click the Enter Customer Number button!", , "Enter Data")

End If

End Sub



Private Sub mnuFileSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
Try
'code to save file
Catch ex1 As Data.ReadOnlyException
MsgBox("Please change the Read only property!", , "Error")
Catch ex2 As Exception
MsgBox("Error while saving your Data!", , "Contact your Administrator")
End Try

'Save Data
If dlgSave.ShowDialog() = DialogResult.OK Then
FileOpen(1, dlgSave.FileName, OpenMode.Output)
Print(1, lstCustomerStatistic.Items)
FileClose(1)
End If
End Sub
End Class]
Thanks Michael
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC