Hello,
I have this pesky homework assignment to read and manipulate a .txt file using three parallel arrays (the attached file is the file in question). It builds with no errors (i'm working in VB 2005), but when I run the program, it gives me the following error message:
Input string not in a correct format
************** Exception Text **************
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Decimal.Parse(String s, IFormatProvider provider)
at System.Convert.ToDecimal(String value)
at ch9._6.frmDJPlayList.frmDJPlayList_Load(Object sender, EventArgs e) in d:\ch9.6\ch9.6\Form1.vb:line 40
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Here's my code thus far:
CODE
Public Class frmDJPlayList
Public Shared _intSizeOfArray As Integer = 52
Public Shared _strTitleOfSong(_intSizeOfArray) As String
Public Shared _strGenreOfSong(_intSizeOfArray) As String
Public Shared _decLengthOfSong(_intSizeOfArray) As Decimal
Private Sub frmDJPlayList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The frmDJPlayList load event reads the songs.txt file and fills
' the ComboBox object with genre types.
' Initialize an instance of the StreamReader object
' and declare variables
Dim objReader As IO.StreamReader
Dim strLocationAndNameOfFile As String = "c:\songs.txt"
Dim intCount As Integer = 0
Dim strFileErrorMessage As String = _
"The file is not available. Restart when file is available."
' Verify the file exists
If IO.File.Exists(strLocationAndNameOfFile) Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
' Read file line by line until completed
Do While objReader.Peek <> -1
_strTitleOfSong(intCount) = objReader.ReadLine()
_strGenreOfSong(intCount) = objReader.ReadLine()
_decLengthOfSong(intCount) = Convert.ToDecimal(objReader.ReadLine())
intCount += 1
Loop
objReader.Close()
Else
MessageBox.Show(strFileErrorMessage, "Error")
Me.Close()
End If
End Sub
Please help!