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

📄 main.frm

📁 vb源码大全
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "简易学生信息管理"
   ClientHeight    =   2685
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4830
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2685
   ScaleWidth      =   4830
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdModifyBirthday 
      Caption         =   "修改>>"
      Height          =   350
      Left            =   3960
      TabIndex        =   11
      Top             =   60
      Width           =   735
   End
   Begin VB.CommandButton cmdModifyName 
      Caption         =   "修改>>"
      Height          =   350
      Left            =   2040
      TabIndex        =   10
      Top             =   60
      Width           =   735
   End
   Begin VB.Frame fraOperate 
      Height          =   1575
      Left            =   1560
      TabIndex        =   6
      Top             =   960
      Width           =   3135
      Begin VB.CommandButton cmdAbout 
         Caption         =   "关于(&A)..."
         Height          =   495
         Left            =   1680
         TabIndex        =   12
         Top             =   960
         Width           =   1215
      End
      Begin VB.CommandButton cmdAddRecord 
         Caption         =   "增加记录(&A)"
         Height          =   495
         Left            =   240
         TabIndex        =   9
         Top             =   240
         Width           =   1215
      End
      Begin VB.CommandButton cmdReportRecord 
         Caption         =   "报告记录(&R)"
         Height          =   495
         Left            =   240
         TabIndex        =   8
         Top             =   960
         Width           =   1215
      End
      Begin VB.CommandButton cmdDeleteRecord 
         Caption         =   "删除记录(&D)"
         Height          =   495
         Left            =   1680
         TabIndex        =   7
         Top             =   240
         Width           =   1215
      End
   End
   Begin VB.TextBox txtName 
      Height          =   375
      Left            =   1560
      Locked          =   -1  'True
      TabIndex        =   2
      Top             =   480
      Width           =   1215
   End
   Begin VB.TextBox txtBirthday 
      Height          =   375
      Left            =   3120
      Locked          =   -1  'True
      TabIndex        =   1
      Top             =   480
      Width           =   1575
   End
   Begin VB.ListBox lstSerial 
      Height          =   2010
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   1215
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "学号:"
      Height          =   180
      Left            =   120
      TabIndex        =   5
      Top             =   120
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "出生日期:"
      Height          =   180
      Left            =   3000
      TabIndex        =   4
      Top             =   120
      Width           =   900
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "姓名:"
      Height          =   180
      Left            =   1440
      TabIndex        =   3
      Top             =   120
      Width           =   540
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

''声明一个学生对象,注意由于需要处理事件,需要使用WithEvents关键字
Dim WithEvents mStudent As clsStudent
Attribute mStudent.VB_VarHelpID = -1

''声明用来保存学生对象的集合
Dim colStudent As New Collection

''保存最大的学号,可以通过在mnMaxSerial+1来作为新增的学生对象的学号
Dim mnMaxSerial As Integer

Private Sub cmdAbout_Click()
   ''实例化一个About窗口类
   Dim frm As New frmAbout
   
   ''调用About窗口对象的ShowDialog方法显示窗体
   frm.ShowDialog 1, "关于学生信息管理系统", "简易学生管理系统!", "版本:1.1.1", 5
End Sub

Private Sub cmdAddRecord_Click()
   ''生成学生的学号
   mnMaxSerial = mnMaxSerial + 1
   
   Dim strName As String
   Dim strBirthday As String
   
   ''获取学生的姓名
   strName = Trim(InputBox("输入新增学生的姓名:"))
   If strName = "" Then Exit Sub
   
   ''获取学生的出生日期
   strBirthday = Trim(InputBox("输入新增学生的出生日期(1980-1-1):", , "1980-9-1"))
   If strBirthday = "" Then
      If Not IsDate(strBirthday) Then MsgBox "学生的出生日期错误!"
      Exit Sub
   End If
   
   ''创建一个学生对象
   Set mStudent = New clsStudent
   Dim bResult As Boolean
   bResult = mStudent.Create(CStr(mnMaxSerial), strName, CDate(strBirthday))
   
   ''若创建了以学生对象,则将其加入到集合colStudent中
   If bResult Then
      colStudent.Add mStudent, CStr(mnMaxSerial)
   
      ''添加到列表框中,并选中对应的学生记录
      lstSerial.AddItem CStr(mnMaxSerial)
      lstSerial.ListIndex = lstSerial.ListCount - 1
   Else
      Set mStudent = Nothing
      Set mStudent = New clsStudent
   End If
End Sub

Private Sub cmdDeleteRecord_Click()
   ''如果mStudent不代表任何的记录元素(此时mStudent的Serial属性为空),则退出过程
   If mStudent.Serial = "" Then Exit Sub
   
   ''首先在lstSerial中删除该学生记录的学号
   Dim i As Integer
   For i = 0 To lstSerial.ListCount - 1
      If lstSerial.List(i) = mStudent.Serial Then
          lstSerial.RemoveItem i
          Exit For
      End If
   Next i
   
   ''从集合中将该学生对象删除掉
   colStudent.Remove mStudent.Serial
   
   If lstSerial.ListCount >= 1 Then
      lstSerial.ListIndex = 0
   Else
      Set mStudent = Nothing
      Set mStudent = New clsStudent
      
      txtName.Text = ""
      txtBirthday.Text = ""
   End If
End Sub

Private Sub cmdModifyBirthday_Click()
   ''如果mStudent不代表任何的记录元素(此时mStudent的Serial属性为空),则退出过程
   If mStudent.Serial = "" Then Exit Sub
   
   ''取得学生的出生日期,并将其赋给学生对象的Birthday属性。
   Dim strBirthday As String
   strBirthday = Trim(InputBox("输入该学生的出生日期(1980-1-1):", , mStudent.Birthday))
   
   If strBirthday = "" Or strBirthday = mStudent.Birthday Then
      If Not IsDate(strBirthday) Then MsgBox "学生的出生日期错误!"
      
      Exit Sub
   End If
   
   mStudent.Birthday = strBirthday
   mStudent.Refresh
End Sub

Private Sub cmdModifyName_Click()
   ''如果mStudent不代表任何的记录元素(此时mStudent的Serial属性为空),则退出过程
   If mStudent.Serial = "" Then Exit Sub

   Dim strName As String
   strName = Trim(InputBox("输入该学生的姓名:", , mStudent.StudentName))
   If strName = "" Or mStudent.StudentName = strName Then Exit Sub
   
   mStudent.StudentName = strName
   mStudent.Refresh
End Sub

Private Sub cmdReportRecord_Click()
   ''如果mStudent不代表任何的记录元素(此时mStudent的Serial属性为空),则退出过程
   If mStudent.Serial = "" Then Exit Sub
   
   If Not IsNull(mStudent) Then
      mStudent.Report ''调用Report方法
   End If
End Sub

Private Sub Form_Load()
   mnMaxSerial = 1000
   
   Set mStudent = New clsStudent
End Sub

Private Sub Form_Unload(Cancel As Integer)
   ''卸载mStudent对象
   Set mStudent = Nothing
End Sub

Private Sub lstSerial_Click()
   If lstSerial.ListIndex >= 0 Then
      ''根据lstSerial中所选的学号,来调用mStudent的Refresh方法更新显示
      Set mStudent = colStudent(lstSerial.Text)
      mStudent.Refresh
   End If
End Sub

Private Sub mStudent_Error(ByVal msgErr As String)
   ''用来响应Error错误事件
   ''使用MsgBox方法来显示错误信息
   Dim str As String
   str = "出现以下错误:" & vbCrLf
   str = str & msgErr
   MsgBox str, vbCritical, "错误"
End Sub

Private Sub mStudent_RefreshRecord(ByVal theName As String, ByVal theDate As Date)
   ''用来产生对RefreshRecord事件的响应
   ''将学生记录的姓名和出生日期属性赋给对应的文本框
   txtName.Text = theName
   txtBirthday.Text = theDate
End Sub

Private Sub mStudent_ReportRecord(ByVal theSerial As String, ByVal theName As String, ByVal theAge As Integer)
   ''用来产生对ReportRecord事件的响应
   ''使用MsgBox方法来显示学生的各种信息
   MsgBox "学号为:" & theSerial & vbCrLf & _
            "姓名为:" & theName & vbCrLf & "年龄为:" & theAge, vbInformation, "学生信息"
            
End Sub

⌨️ 快捷键说明

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