943,851 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 2850
  • VB.NET RSS
Jul 31st, 2008
0

Get unhandled exception of type'System.Argument Exception'

Expand Post »
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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michael0101 is offline Offline
3 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Update Accessdb using VB.NEt
Next Thread in VB.NET Forum Timeline: Matching same values in 2 databases and preparing a report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC