当文本框中的文本等于某个单词时,我需要在组合框中输入值以保存该文本

时间:2019-03-27 11:53:01

标签: vb.net

我在debug文件夹中的文本文件中有订单,当我在文本框中键入订单名称时,它会显示该订单是一个列表框,并且在下面有一个组合框,我可以在其中更改餐点的状态准备(准备,准备交付等)。如果我返回该表单,并在文本框中输入相同的订单名称,则需要先前的出行状态已在文本框中。感谢您的帮助!

Public Class frmOrderStatus

    Private Sub btnStatus_Click(sender As Object, e As EventArgs) Handles btnStatus.Click
        Dim sr As IO.StreamReader = IO.File.OpenText(strTxtOrderNum & ".txt")
        Do Until sr.EndOfStream
            lstOrder.Items.Add(sr.ReadLine)
        Loop


    End Sub

    Private Sub OrderStatus_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lstOrder.Items.Clear()
        btnStatus.Enabled = False
        ChangeStatus.Enabled = False



    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnValidate.Click
        strTxtOrderNum = txtOrderNum2.Text
        btnStatus.Enabled = True
        ChangeStatus.Enabled = True

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        strSaveStatus = ChangeStatus.SelectedIndex


    End Sub

    Private Sub ChangeStatus_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ChangeStatus.SelectedIndexChanged

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

它识别文件;它只是告诉您它正在使用中。流必须关闭并处置。我看不到StreamReader甚至没有被关闭,更不用说处置了。即使出现错误,`Using ... End Using块也会关闭并处理对象。

我只是用了一个碰巧要测试的文本文件。

Private strTxtOrderNum As String = "host"

Private Sub ReadFile()
    Using sr As IO.StreamReader = IO.File.OpenText(strTxtOrderNum & ".txt")
        Do Until sr.EndOfStream
            ListBox1.Items.Add(sr.ReadLine)
        Loop
    End Using
End Sub

Private Sub WriteFile()
    Dim strSelectedItem = ComboBox1.Text
    Using swVar As IO.StreamWriter = IO.File.AppendText(strTxtOrderNum & ".txt")
        swVar.WriteLine(strSelectedItem)
    End Using
End Sub