home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Quiz_Softw2029431162006.psc / cExamDB.cls < prev    next >
Text File  |  2003-07-04  |  5KB  |  179 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cExamDB"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' Primary.mdb
  17. '   - all correct answers are stored in Option 1.
  18. '   - you can add as many categories as you like.
  19.  
  20. Public Title      As String
  21. Public Direction  As String
  22. Public TotalItems As Integer
  23. Public MaxTime    As Integer
  24.  
  25. Public CurCategory As Integer
  26.  
  27. Dim DB As Database
  28. Dim RS As Recordset
  29.  
  30. Public Sub InitExam(Filename As String)
  31.     On Error GoTo ErrOpen
  32.     
  33.     Set DB = OpenDatabase(Filename)
  34.     
  35.     Dim tdfLoop As TableDef, oTemp As Object
  36.     
  37.     ' read all tables
  38.     For Each tdfLoop In DB.TableDefs
  39.         If Trim(UCase(Left(tdfLoop.Name, 10))) = "CATEGORY@1" Then
  40.             Set oTemp = New cCategory
  41.             oTemp.Table = tdfLoop.Name
  42.             oTemp.Description = Mid$(tdfLoop.Name, 12, Len(tdfLoop.Name))
  43.             oTemp.Items = 0
  44.             oTemp.Score = 0
  45.             AvailCategory.Add oTemp
  46.         End If
  47.     Next tdfLoop
  48.     
  49.     Set RS = DB.OpenRecordset("select * from Title")
  50.     Title = RS![ExamTitle]
  51.     CurCategory = 1
  52.     Exit Sub
  53. ErrOpen:
  54.     MsgBox Err.Description, vbCritical Or vbOKOnly, "Error"
  55.     End
  56. End Sub
  57.  
  58. Public Sub Category(s As String)
  59.     On Error GoTo ErrCategory
  60.     
  61.     Static NextItem As Integer
  62.     Dim MaxRecord As Integer, temp As String
  63.     
  64.     temp = Replace(s, "Category@1", "Category@2")
  65.     temp = "select * from [" & temp & "];"
  66.     Set RS = DB.OpenRecordset(temp)
  67.     Direction = Space(5) & RS![Direction]
  68.     TotalItems = RS![Items]
  69.     MaxTime = RS![Time]
  70.     NextItem = NextItem + 1
  71.     AvailCategory(NextItem).Items = TotalItems
  72.     s = "select * from [" & s & "];"
  73.     Set RS = DB.OpenRecordset(s)
  74.     
  75.     If RS.RecordCount = 0 Then
  76.         MsgBox "No record found!", vbInformation Or vbOKOnly, _
  77.             "Category : " & AvailCategory(CurCategory).Description
  78.         End
  79.     Else
  80.         Dim ArrTempQ() As Integer   ' Array Questions
  81.         Dim ArrTempO() As Integer   ' Array Options
  82.         
  83.         Dim TotalRecords As Long
  84.         Dim oTemp As Object, i As Integer, j As Integer
  85.         
  86.         RS.MoveFirst
  87.         RS.MoveLast
  88.         TotalRecords = RS.AbsolutePosition + 1
  89.         
  90.         ReDim ArrTempQ(TotalRecords) As Integer
  91.         ReDim ArrTempO(4) As Integer
  92.         
  93.         Shuffle ArrTempQ()
  94.         frmMain.imcListAns.ComboItems.Clear
  95.         For i = LBound(ArrTempQ()) To UBound(ArrTempQ()) - 1
  96.             Set oTemp = New cData
  97.             oTemp.ItemID = ArrTempQ(i)
  98.             Shuffle ArrTempO()
  99.             For j = LBound(ArrTempO()) To UBound(ArrTempO()) - 1
  100.                 oTemp.OptionID.Add ArrTempO(j)
  101.                 ArrTempO(j) = 0
  102.             Next j
  103.             DataInfo.Add oTemp
  104.         Next i
  105.         
  106.         For i = LBound(ArrTempQ()) To TotalItems - 1
  107.             frmMain.imcListAns.ComboItems.Add , , Format$(i + 1, "000"), "imgLightOff"
  108.             frmMain.imcListAns.ComboItems(1).Selected = True
  109.             Set oTemp = New cAnswer
  110.             oTemp.Answer = 0
  111.             oTemp.Selected = 0
  112.             oTemp.Flag = False
  113.             MyAnswer.Add oTemp
  114.         Next i
  115.     End If
  116.     Exit Sub
  117. ErrCategory:
  118.     MsgBox Err.Description, vbCritical Or vbOKOnly, "Error"
  119. End Sub
  120.  
  121. Public Sub Question(ItemID As Integer)
  122.     RS.MoveLast
  123.     RS.MoveFirst
  124.     RS.FindFirst "[ItemID]=" & ItemID
  125.     
  126.     If RS.NoMatch Then
  127.         RS.MoveFirst
  128.         Question RS.AbsolutePosition
  129.     Else
  130.         With frmMain
  131.             Dim sTemp As String
  132.  
  133.             .lblQuestion.Caption = RS.Fields("Question").Value
  134.             sTemp = "[Option " & DataInfo(ItemID).OptionID(1) & "]"
  135.             .lblOption(0).Caption = RS.Fields(sTemp).Value
  136.             sTemp = "[Option " & DataInfo(ItemID).OptionID(2) & "]"
  137.             .lblOption(1).Caption = RS.Fields(sTemp).Value
  138.             sTemp = "[Option " & DataInfo(ItemID).OptionID(3) & "]"
  139.             .lblOption(2).Caption = RS.Fields(sTemp).Value
  140.             sTemp = "[Option " & DataInfo(ItemID).OptionID(4) & "]"
  141.             .lblOption(3).Caption = RS.Fields(sTemp).Value
  142.         End With
  143.     End If
  144. End Sub
  145.  
  146. Public Sub ComputeScore()
  147.     Dim n As Integer
  148.     
  149.     n = IIf(CurCategory = -1, AvailCategory.Count + 1, CurCategory)
  150.     
  151.     Dim i As Integer, pos As Integer, Score As Integer
  152.     
  153.     Score = 0
  154.     For i = 1 To MyAnswer.Count
  155.         ' if answer is equal to 1 then your answer is correct
  156.         If MyAnswer(i).Answer = 1 Then
  157.             Score = Score + 1
  158.         End If
  159.     Next i
  160.     
  161.     AvailCategory(n - 1).Score = Score
  162. End Sub
  163.  
  164. Public Sub NextCategory()
  165.     If CurCategory <= AvailCategory.Count Then
  166.         Category AvailCategory(CurCategory).Table
  167.     End If
  168.     
  169.     CurCategory = CurCategory + 1
  170.     If CurCategory > AvailCategory.Count Then
  171.         CurCategory = -1 ' no more category
  172.     End If
  173. End Sub
  174.  
  175. Public Sub CleanUp()
  176.     RS.Close
  177.     DB.Close
  178. End Sub
  179.