到目前为止,我有这个,虽然我错过了一些东西。我应该使用数组来使用.txt 中的项目填充列表框,然后当单击列表框中的项目时,标签会更新价格。有什么建议么?
Public Class frmMain
Structure product
Public itemnumber As String
Public itemprice As Decimal
End Structure
Private Sub ButtonExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ItemInfo As String = "H:\Users\user\Documents\Visual Studio 2012\Projects\WindowsApplication9\ItemInfo.txt"
Dim inFile As IO.StreamReader
Dim strName As String
Dim skipLine As Boolean
If System.IO.File.Exists("H:\Users\user\Documents\Visual Studio 2012\Projects\WindowsApplication9\ItemInfo.txt") = True Then
inFile = IO.File.OpenText("H:\Users\user\Documents\Visual Studio 2012\Projects\WindowsApplication9\ItemInfo.txt")
Do Until inFile.Peek = -1
strName = inFile.ReadLine
If skipLine = False Then
ListBox1.Items.Add(strName)
skipLine = True
Else : skipLine = False
End If
Loop
Dim objReader As New System.IO.StreamReader(ItemInfo)
ListBox1.Text = objReader.ReadToEnd
objReader.Close()
Else
MsgBox("File Does Not Exist")
End If
End Sub
End Class