⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form4.vb

📁 symbol mc1000进行数据采集代码示例
💻 VB
字号:
Public Class Form4
    Inherits System.Windows.Forms.Form
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Dim s_name As String
    Dim s_date, s_time, s_barcode, s_kh As String
    Dim file_num As Integer
    Dim i, j As Long
    Dim txtlineCount As Long

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button5 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button4 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Label3 = New System.Windows.Forms.Label
        '
        'Label2
        '
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlDarkDark
        Me.Label2.Location = New System.Drawing.Point(16, 48)
        Me.Label2.Size = New System.Drawing.Size(88, 16)
        Me.Label2.Text = "所扫条码:"
        '
        'Label1
        '
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlDarkDark
        Me.Label1.Location = New System.Drawing.Point(16, 16)
        Me.Label1.Size = New System.Drawing.Size(56, 16)
        Me.Label1.Text = "文件名:"
        '
        'Button5
        '
        Me.Button5.Font = New System.Drawing.Font("宋体", 8.0!, System.Drawing.FontStyle.Bold)
        Me.Button5.Location = New System.Drawing.Point(32, 104)
        Me.Button5.Size = New System.Drawing.Size(72, 23)
        Me.Button5.Text = "第一条&("
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(40, 72)
        Me.TextBox1.Size = New System.Drawing.Size(160, 21)
        Me.TextBox1.Text = ""
        '
        'Button4
        '
        Me.Button4.Font = New System.Drawing.Font("宋体", 8.0!, System.Drawing.FontStyle.Bold)
        Me.Button4.Location = New System.Drawing.Point(144, 136)
        Me.Button4.Size = New System.Drawing.Size(72, 23)
        Me.Button4.Text = "未尾条&)"
        '
        'Button3
        '
        Me.Button3.Font = New System.Drawing.Font("宋体", 8.0!, System.Drawing.FontStyle.Bold)
        Me.Button3.Location = New System.Drawing.Point(144, 104)
        Me.Button3.Size = New System.Drawing.Size(72, 23)
        Me.Button3.Text = "上一条&∩"
        '
        'Button2
        '
        Me.Button2.Font = New System.Drawing.Font("宋体", 8.0!, System.Drawing.FontStyle.Bold)
        Me.Button2.Location = New System.Drawing.Point(32, 136)
        Me.Button2.Size = New System.Drawing.Size(72, 23)
        Me.Button2.Text = "下一条&∪"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(184, 16)
        Me.Button1.Size = New System.Drawing.Size(56, 23)
        Me.Button1.Text = "确定"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(80, 16)
        Me.TextBox2.Size = New System.Drawing.Size(88, 21)
        Me.TextBox2.Text = ""
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(240, 176)
        Me.ListBox1.Size = New System.Drawing.Size(100, 98)
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold)
        Me.Label3.Location = New System.Drawing.Point(96, 48)
        Me.Label3.Size = New System.Drawing.Size(96, 16)
        Me.Label3.Text = "0"
        '
        'Form4
        '
        Me.ClientSize = New System.Drawing.Size(258, 167)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button5)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox2)
        Me.MaximizeBox = False
        Me.Text = "扫描条码"

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Len(Trim(TextBox2.Text)) < 1 Then
            MsgBox("文件名不能为空!", MsgBoxStyle.DefaultButton1, "文件错误")
            Exit Sub
        End If
        P_filename = P_path + Trim(TextBox2.Text) + ".txt"
        Dim fsMyfile As IO.FileStream
        Dim swMyfile As IO.StreamReader
        '存在时,不存在时新建
        Try
            fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
            swMyfile = New IO.StreamReader(fsMyfile)
            Button2.Enabled = True
            Button3.Enabled = True
            Button4.Enabled = True
            Button5.Enabled = True
        Catch ex As Exception
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            MsgBox("文件不存在!", MsgBoxStyle.DefaultButton1, "对不起")
            Exit Sub
        End Try

        Dim lstr As String
        Do
            lstr = swMyfile.ReadLine
            If Len(Trim(lstr)) < 1 Then
                Exit Do
            Else
                ListBox1.Items.Add(lstr)
            End If
        Loop
        swMyfile.Close()
        fsMyfile.Close()
    End Sub

    Function mdi_str(ByVal str As String)
        Dim s, t As String
        s = ""
        Dim mdi_i As Integer
        mdi_i = InStr(1, str, Chr(9))
        mdi_i = mdi_i + 1

        Do While Mid(str, mdi_i, 1) <> Chr(9)
            s = s + Mid(str, mdi_i, 1)
            mdi_i = mdi_i + 1
        Loop
        Return s
    End Function

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = mdi_str(ListBox1.Items(0).ToString)
        i = 0
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        i = i - 1
        If i < 0 Then
            i = 0
            MsgBox("文件已到开始处!", MsgBoxStyle.DefaultButton1, "操作有误")
            Exit Sub
        End If
        TextBox1.Text = mdi_str(ListBox1.Items(i).ToString)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        i = i + 1
        If i > ListBox1.Items.Count - 1 Then
            i = ListBox1.Items.Count - 1
            MsgBox("文件已到未尾!", MsgBoxStyle.DefaultButton1, "操作有误")
            Exit Sub
        End If
        TextBox1.Text = mdi_str(ListBox1.Items(i).ToString)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = mdi_str(ListBox1.Items(ListBox1.Items.Count - 1).ToString)
        i = ListBox1.Items.Count - 1
    End Sub

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        TextBox2.Focus()
        TextBox2.SelectAll()
        'Me.Focus()
        i = 0
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyValue = 37 Or e.KeyValue = 27 Then
            Me.Close()
        End If
        If e.KeyValue = 13 Then
            If Len(Trim(TextBox2.Text)) < 1 Then
                MsgBox("文件名不能为空!", MsgBoxStyle.DefaultButton1, "文件错误")
                TextBox2.Focus()
                TextBox2.SelectAll()
                Exit Sub
            End If
            j = 0
            P_filename = P_path + Trim(TextBox2.Text) + ".txt"
            Dim fsMyfile As IO.FileStream
            Dim swMyfile As IO.StreamReader
            '存在时,不存在时新建
            Try
                fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
                swMyfile = New IO.StreamReader(fsMyfile)
                Button2.Enabled = True
                Button3.Enabled = True
                Button4.Enabled = True
                Button5.Enabled = True
                Me.Focus()
            Catch ex As Exception
                Button2.Enabled = False
                Button3.Enabled = False
                Button4.Enabled = False
                Button5.Enabled = False
                MsgBox("文件不存在!", MsgBoxStyle.DefaultButton1, "对不起")
                TextBox2.Focus()
                TextBox2.SelectAll()
                Exit Sub
            End Try

            Dim lstr As String
            Do
                lstr = swMyfile.ReadLine
                If Len(Trim(lstr)) < 1 Then
                    Exit Do
                Else
                    j = j + 1
                    ListBox1.Items.Add(lstr)
                End If
            Loop
            Label3.Text = j.ToString
            TextBox1.Text = mdi_str(ListBox1.Items(0).ToString)
            i = 0
            swMyfile.Close()
            fsMyfile.Close()
        End If
    End Sub

    Private Sub Form4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyValue = 37 Or e.KeyValue = 27 Then
            TextBox1.Text = mdi_str(ListBox1.Items(0).ToString)
            i = 0
            Me.Focus()
        ElseIf e.KeyValue = 38 Then
            i = i - 1
            If i < 0 Then
                i = 0
                MsgBox("文件已到开始处!", MsgBoxStyle.DefaultButton1, "操作有误")
                Me.Focus()
                Exit Sub
            End If
            TextBox1.Text = mdi_str(ListBox1.Items(i).ToString)
            Me.Focus()
        ElseIf e.KeyValue = 40 Or e.KeyValue = 18 Then
            i = i + 1
            If i > ListBox1.Items.Count - 1 Then
                i = ListBox1.Items.Count - 1
                MsgBox("文件已到未尾!", MsgBoxStyle.DefaultButton1, "操作有误")
                Me.Focus()
                Exit Sub
            End If
            TextBox1.Text = mdi_str(ListBox1.Items(i).ToString)
            Me.Focus()
        ElseIf e.KeyValue = 39 Then
            TextBox1.Text = mdi_str(ListBox1.Items(ListBox1.Items.Count - 1).ToString)
            i = ListBox1.Items.Count - 1
            Me.Focus()
        ElseIf e.KeyValue = 13 Then
            Me.Close()
        End If

        Label3.Text = (i + 1).ToString + "/" + j.ToString
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -