1
我想制作一个程序,检查所有产品的库存文件,并返回来自输入的GTIN代码的正确信息(您将(希望))从看着我的代码)努力从文本文件中获取字符串(Visual Basic)
Public Class Form1
Dim FILE_NAME As String = "H:\Visual Studio 2013\Projects\Control Task 2 Barcode Orders\Control Task 2 Barcode Orders\bin\Debug\receipt_orders.txt"
Dim GTIN As String
Dim LineContaining As String
Dim quantity As Integer
Dim description As String
Dim singleamount As String
Dim singleprice As Double
Dim totalprices As Double
Private Sub btnEnterGTIN_Click(sender As Object, e As EventArgs) Handles btnEnterGTIN.Click
GTIN = getValidGTIN()
Call itemfinder(GTIN)
End Sub
Function getValidGTIN()
Dim GTIN, ValidGTINAmountCharacters As String
Dim GTINOK As Boolean
'Declaring variables.
GTINOK = False
Do
GTIN = InputBox("Enter the full GTIN Number (it should be 8 digits long)")
'Prompts the user to enter the GTIN.
ValidGTINAmountCharacters = Len(GTIN)
'Makes it so that the amount of characters of the GTIN is stored in the variable ValidGTINAmountCharacters.
If ValidGTINAmountCharacters = 8 Then GTINOK = True
'Makes it so the program will only accept an input if it was 8 characters long.
If Not IsNumeric(GTIN) Then GTINOK = False
'Makes it so that if any other character typed in apart from a number is not valid.
If Not GTINOK Then MsgBox("The GTIN Number isn't valid. It should be a 8 digit number. (Should not contain letters or symbols).")
'Makes it so that if the GTIN is not valid according to the above, a message appears saying it is invalid.
Loop Until GTINOK
Return GTIN
End Function
Private Sub itemfinder(ByVal GTIN As String)
Using reader As New IO.StreamReader("receipt_orders.txt")
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains(GTIN) Then
line = LineContaining
Exit While
End If
End While
End Using
description = Mid$(LineContaining, 10, 17)
singleamount = Mid$(LineContaining, 38, 4)
quantity = InputBox("Enter the amount required")
totalprices = quantity * singleamount
lstGTIN.Items.Add(GTIN)
lstName.Items.Add(description)
lstQuantity.Items.Add(quantity)
lstSinglePrice.Items.Add(singleamount)
lstTotal.Items.Add(totalprices)
Dim sum As Double
For x As Integer = 0 To lstTotal.Items.Count - 1
sum += Val(lstTotal.Items.Item(x).ToString)
Next
txtTotalPrice.Text = sum.ToString
End Sub
End Class
当我在数量和品种代码输入,我得到有关的总价格的计算错误代码 - 我不知道如何解决这个问题! 此外,我使用这样的
12345670 L-Shaped Brackets 7.20
10101010 Television 1.80
69696969 Screws 0.20
容貌请尽量解释如何解决这个问题尽可能的简单文本文件!我不是很擅长Visual Basic!
这不是vbscript。任何你没有指定错误信息的原因? – shawnt00
也许你需要'LineContaining = line'而不是你得到的是相反的分配。 – shawnt00
工作!我觉得很蠢,错误是因为这个,非常感谢你! – Senyd