(五)組合查詢-機房收費系統
阿新 • • 發佈:2019-01-02
前提:
組合查詢的思路需要理清,在理清思路的同時,按照先英的想法去執行
一、流程圖 思路
1.用selectcase進行文字轉換
2.利用 if ···then···Select Case n Case Text1.Text = "卡號" b = "cardno" Case Text1.Text = "姓名" b = studentName Case Text1.Text = "上機日期" b = ondate Case Text1.Text = "上機時間" b = ontime Case Text1.Text = "下機日期" b = offdate Case Text1.Text = "下機時間" b = offtime Case Text1.Text = "消費金額" b = consume Case Text1.Text = "餘額" b = cash Case Else End Select </span>
<pre name="code" class="vb"><pre name="code" class="vb">If Combo7.Text = "與" Then one = "and " ElseIf Combo7.Text = "或" Then one = "or " Else one = "" End If If Combo8.Text = "與" Then two = "and " ElseIf Combo8.Text = "或" Then two = "or " Else two = "" End If
3..combo 顯示
(1)利用迴圈,在模組中建立一個 function
Private Sub Form_Load()
a(0) = "卡號"
a(1) = "姓名"
a(2) = "上機日期"
a(3) = "上機時間"
a(4) = "下機日期"
a(5) = "下機時間"
a(6) = "消費金額"
a(7) = "餘額"
Call Combo(Me)
(2)
相應窗體
4.查詢(最基本的執行) 在最一開始除錯的時候 使用的 b 可以直接用 cardno 之列的資料庫中有的表示。後來發現要與combox 裡的內容相對應所以需要Public Function Combo(Nam) For i = 0 To 7 Nam.Combo1.AddItem a(i) Nam.Combo2.AddItem a(i) Nam.Combo3.AddItem a(i) Next End Function
select case 如前面所寫的程式碼
'任務二:查詢
if one= "" then
<span style="white-space:pre"> </span>txtSQL = "select * from line_Info where " & b & combo4.Text & Trim(Text1.Text) & "' "
<span style="white-space:pre"> </span>Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "沒有資訊", vbOKOnly + vbExclamation, "提示"
end if
elseif two =""then
<span style="white-space:pre"> </span><pre name="code" class="vb"><span style="white-space:pre"> </span>txtSQL =txtSQL & one & c & Combo5.Text & "'" & Trim(Text2.Text) & "' "
<span style="white-space:pre"> </span> Set mrc = ExecuteSQL(txtSQL, MsgText)
<span style="white-space:pre"> </span>
If mrc.EOF Then
MsgBox "沒有資訊", vbOKOnly + vbExclamation, "提示"
<span style="white-space:pre"> </span>end if
Else
<pre name="code" class="vb"><span style="white-space:pre"> </span>txtSQL =txtSQL & two & d & Combo6.Text & "'" & Trim(Text2.Text) & "'"
<span> </span> <span style="white-space:pre"> </span>Set mrc = ExecuteSQL(txtSQL, MsgText)
<span> </span>
If mrc.EOF Then
MsgBox "沒有資訊", vbOKOnly + vbExclamation, "提示"<span style="font-family: Arial, Helvetica, sans-serif;">End If</span>
End IfEnd If
總結:
每一個窗體裡都會有很多不一樣的東西慢慢學習,在敲這個窗體的時候對vb的知識的整體運用,才會發現自己的vb學的水平,機房是一個進步,也是一個複習。