【前言】
机房收费系统在验收的时候,师父最后给我提了一个建议,希望我可以关于机房收费系统的常用语句总结一下,那些固定的语句以后也会经常会用到,总结一下对于以后的学习比较有利,自己也较有同感,因此写下这篇博客。
【正文】
一、对于数据库的增、删、改、查
<定义>:
<span style="font-size:18px;"> Dim mrc As ADODB.Recordset Dim txtSQL As String Dim Msgtext As String </span>
<增>:
<span style="font-size:18px;"> mrc.AddNew With mrc .Fields(1) = txtCardID.Text .Fields(2) = txtSID.Text .Fields(3) = txtName.Text .Fields(4) = txtDepart.Text .Fields(5) = txtSex.Text .Fields(6) = txtOndate.Text .Fields(7) = txtOntime.Text .Fields(8) = txtOffdate.Text .Fields(9) = txtOfftime.Text .Fields(10) = txtContime.Text .Fields(11) = Val(txtConsume.Text) .Fields(12) = Val(txtCash.Text) .Fields(13) = "正常下机" .Fields(14) = Winsock1.LocalHostName End With mrc.Update</span>
<查>:
查询条件限制为1条:
<span style="font-size:18px;"> </span><span style="font-size:18px;">txtSQL = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext)</span>
查询条件限制为多条:
<span style="font-size:18px;"> txtSQL = "select * from student_Info where cardno ='" & Trim(txtCardID.Text) & "'and status='" & "不使用" & "'" Set mrcStudent = ExecuteSQL(txtSQL, Msgtext)</span>
对于SQL数据库的一些操作经常会出现很多引号,容易出现错误,不明白如何将这些引号断开来看,下图是根据自己的理解来划分引号的位置(如果大家有不同的见解,希望我们可以讨论):
二、对于MDI窗体及窗体上的图片,如何将子窗体在运行的时候显示
<定义API函数>:
<span style="font-size:18px;">Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long </span>
<将窗体显示>:
<span style="font-size:18px;">SetParent frmReCashRecord.hWnd, Picture1.hWnd</span>
三、将数据库中的信息显示在MSFlexGrid1控件中
<span style="font-size:18px;">With MSFlexGrid1 .CellAlignment = 4 .Rows = 1 .TextMatrix(0, 0) = "用户名" .TextMatrix(0, 1) = "姓名" .TextMatrix(0, 2) = "开户人" Do While mrc.EOF = False .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0)) .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(3)) .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(1)) mrc.MoveNext Loop End With</span>
四、对于MDI窗体,如何使在打开第二个窗体时将第一个窗体最小化在MDI窗体的左下端
<span style="font-size:18px;">Private Sub form_Activate() Dim a As Form For Each a In Forms If a.Name <> frmMain.Name And a.Name <> Me.Name Then a.WindowState = 1 '1为窗体最小化,0为正常,2为最大 Me.ZOrder 0 '日结账单窗体显示在MDI窗体的最前端 End If Next End Sub</span>
五、将MSFlexGrid控件中的信息导出到Excel表
<span style="font-size:18px;">Public Sub OutDataToExcel(Flex As MSFlexGrid) '导出至Excel表的过程 Dim s As String Dim i As Integer Dim j As Integer Dim k As Integer On Error GoTo ert Me.MousePointer = 11 Dim Excelapp As Excel.Application Set Excelapp = New Excel.Application On Error Resume Next DoEvents Excelapp.SheetsInNewWorkbook = 1 '代表新插入工作表的个数 Excelapp.Workbooks.Add Excelapp.ActivateSheet.Cells(1, 3) = s Excelapp.Range("C1").Select Excelapp.Selection.Font.FontStyle = "Bold" Excelapp.Selection.Font.Size = 16 With Flex k = .Rows For i = 0 To k - 1 For j = 0 To .Cols - 1 DoEvents Excelapp.ActivateSheet.Cells(3 + i, j + 1) = "'" & .TextMatrix(i, j) Next j Next i End With Me.MousePointer = 0 Excelapp.Visible = True ert: If Not (Excelapp Is Nothing) Then Excelapp.Quit End If End Sub Private Sub cmdExcel_Click() OutDataToExcel MSFlexGrid1 End Sub</span>
六、关于选择日期的时候,出现起始和终止日期,设置温馨提示(不可晚于目前日期、终止日期不可小于起始日期)
<span style="font-size:18px;">Private Sub DTPicker1_change() If DTPicker1.Value > Date Then MsgBox "起始日期晚于目前日期,请验证", vbOKOnly + vbExclamation, "警告" DTPicker1.Value = Date End If End Sub Private Sub DTPicker2_change() If DTPicker2.Value > Date Then MsgBox "终止日期晚于目前日期,请验证", vbOKOnly + vbExclamation, "警告" DTPicker2.Value = Date End If Dim a As Integer a = DateDiff("d", DTPicker1.Value, DTPicker2.Value) If a <= 0 Then MsgBox "终止日期需晚于起始日期,请验证", vbOKOnly + vbExclamation, "警告" Exit Sub End If End Sub</span>
【总结】
在总结的过程中,再次加深了对这些常用语句的印象。学习完后总结是必不可少的,这篇博客希望可以对大家有所帮助,在以后前进的道路上多回头看看。