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

📄 form3.vb

📁 symbol mc1000进行数据采集代码示例
💻 VB
字号:
Imports System.IO.FileStream
Imports System.IO.File
imports System.IO 
Public Class Form3
    Inherits System.Windows.Forms.Form
    Dim s_name As String
    Dim s_date, s_time, s_barcode, s_kh As String
    Dim file_num As Integer
    Dim i As Long
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label

#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 TextBox2 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("宋体", 10.0!, System.Drawing.FontStyle.Bold)
        Me.Label4.ForeColor = System.Drawing.Color.Red
        Me.Label4.Location = New System.Drawing.Point(24, 16)
        Me.Label4.Size = New System.Drawing.Size(184, 23)
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold)
        Me.Label3.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
        Me.Label3.Location = New System.Drawing.Point(112, 120)
        Me.Label3.Size = New System.Drawing.Size(56, 16)
        Me.Label3.Text = "0"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 120)
        Me.Label2.Size = New System.Drawing.Size(96, 16)
        Me.Label2.Text = "本次扫入总数:"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(24, 80)
        Me.TextBox1.Size = New System.Drawing.Size(176, 21)
        Me.TextBox1.Text = ""
        Me.TextBox1.Visible = False
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 40)
        Me.Label1.Size = New System.Drawing.Size(96, 16)
        Me.Label1.Text = "扫入的条码:"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(16, 56)
        Me.TextBox2.Size = New System.Drawing.Size(176, 21)
        Me.TextBox2.Text = ""
        '
        'Form3
        '
        Me.ClientSize = New System.Drawing.Size(218, 159)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.MaximizeBox = False
        Me.Text = "扫描条码"

    End Sub

#End Region


    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If (e.KeyValue = 37) Or (e.KeyValue = 27) Then
            Me.Close()
        Else
            If e.KeyValue = 13 Then
                Dim fsMyfile As IO.FileStream
                    Dim swMyfile As IO.StreamWriter
                    Label4.Text = ""
                    Dim Lstr As String
                    If File.Exists(P_filename) Then
                        '
                    Else
                        fsMyfile = New IO.FileStream(P_filename, IO.FileMode.CreateNew, IO.FileAccess.Write)
                        swMyfile = New IO.StreamWriter(fsMyfile)
                        swMyfile.Close()
                    fsMyfile.Close()

                    End If

                    
                If Len(Trim(TextBox1.Text)) < 13 Then
                    MessageBox.Show("对不起,你所扫描的条码长度不正确!")
                    TextBox1.Focus()
                    TextBox1.SelectAll()
                    Beep()
                    Exit Sub
                End If

                'Dim fsMyfile1 As New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
                'Dim swMyfile1 As New IO.StreamReader(fsMyfile1)
                'Do
                '    Lstr = swMyfile1.ReadLine
                '    If Len(Trim(Lstr)) < 1 Then
                '        Exit Do
                '        'Else
                '        '    If InStr(1, mdi_str(Lstr), Trim(TextBox1.Text)) > 0 Then
                '        '        Label4.Text = "重复扫描..."
                '        '        TextBox1.Focus()
                '        '        TextBox1.SelectAll()
                '        '        swMyfile1.Close()
                '        '        fsMyfile1.Close()
                '        '        Exit Sub
                '        '    End If
                '    End If

                'Loop
                'swMyfile1.Close()
                'fsMyfile1.Close()
                fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Append, IO.FileAccess.Write)
                swMyfile = New IO.StreamWriter(fsMyfile)
                '********************
                '条形码与书刊号的转换_star
                Dim isbn_barcode As String
                isbn_barcode = Mid(TextBox1.Text, 4, 9)
                Dim isbn_i, isbn_sum As Integer
                isbn_sum = 0
                For isbn_i = 1 To 9
                    isbn_sum = isbn_sum + CInt(Mid(isbn_barcode, isbn_i, 1)) * (11 - isbn_i)
                Next
                Dim isbn_end As Integer
                Dim isbn_star As String
                isbn_end = isbn_sum Mod 11
                If isbn_end = 0 Then
                    isbn_star = "0"
                ElseIf isbn_end = 1 Then
                    isbn_star = "X"
                Else
                    isbn_star = Trim(Str(11 - isbn_end))
                End If
                isbn_barcode = isbn_barcode + isbn_star
                TextBox1.Text = isbn_barcode
                '条形码与书刊号的转换_end
                '********************
                s_date = TextBox1.Text + Chr(9)
                s_time = Now().Today.ToShortDateString + " " + Now().ToLongTimeString + Chr(9)
                s_barcode = "dlksjkfd"
                s_date = s_time + s_date + P_kh
                swMyfile.WriteLine(s_date)
                swMyfile.Flush()
                i = i + 1
                Label3.Text = i.ToString
                swMyfile.Close()
                fsMyfile.Close()
                TextBox1.Focus()
                TextBox1.SelectAll()
                TextBox2.Text = TextBox1.Text
            End If
            End If

    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'file_num = FreeFile()
        i = 0
        TextBox1.Focus()
    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 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 + -