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

📄 form1.vb

📁 一些VB中数组运用的例子
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents txtList As System.Windows.Forms.TextBox
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnSort As System.Windows.Forms.Button
    Friend WithEvents btnCls As System.Windows.Forms.Button
    Friend WithEvents btnIns As System.Windows.Forms.Button
    Friend WithEvents btnDel As System.Windows.Forms.Button
        
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnSort = New System.Windows.Forms.Button
        Me.btnAdd = New System.Windows.Forms.Button
        Me.txtList = New System.Windows.Forms.TextBox
        Me.btnDel = New System.Windows.Forms.Button
        Me.btnIns = New System.Windows.Forms.Button
        Me.btnCls = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnSort
        '
        Me.btnSort.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnSort.Location = New System.Drawing.Point(270, 59)
        Me.btnSort.Name = "btnSort"
        Me.btnSort.Size = New System.Drawing.Size(77, 25)
        Me.btnSort.TabIndex = 8
        Me.btnSort.Text = "排序"
        '
        'btnAdd
        '
        Me.btnAdd.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnAdd.Location = New System.Drawing.Point(270, 17)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(77, 25)
        Me.btnAdd.TabIndex = 0
        Me.btnAdd.Text = "新增"
        '
        'txtList
        '
        Me.txtList.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.txtList.Location = New System.Drawing.Point(22, 17)
        Me.txtList.Multiline = True
        Me.txtList.Name = "txtList"
        Me.txtList.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtList.Size = New System.Drawing.Size(226, 109)
        Me.txtList.TabIndex = 9
        Me.txtList.Text = ""
        '
        'btnDel
        '
        Me.btnDel.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnDel.Location = New System.Drawing.Point(356, 59)
        Me.btnDel.Name = "btnDel"
        Me.btnDel.Size = New System.Drawing.Size(77, 25)
        Me.btnDel.TabIndex = 10
        Me.btnDel.Text = "删除"
        '
        'btnIns
        '
        Me.btnIns.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnIns.Location = New System.Drawing.Point(356, 17)
        Me.btnIns.Name = "btnIns"
        Me.btnIns.Size = New System.Drawing.Size(77, 25)
        Me.btnIns.TabIndex = 9
        Me.btnIns.Text = "插入"
        '
        'btnCls
        '
        Me.btnCls.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnCls.Location = New System.Drawing.Point(270, 101)
        Me.btnCls.Name = "btnCls"
        Me.btnCls.Size = New System.Drawing.Size(77, 25)
        Me.btnCls.TabIndex = 7
        Me.btnCls.Text = "清除"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(444, 134)
        Me.Controls.Add(Me.txtList)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.btnSort)
        Me.Controls.Add(Me.btnCls)
        Me.Controls.Add(Me.btnIns)
        Me.Controls.Add(Me.btnDel)
        Me.Name = "Form1"
        Me.Text = "f10_7_1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    '************** f10_7_1 **************    
    Dim aName As New ArrayList    '声明aName为ArrayList类别数组
    Dim i As Integer
    Dim s_name As String
    Dim s_no As Integer

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        s_name = InputBox("请输入姓名", "新增")
        aName.Add(s_name)
        '在文本框内呈现类别数组的元素内容
        txtList.Text = ""
        For i = 0 To aName.Count - 1
            txtList.Text &= i + 1 & vbTab & aName.Item(i) & vbNewLine
        Next i
    End Sub

    Private Sub btnIns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIns.Click
        Do
            s_no = Val(InputBox("请输入插入编号", "插入"))
        Loop Until s_no > 0 And s_no < aName.Count + 1
        s_name = InputBox("请输入插入姓名", "插入")
        aName.Insert(s_no - 1, s_name)
        txtList.Text = ""
        For i = 0 To aName.Count - 1
            txtList.Text &= i + 1 & vbTab & aName.Item(i) & vbNewLine
        Next i
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        Do
            s_no = Val(InputBox("请输入删除编号", "删除"))
        Loop Until s_no > 0 And s_no < aName.Count + 1
        aName.RemoveAt(s_no - 1)
        txtList.Text = ""
        For i = 0 To aName.Count - 1
            txtList.Text &= i + 1 & vbTab & aName.Item(i) & vbNewLine
        Next i
    End Sub

    Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
        aName.Sort()
        txtList.Text = ""
        For i = 0 To aName.Count - 1
            txtList.Text &= i + 1 & vbTab & aName.Item(i) & vbNewLine
        Next i
    End Sub

    Private Sub btnCls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCls.Click
        aName.Clear()
        txtList.Text = ""
        For i = 0 To aName.Count - 1
            txtList.Text &= i + 1 & vbTab & aName.Item(i) & vbNewLine
        Next i
    End Sub

End Class

⌨️ 快捷键说明

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