I've created a program that will allow a user to choose a shoe style from a listbox and the program will return a price in a textbox. I have the code finished but I'm getting an error when I try to run the program. Can anyone give me an idea of how to fix it? The code is below. I've bolded the line where I'm getting the error. The error is "NullReferenceE xception was unhandled"
[CODE=vbnet]Option Explicit On
Option Strict On
Public Class mainform
Structure shoes
Public price As Decimal
Public stylenumber As String
End Structure
Private items(9) As shoes
Private Sub mainform_load(B yVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim path As String = "C:\Course Technology\8362 3-0\VbReloaded\Ch ap09\Shoe Circus Solution\Shoe Circus Project\"
Dim text As String
Dim newlineindex As Integer
Dim recordindex As Integer
Dim record As String
Dim commaindex As Integer
If My.Computer.Fil eSystem.FileExi sts(path & "shoesinfo.txt" ) Then text = My.Computer.Fil eSystem.ReadAll Text(path & "shoesinfo.text ")
For subscript As Integer = 0 To 9
'Error Occours here
newlineindex = text.IndexOf(Co ntrolChars.NewL ine, recordindex)
record = text.Substring( recordindex, newlineindex - recordindex)
commaindex = record.IndexOf( ",", 0)
items(subscript ).stylenumber = record.Substrin g(0, commaindex)
items(subscript ).price = Convert.ToDecim al(record.Subst ring(commaindex + 1))
stylelistbox.It ems.Add(items(s ubscript).style number)
recordindex = newlineindex + 2
Next subscript
stylelistbox.Se lectedIndex = 0
End Sub
Private Sub stylelistbox_se lectedindexchan ged(ByVal sender As Object, ByVal e As System.EventArg s) Handles stylelistbox.Se lectedIndexChan ged
pricetextbox.Te xt = items(stylelist box.SelectedInd ex).price.ToStr ing("N2")
End Sub
End Class[/CODE]
[CODE=vbnet]Option Explicit On
Option Strict On
Public Class mainform
Structure shoes
Public price As Decimal
Public stylenumber As String
End Structure
Private items(9) As shoes
Private Sub mainform_load(B yVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim path As String = "C:\Course Technology\8362 3-0\VbReloaded\Ch ap09\Shoe Circus Solution\Shoe Circus Project\"
Dim text As String
Dim newlineindex As Integer
Dim recordindex As Integer
Dim record As String
Dim commaindex As Integer
If My.Computer.Fil eSystem.FileExi sts(path & "shoesinfo.txt" ) Then text = My.Computer.Fil eSystem.ReadAll Text(path & "shoesinfo.text ")
For subscript As Integer = 0 To 9
'Error Occours here
newlineindex = text.IndexOf(Co ntrolChars.NewL ine, recordindex)
record = text.Substring( recordindex, newlineindex - recordindex)
commaindex = record.IndexOf( ",", 0)
items(subscript ).stylenumber = record.Substrin g(0, commaindex)
items(subscript ).price = Convert.ToDecim al(record.Subst ring(commaindex + 1))
stylelistbox.It ems.Add(items(s ubscript).style number)
recordindex = newlineindex + 2
Next subscript
stylelistbox.Se lectedIndex = 0
End Sub
Private Sub stylelistbox_se lectedindexchan ged(ByVal sender As Object, ByVal e As System.EventArg s) Handles stylelistbox.Se lectedIndexChan ged
pricetextbox.Te xt = items(stylelist box.SelectedInd ex).price.ToStr ing("N2")
End Sub
End Class[/CODE]
Comment