| | |
Get unhandled exception of type'System.Argument Exception'
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Solved Threads: 0
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]
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
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: issue in exporting crystal report to excel on server
- Next Thread: Matching same values in 2 databases and preparing a report
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application array assignment basic binary box button buttons center click code connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan peertopeervideostreaming picturebox plugin port print printing printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net web wpf xml





