我试图弄清楚如何让用户在一个表单中写入他们想要在列表框中的另一个表单上看到的信息。基本上,用户会写下他们想要的详细信息(标题、作者、股票、价格、小说或非小说),然后按记录详细信息,程序会在文本文件中搜索这些值,然后另一种形式会出现列表框,他们将在其中看到所有选定的书籍。
这是我到目前为止的代码,它基本上读取文本文件信息并将其存储到一个数组中:
Dim Title As String
Dim Author As String
Dim Stock As Integer
Dim Price As Double
Dim Fiction As String
Dim NonFiction As String
Private Sub btnRecord_Click(sender As System.Object, e As System.EventArgs) Handles btnRecord.Click
''Read the information into a string''
Dim objReader As New StreamReader("C:\Users\Books.txt")
Dim fileString As String = objReader.ReadToEnd()
objReader.Close()
objReader.Dispose()
''Concert string into array''
Dim Array As Char() = fileString.ToCharArray()
Array(0) = CChar("BookName")
''Declare the string to hold the value''
Dim resultString As String = ","
''Increment each item in the string''
Dim curChar As Char
For i As Integer = 0 To (Array.Length - 1)
curChar = Array(i)
If (Char.IsLetterOrDigit(curChar)) Then
Array(i) = Chr(Asc(curChar) + 1)
End If
Next
''Conver the array back to string''
Dim newString As String = New String(Array)
''Hide the details form when book inventory runs''
Me.Hide()
''display inventory form''
frmInventory.Show()
End Sub