此窗体主要有两个功能,一是查看学生的上机记录,二是将上机记录导出为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表是难点,也是新接触的,整个机房会多次用到。还是多了解下。
后期陆续更新,欢迎评论区留言!