VB6 & Access2k 簡易選擇題庫做法


簡易分析:
1.從資料庫取出題目與答案
2.隨機取出(防止重覆處理暫時不寫)
3.答對時給予訊息(計分方式暫時不寫)
4.放棄題目,重新取出一組














-------------------------------------------------
  
Option Explicit  
Dim cn As ADODB.Connection  
Dim rs As ADODB.Recordset  
Dim ssql As String, ans As String  
Dim i As Integer  
Private Sub Command1_Click(Index As Integer)  
    Select Case Index  
        Case 1  
            ref  
        Case 2  
            If ans = rs.Fields(6).Value Then MsgBox "答對了!!"  
            For i = 0 To 3  
                Option1(i).Value = 0  
            Next  
    End Select  
End Sub  
Private Sub Form_Load()  
    '設定連結資料庫  
    Set cn = New ADODB.Connection  
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _  
                     "\Test.mdb;Persist Security Info=False;Jet OLEDB:Database Password=;"  
    cn.CursorLocation = adUseClient  
    '使用sql語法查詢  
    ssql = "select * from Question"  
    Set rs = cn.Execute(ssql)  
    ref  
End Sub  
Public Sub ref()  
    Dim tmprnd As Integer  
    '產生RecordCount亂數值,防止亂數重覆的部份未寫  
    tmprnd = Int(((rs.RecordCount) * Rnd) + 1)  
    rs.Move tmprnd - 1, 1  
    Text2.Text = rs.Fields(1).Value  
    For i = 0 To 3  
        Option1(i).Caption = rs.Fields(i + 2).Value  
    Next  
End Sub  
Private Sub Option1_Click(Index As Integer)  
'如果要用數字1234當選項,ASCII 字元65換成49  
ans = Chr(Index + 65)  
End Sub  
 

沒有留言:

張貼留言