1. 程式人生 > >機房——一般使用者——檢視上機記錄

機房——一般使用者——檢視上機記錄

此窗體主要有兩個功能,一是檢視學生的上機記錄,二是將上機記錄匯出為Excel表
在這裡插入圖片描述
敲窗體之前要先做流程圖,流程圖是機房學習必不可少的步驟
在這裡插入圖片描述
查詢功能部分程式碼展示

 If txtCardNo.Text = "" Then
        MsgBox "請輸入卡號!", vbOKOnly + vbExclamation, "提示"
        txtCardNo.SetFocus
        Exit Sub
    
    Else
        txtsql = "select * from line_info where cardno='" & txtCardNo.Text & "'"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        
        If mrc.EOF = True Then
            MsgBox "沒有資料或卡號不存在", vbOKOnly + vbExclamation, "提示"
            txtCardNo.Text = ""
            txtCardNo.SetFocus
            Exit Sub
        End If
    End If
    
    With myFlexgrid
        .rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "卡號"
        .TextMatrix(0, 1) = "姓名"
        .TextMatrix(0, 2) = "上機日期"
        .TextMatrix(0, 3) = "上機時間"
        .TextMatrix(0, 4) = "下機日期"
        .TextMatrix(0, 5) = "下機時間"
        .TextMatrix(0, 6) = "消費金額"
        .TextMatrix(0, 7) = "餘額"
        .TextMatrix(0, 8) = "備註"
        
        txtsql = "select * from line_info "
        Set mrc1 = ExecuteSQL(txtsql, msgtext)
        
        Do While mrc1.EOF = False
        
            .rows = .rows + 1
            .CellAlignment = 4
            .TextMatrix(.rows - 1, 0) = Trim(mrc.Fields(1))
            .TextMatrix(.rows - 1, 1) = Trim(mrc.Fields(3))
            .TextMatrix(.rows - 1, 2) = Trim(mrc.Fields(6))
            .TextMatrix(.rows - 1, 3) = Trim(mrc.Fields(7))
            .TextMatrix(.rows - 1, 4) = Trim(mrc.Fields(8))
            .TextMatrix(.rows - 1, 5) = Trim(mrc.Fields(9))
            .TextMatrix(.rows - 1, 6) = Trim(mrc.Fields(11))
            .TextMatrix(.rows - 1, 7) = Trim(mrc.Fields(12))
            .TextMatrix(.rows - 1, 8) = Trim(mrc.Fields(13))
            
                
            mrc1.MoveNext    '移動到下一條記錄
        Loop
        End With

當查詢出資料後,就要將資料匯出為Excel表
匯出Excel表及程式碼:參考部落格http://blog.sina.com.cn/s/blog_17e40bf4d0102y8yy.html
很簡單的功能,匯出Excel表是難點,也是新接觸的,整個機房會多次用到。還是多瞭解下。
後期陸續更新,歡迎評論區留言!