📄 frmmain.frm
字号:
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 17
Top = 2880
Width = 1215
End
Begin VB.Label Label4
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Mark2 :"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 16
Top = 2400
Width = 1215
End
Begin VB.Label Label3
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Mark1 :"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 15
Top = 1920
Width = 1215
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Name :"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 14
Top = 1440
Width = 1215
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Roll No :"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 13
Top = 960
Width = 1215
End
End
Begin VB.Label Lbl
Alignment = 2 'Center
BackStyle = 0 'Transparent
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000C000&
Height = 495
Left = 960
TabIndex = 21
Top = 720
Width = 6735
End
Begin VB.Menu file
Caption = "&File"
Begin VB.Menu makeConn
Caption = "&Make Connection"
Shortcut = ^M
End
Begin VB.Menu exit
Caption = "E&xit"
End
End
Begin VB.Menu about
Caption = "&About"
Begin VB.Menu author
Caption = "About Author"
Shortcut = ^A
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Add the Following Reference
'Project --> References... --> Microsoft ActiveX Data Objects 2.0 Library
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'If you know query language then this program will be very easy to understand
Dim con As ADODB.Connection
Dim rSt As Recordset
Dim strCon As String
Private Sub author_Click()
frmAbout.Show , frmMain
End Sub
Private Sub ClearAll()
txtNo = "": txtName = "": txtMark1 = "": txtMark2 = "": txtMark3 = "": txtTotal = "": txtAvg = ""
Call ComboManage
cmdUpdate.Enabled = False
cmdDelete.Enabled = False
cmdAdd.Enabled = True
txtNo.Enabled = True
txtNo.SetFocus
End Sub
Private Sub ComboManage()
On Error GoTo ErrorHandler
ComboNo.Clear
Set rSt = New ADODB.Recordset
rSt.Open "select ROLLNO_0 from StudentDetail", con, adOpenForwardOnly, adLockReadOnly
Do While (Not rSt.EOF)
ComboNo.AddItem (rSt("ROLLNO_0"))
rSt.MoveNext
Loop
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub cmdClearAll_Click()
Call ClearAll
cmdAdd.Enabled = True
End Sub
Private Sub ComboNo_Click()
On Error GoTo ErrorHandler
Set rSt = New ADODB.Recordset
rSt.Open "select * from StudentDetail where ROLLNO_0=" & ComboNo.Text, con, adOpenForwardOnly, adLockReadOnly
txtNo = rSt("ROLLNO_0")
txtName = rSt("NAME_0")
txtMark1 = rSt("MARK1_0")
txtMark2 = rSt("MARK2_0")
txtMark3 = rSt("MARK3_0")
txtTotal = rSt("TOTAL_0")
txtAvg = rSt("AVG_0")
txtNo.Enabled = False
cmdUpdate.Enabled = True
cmdDelete.Enabled = True
cmdAdd.Enabled = False
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub Form_Load()
strCon = App.Path
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strCon & "\Student.mdb"
End Sub
Private Sub addNew_Click()
FrameMain(1).Visible = True
cmdAdd.Visible = True: txtNo.Visible = True
cmdUpdate.Visible = False: cmdDelete.Visible = False: ComboNo.Visible = False
Label = "Adding New Student"
Call ClearAll
End Sub
Private Sub makeConn_Click()
On Error GoTo ErrorHandler
'MsgBox strCon
Set con = New ADODB.Connection
con.ConnectionString = strCon
con.Open
Call ComboManage
makeConn.Enabled = False: makeConn.Visible = False
FrameMain(1).Enabled = True
Set rSt = New ADODB.Recordset
rSt.Open "select * from StudentDetail", con, adOpenForwardOnly, adLockReadOnly
txtNo = rSt("ROLLNO_0")
txtName = rSt("NAME_0")
txtMark1 = rSt("MARK1_0")
txtMark2 = rSt("MARK2_0")
txtMark3 = rSt("MARK3_0")
txtTotal = rSt("TOTAL_0")
txtAvg = rSt("AVG_0")
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub cmdAdd_Click()
On Error GoTo ErrorHandler
Dim a As New Command
Dim intTotal As Integer ', dblAvg As Double
Set a.ActiveConnection = con
''''''''''''''''''''''''''''''''''''
intTotal = Val(txtMark1) + Val(txtMark2) + Val(txtMark3)
''''''''''''''''''''''''''''''''''''
a.CommandText = "insert into StudentDetail values(" & txtNo & ",'" & txtName & "'," & txtMark1 & "," & txtMark2 & "," & txtMark3 & "," & intTotal & "," & intTotal / 3 & ")"
a.Execute
MsgBox "Record Added"
Call ComboManage: Call ClearAll
txtNo.SetFocus
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub cmdUpdate_Click()
'On Error GoTo ErrorHandler
Dim a As New Command
Dim intTotal As Integer ', dblAvg As Double
'con.Close
'con.Open
Set a.ActiveConnection = con
''''''''''''''''''''''''''''''''''''
intTotal = Val(txtMark1) + Val(txtMark2) + Val(txtMark3)
''''''''''''''''''''''''''''''''''''
rSt.Close
rSt.ActiveConnection = con
rSt.Open "select * from StudentDetail", con, adSearchForward, adLockOptimistic
' rSt.Find
' rSt.ActiveCommand = a
rSt.Find "[ROLLNO_0]=" & ComboNo.Text, 1, adSearchForward
s = "[" & txtName & "," & txtMark1 & " , " & txtMark2 & "," & txtMark3 & "," & intTotal & "," & intTotal / 3 & "]"
' rSt.update "[NAME=,MARK1=,MARK2=,MARK3=,TOTAL=,AVG=]", s
'1,2,3,4,5,6
a.CommandText = "Update StudentDetail set NAME_0='" & txtName & _
"',MARK1_0=" & txtMark1 & ",MARK2_0=" & txtMark2 & ",MARK3_0=" & _
txtMark3 & ",TOTAL_0=" & intTotal & ",AVG_0=" & intTotal / 3 & _
" where ROLLNO_0=" & ComboNo.Text
a.Execute
MsgBox "Record Updated"
Set rSt = New ADODB.Recordset
rSt.Open "select * from StudentDetail where ROLLNO_0=" & txtNo.Text, con, adOpenForwardOnly, adLockReadOnly
txtNo = rSt("ROLLNO_0")
txtName = rSt("NAME_0")
txtMark1 = rSt("MARK1_0")
txtMark2 = rSt("MARK2_0")
txtMark3 = rSt("MARK3_0")
txtTotal = rSt("TOTAL_0")
txtAvg = rSt("AVG_0")
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub cmdDelete_Click()
On Error GoTo ErrorHandler
Dim a As New Command
Dim intTotal As Integer ', dblAvg As Double
Set a.ActiveConnection = con
a.CommandText = "delete from StudentDetail where ROLLNO_0=" & ComboNo.Text
MsgBox "Record Deleted"
a.Execute
Call ComboManage: Call ClearAll
Exit Sub
ErrorHandler:
MsgBox Error
End Sub
Private Sub exit_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -