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

📄 form6.vb

📁 symbol mc1000进行数据采集代码示例
💻 VB
字号:
Public Class Form6
    Inherits System.Windows.Forms.Form
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    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 TextBox4 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox4 = New System.Windows.Forms.TextBox
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(136, 120)
        Me.Button2.Size = New System.Drawing.Size(72, 24)
        Me.Button2.Text = "放弃"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(32, 120)
        Me.Button1.Size = New System.Drawing.Size(72, 24)
        Me.Button1.Text = "更改"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(88, 80)
        Me.TextBox3.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox3.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(88, 48)
        Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox2.Text = ""
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(88, 16)
        Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox1.Text = ""
        '
        'Label3
        '
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlDarkDark
        Me.Label3.Location = New System.Drawing.Point(24, 80)
        Me.Label3.Size = New System.Drawing.Size(72, 23)
        Me.Label3.Text = "确认口令:"
        '
        'Label2
        '
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlDarkDark
        Me.Label2.Location = New System.Drawing.Point(24, 48)
        Me.Label2.Size = New System.Drawing.Size(64, 23)
        Me.Label2.Text = "新口令:"
        '
        'Label1
        '
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlDarkDark
        Me.Label1.Location = New System.Drawing.Point(24, 16)
        Me.Label1.Size = New System.Drawing.Size(64, 23)
        Me.Label1.Text = "原口令:"
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(280, 27)
        Me.TextBox4.Multiline = True
        Me.TextBox4.Size = New System.Drawing.Size(184, 104)
        Me.TextBox4.Text = ""
        '
        'Form6
        '
        Me.ClientSize = New System.Drawing.Size(242, 159)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        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 TextBox1.Text = P_pass Then
            If Trim(TextBox2.Text) = Trim(TextBox3.Text) And Len(Trim(TextBox2.Text)) Then
                Dim sbStrBuilder1 As New System.Text.StringBuilder(TextBox4.Text)
                Dim str, new_str As String
                str = P_kh + Chr(9) + P_pass
                new_str = P_kh + Chr(9) + Trim(TextBox3.Text)
                sbStrBuilder1.Replace(str, new_str)
                TextBox4.Text = sbStrBuilder1.ToString()
                P_filename = "work.dat"
                Dim fsMyfile As New IO.FileStream(P_filename, IO.FileMode.Create, IO.FileAccess.Write)
                Dim swMyfile As New IO.StreamWriter(fsMyfile)
                swMyfile.WriteLine(TextBox4.Text)
                swMyfile.Flush()

                swMyfile.Close()
                fsMyfile.Close()
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub


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

    End Sub

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyValue = 13 Then
            TextBox2.Focus()
            TextBox2.SelectAll()
        End If
    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 = 13 Then
            TextBox3.Focus()
            TextBox3.SelectAll()
        End If
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
        If e.KeyValue = 27 Or e.KeyValue = 37 Then
            Me.Close()
        End If

        If e.KeyValue = 13 Then
            If TextBox1.Text = P_pass Then
                If Trim(TextBox2.Text) = Trim(TextBox3.Text) And Len(Trim(TextBox2.Text)) >= 1 Then
                    Dim sbStrBuilder1 As New System.Text.StringBuilder(TextBox4.Text)
                    Dim str, new_str As String
                    str = P_kh + Chr(9) + P_pass
                    new_str = P_kh + Chr(9) + Trim(TextBox3.Text)
                    sbStrBuilder1.Replace(str, new_str)
                    TextBox4.Text = sbStrBuilder1.ToString()
                    P_filename = P_path + "work.dat"
                    Dim fsMyfile As New IO.FileStream(P_filename, IO.FileMode.Create, IO.FileAccess.Write)
                    Dim swMyfile As New IO.StreamWriter(fsMyfile)
                    swMyfile.WriteLine(TextBox4.Text)
                    swMyfile.Flush()
                    swMyfile.Close()
                    fsMyfile.Close()
                    Me.Close()
                Else
                    MsgBox("两次输入口令不一至!", MsgBoxStyle.DefaultButton1, "对不起")
                    TextBox1.Focus()
                    TextBox1.SelectAll()
                End If
            Else
                MsgBox("输入的原口令不正确!", MsgBoxStyle.DefaultButton1, "对不起")
                TextBox1.Focus()
                TextBox1.SelectAll()
            End If
        End If
    End Sub

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        P_path = "\data\"
        P_filename = P_path + "work.dat"
        Dim lstr, pass As String
        '存在时,不存在时新建
        ''''''''''''''''''''''''''''''''////////////////
        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)
        Catch ex As Exception
            Label2.Text = "文件不存在!"
            Exit Sub
        End Try
        Do
            lstr = swMyfile.ReadLine
            If Len(Trim(lstr)) < 1 Then
                Exit Do
            End If
            TextBox4.Text = TextBox4.Text + lstr + Chr(13) + Chr(10)
        Loop
        swMyfile.Close()
        fsMyfile.Close()
        TextBox1.Focus()
        TextBox1.SelectAll()
    End Sub
End Class

⌨️ 快捷键说明

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