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

📄 form8.vb

📁 symbol mc1000进行数据采集代码示例
💻 VB
字号:
Imports System.io
Public Class Form8
    Inherits System.Windows.Forms.Form
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox

#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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.RadioButton2 = New System.Windows.Forms.RadioButton
        Me.RadioButton1 = New System.Windows.Forms.RadioButton
        Me.ListBox1 = New System.Windows.Forms.ListBox
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(160, 80)
        Me.Button2.Size = New System.Drawing.Size(56, 23)
        Me.Button2.Text = "放弃"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(160, 16)
        Me.Button1.Size = New System.Drawing.Size(56, 23)
        Me.Button1.Text = "删除"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(32, 80)
        Me.TextBox1.Text = ""
        '
        'RadioButton2
        '
        Me.RadioButton2.Checked = True
        Me.RadioButton2.Location = New System.Drawing.Point(32, 48)
        Me.RadioButton2.Text = "指定数据文件"
        '
        'RadioButton1
        '
        Me.RadioButton1.Location = New System.Drawing.Point(32, 16)
        Me.RadioButton1.Text = "所有数据文件"
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(-120, 216)
        Me.ListBox1.Size = New System.Drawing.Size(800, 86)
        Me.ListBox1.Visible = False
        '
        'Form8
        '
        Me.ClientSize = New System.Drawing.Size(234, 135)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.RadioButton2)
        Me.Controls.Add(Me.RadioButton1)
        Me.Controls.Add(Me.ListBox1)
        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 RadioButton1.Checked = True Then
            Dim targetDirectory As String
            targetDirectory = "\data"

            Dim fileEntries() As String = System.IO.Directory.GetFiles(targetDirectory)
            Dim fn As File
            Dim fo As Directory
            If Directory.Exists(targetDirectory) Then
                If Directory.GetFileSystemEntries(targetDirectory).Length = 0 Then
                    Console.WriteLine("Folder " & targetDirectory & " is empty")
                Else
                    Dim i As Long
                    i = 0
                    Do While i >= 0
                        Try

                            If InStr(1, fileEntries(i), ".txt", CompareMethod.Text) > 0 Or InStr(1, fileEntries(i), ".txt", CompareMethod.Text) > 0 Then
                                ListBox1.Items.Add(fileEntries(i))
                                File.Delete(fileEntries(i))
                            End If
                            i = i + 1
                        Catch ex As Exception
                            i = -1
                            Exit Try
                        End Try
                    Loop
                End If
            End If
        Else
            File.Delete("\data\" + Trim(TextBox1.Text) + ".txt")
        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 Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Focus()
    End Sub

    Private Sub Form8_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyValue = 38 Then
            If RadioButton1.Checked = True Then
                RadioButton1.Checked = False
                RadioButton2.Checked = True
            Else
                RadioButton2.Checked = False
                RadioButton1.Checked = True
            End If
        ElseIf e.KeyValue = 40 Or e.KeyValue = 18 Then
            If RadioButton1.Checked = True Then
                RadioButton1.Checked = False
                RadioButton2.Checked = True
            Else
                RadioButton2.Checked = False
                RadioButton1.Checked = True
            End If
        ElseIf e.KeyValue = 13 Then
            If RadioButton2.Checked = True Then
                TextBox1.Focus()
                TextBox1.SelectAll()
            Else
                del()
            End If
        ElseIf e.KeyValue = 37 Or e.KeyValue = 27 Then
            Me.Close()
        End If
    End Sub
    Function del()
        If RadioButton1.Checked = True Then
            Dim targetDirectory As String
            targetDirectory = "\data"

            Dim fileEntries() As String = System.IO.Directory.GetFiles(targetDirectory)
            Dim fn As File
            Dim fo As Directory
            If Directory.Exists(targetDirectory) Then
                If Directory.GetFileSystemEntries(targetDirectory).Length = 0 Then
                    '
                Else
                    Dim i As Long
                    i = 0
                    Do While i >= 0
                        Try

                            If InStr(1, fileEntries(i), ".txt", CompareMethod.Text) > 0 Or InStr(1, fileEntries(i), ".txt", CompareMethod.Text) > 0 Then
                                ListBox1.Items.Add(fileEntries(i))
                                File.Delete(fileEntries(i))
                            End If
                            i = i + 1
                        Catch ex As Exception
                            i = -1
                            Exit Try
                        End Try
                    Loop
                    MsgBox("所有数据文件已删除!", MsgBoxStyle.DefaultButton1, "提示")
                    Me.Focus()
                End If
            End If
        Else
            File.Delete("\data\" + Trim(TextBox1.Text) + ".txt")
            MsgBox("指定数据文件已删除!", MsgBoxStyle.DefaultButton1, "提示")
            Me.Focus()
        End If

    End Function

    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
            del()
        ElseIf e.KeyValue = 37 Or e.KeyValue = 27 Then
            Me.Close()
        End If
    End Sub
End Class

⌨️ 快捷键说明

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