LISTING PROGRAM
Script Form1 ( frmLogin.frm)
Option Explicit
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click() 'set the global var to false 'to denote a failed login '.LoginSucceeded = False 'Me.Hide
End Sub
Private Sub cmdLogin_Click()
If Me.txtPlayerName.Text <> "" And Me.txtPassword.Text <> "" Then
'Register the Player Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT idPlayer,PlayerName FROM tbl_Pemain WHERE PlayerName = '" &
Me.txtPlayerName.Text & "' AND '" & Me.txtPassword.Text & "' "
If Not objRs.EOF Then 'Close Connection
Dim frm As New frmCategoryFlash frm.idPlayer = objRs!idPlayer objRs.Close
Call Module1.CloseConnection Unload Me
frm.Show Else
MsgBox "Login Gagal", vbExclamation End If
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection End If
End Sub
Private Sub cmdRegister_Click() Me.Hide
Dim frm As New frmRegister frm.Show
End Sub
Private Sub Form_Load()
Script Form2 ( frmRegister.frm )
Private Sub cmdRegister_Click()
If Me.txtPlayerName.Text <> "" And Me.txtPassword.Text <> "" Then
'Register the Player Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "insert into tbl_Pemain (PlayerName,[Password]) VALUES('" & Me.txtPlayerName.Text & "','" &
Me.txtPassword.Text & "')" objCon.Execute sSql
'Close Connection
Call Module1.CloseConnection
MsgBox "Selamat Anda Telah Terdaftar", vbInformation
Unload Me Exit Sub errHandler:
Module1.CloseConnection
Else
MsgBox ("Tolong Isi Data Sepenuhnya")
End If End Sub
Private Sub Form_Unload(Cancel As Integer) Dim frm As New frmLogin
frm.Show End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Script Form3 ( frmCategoryFlash.frm )
Public idPlayer As Integer
Private Sub CmdContinue_Click()
If Me.cboCategory.Text <> "" And Me.lstLevel.SelCount > 0 Then
Dim frm As New frmResponse
frm.Level = Me.lstLevel.Text frm.idPlayer = idPlayer
Unload Me frm.Show End If
End Sub
Private Sub Form_Load() LoadCategory
LoadList
PreviousAnswer (idPlayer) End Sub
Private Sub CheckAvailableQuestion() Dim sSql As String
Call Module1.OpenConnection
sSql="SELECTtbl_Pertanyaan.QuestionText,tbl_Pertanyaan.Di splayOrderNumber, tbl_Katagori.CategoryName,
tbl_Level.LevelName, tbl_Level.LevelColor, tbl_Jawaban.AnswerText, tbl_Level.LevelOrder,
tbl_Pertanyaan.idQuestion, tbl_Jawaban.Correct " & _"FROM tbl_Katagori INNER JOIN (tbl_Level INNER JOIN
(tbl_Pertanyaan INNER JOIN tbl_Jawaban ON
tbl_Pertanyaan.idQuestion = tbl_Jawaban.idQuestion) ON tbl_Level.idLevel = tbl_Pertanyaan.idLevel) ON
tbl_Katagori.idCategory = tbl_Pertanyaan.idCategory WHERE CategoryName = '" & Me.cboCategory.Text & "' AND
LevelName = '" & Me.lstLevel.Text & "' ORDER BY DisplayOrderNumber"
objRs.Open sSql, objCon, 1, 3 If Not objRs.EOF Then
'Close Connection objRs.Close
Call Module1.CloseConnection Me.cmdContinue.Enabled = True Else
Me.cmdContinue.Enabled = False
MsgBox "Tidak tersedia pertanyaan dalam kategori tersebut "
'Close Connection objRs.Close
Call Module1.CloseConnection
End If End Sub
Private Sub LoadList()
Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
objRs.Open sSql, objCon, 1, 3
Do While Not objRs.EOF
Me.lstLevel.AddItem (objRs!LevelName) objRs.MoveNext
Loop
'Close Connection objRs.Close
Call Module1.CloseConnection
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Private Sub LoadCategory()
Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT * FROM tbl_Katagori"
Do While Not objRs.EOF Me.cboCategory.AddItem (objRs!CategoryName)
objRs.MoveNext Loop
'Close Connection objRs.Close
Call Module1.CloseConnection
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Private Sub PreviousAnswer(idPlayer As Integer) 'Delete all previous Answer
Dim sSql As String
On Error GoTo errHandler 'Open Connection
sSql = "DELETE FROM tbl_Respons where idPlayer = " & idPlayer & " "
objCon.Execute sSql
'Close Connection
Call Module1.CloseConnection Exit Sub
errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub lstLevel_Click() CheckAvailableQuestion
End Sub
Script Form4 ( frmResponse.frm)
Public idPlayer As Integer Dim idLastQuestion As Integer
Dim ArrAnswers(1 To 4) As String Dim SelectedAnswer As Integer Dim Score As Double
Dim QuestionPoints As Double
Private Sub LoadHeader()
Me.lblScore.Caption = "Score: 0"
Me.lblCategory.Caption = "Category: " & Category Me.lblLevel.Caption = "Level: " & Level
End Sub
Private Sub CmdContinue_Click() If SelectedAnswer > 0 Then
'Register the Player Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "INSERT into tbl_Respons
objCon.Execute sSql
'Close Connection
Call Module1.CloseConnection Call UpdatePlayerLastAnswer Call LoadPlayerScore
Call LoadQuestionNextQuestion SelectedAnswer = 0
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
Else
MsgBox ("Please select your answer")
End If End Sub
Public Sub UpdatePlayerLastAnswer() 'Update Last Question
Dim sSql As String
Call Module1.OpenConnection
sSql = "UPDATE tbl_Pemain SET LastQuestion = " &
idLastQuestion & " WHERE idPlayer = " & idPlayer & " " objCon.Execute sSql
'Close Connection
Call Module1.CloseConnection
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Public Sub LoadPlayerScore()
'Load Player Score Dim sSql As String
Call Module1.OpenConnection
sSql = "SELECT tbl_Jawaban.idQuestion, tbl_Jawaban.AnswerText FROM tbl_Jawaban " & _
" WHERE idAnswer = " & SelectedAnswer & " AND Correct = true "
objRs.Open sSql, objCon, 1, 3 If Not objRs.EOF Then
Score = QuestionPoints + Score
Me.lblScore.Caption = "Score: " & Score MsgBox "Jawaban Anda Benar"
Else
MsgBox "Sorry,, Anda Salah" End If
'Close Connection
Module1.CloseConnection Exit Sub
errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
LoadHeader
LoadLastQuestion LoadQuestionInitial LoadAnswer
End Sub
Private Sub LoadLastQuestion() Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT * FROM tbl_Pemain WHERE idPlayer = " & Me.idPlayer & " "
objRs.Open sSql, objCon, 1, 3 If Not objRs.EOF Then
idLastQuestion = objRs!LastQuestion End If
'Close Connection objRs.Close
Call Module1.CloseConnection
errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection End Sub
Private Sub LoadQuestionNextQuestion()
Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT tbl_Pertanyaan.QuestionText, tbl_Pertanyaan.DisplayOrderNumber,
tbl_Katagori.CategoryName, tbl_Level.LevelName, tbl_Level.LevelColor, tbl_Jawaban.AnswerText, tbl_Level.LevelOrder, tbl_Pertanyaan.idQuestion, tbl_Jawaban.Correct " & _
"FROM tbl_Katagori INNER JOIN (tbl_Level INNER JOIN (tbl_Pertanyaan INNER JOIN
tbl_Jawaban ON tbl_Pertanyaan.idQuestion = tbl_Jawaban.idQuestion) ON tbl_Level.idLevel =
tbl_Pertanyaan.idLevel) ON tbl_Katagori.idCategory = tbl_Pertanyaan.idCategory WHERE CategoryName = '" & Category & "' AND LevelName = '" & Level & "' AND tbl_Pertanyaan.idQuestion > " & idLastQuestion & ""
If Not objRs.EOF Then
idLastQuestion = objRs!idQuestion Me.lblQuestion.Caption =
objRs!QuestionText
'Close Connection objRs.Close
Call Module1.CloseConnection Call LoadAnswer
Else
'Close Connection objRs.Close
Call Module1.CloseConnection
Unload Me
Dim frm As New frmGameOver frm.idPlayer = idPlayer frm.Score = Score
frm.Show
End If
errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Private Sub LoadQuestionInitial()
Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT tbl_Pertanyaan.QuestionText, tbl_Pertanyaan.DisplayOrderNumber,
tbl_Katagori.CategoryName, tbl_Level.LevelName, tbl_Level.LevelColor, tbl_Jawaban.AnswerText, tbl_Level.LevelOrder, tbl_Pertanyaan.idQuestion, tbl_Jawaban.Correct " & _
"FROM tbl_Katagori INNER JOIN (tbl_Level INNER JOIN (tbl_Pertanyaan INNER JOIN
tbl_Jawaban ON tbl_Pertanyaan.idQuestion = tbl_Jawaban.idQuestion) ON tbl_Level.idLevel =
tbl_Pertanyaan.idLevel) ON tbl_Katagori.idCategory = tbl_Pertanyaan.idCategory WHERE CategoryName = '" & Category & "' AND LevelName = '" & Level & "' ORDER BY DisplayOrderNumber"
If Not objRs.EOF Then
idLastQuestion = objRs!idQuestion Me.lblQuestion.Caption =
objRs!QuestionText
'Close Connection objRs.Close
Call Module1.CloseConnection
Else
'Close Connection objRs.Close
Call Module1.CloseConnection
End If
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
'Clear Selection (tbl_Level INNER JOIN (tbl_Pertanyaan INNER JOIN
tbl_Jawaban ON tbl_Pertanyaan.idQuestion = tbl_Jawaban.idQuestion) ON tbl_Level.idLevel =
tbl_Pertanyaan.idLevel) ON tbl_Katagori.idCategory = tbl_Pertanyaan.idCategory WHERE CategoryName = '" & Category & "' AND LevelName = '" & Level & "' AND tbl_Pertanyaan.idQuestion = " & idLastQuestion & ""
Dim AnswerNumber As Integer Do While Not objRs.EOF
Me.OptAns(AnswerNumber).Caption = objRs!AnswerText
AnswerNumber = AnswerNumber + 1
ArrAnswers(AnswerNumber) = objRs!idAnswer QuestionPoints = objRs!QuestionPoints objRs.MoveNext
Loop
'Close Connection objRs.Close
Call Module1.CloseConnection
Exit Sub errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection End If
End Sub
Private Sub OptAns4_Click()
Private Sub frameAnswer_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub OptAns_Click(Index As Integer) Select Case Index
Case 0
SelectedAnswer = ArrAnswers(1) OptAns(1).Value = False
OptAns(2).Value = False OptAns(3).Value = False Case 1
SelectedAnswer = ArrAnswers(2) OptAns(0).Value = False
OptAns(2).Value = False OptAns(3).Value = False Case 2
SelectedAnswer = ArrAnswers(3) OptAns(0).Value = False
OptAns(1).Value = False OptAns(3).Value = False Case 3
SelectedAnswer = ArrAnswers(4) OptAns(0).Value = False
OptAns(2).Value = False End Select
End Sub
Script Form5 ( frmGameOver.frm)
Public idPlayer As Integer Public Score As Double
Private Sub GameOver()
'Register the Player Dim sSql As String
On Error GoTo errHandler 'Open Connection
Call Module1.OpenConnection
sSql = "SELECT tbl_Pertanyaan.QuestionText, tbl_Jawaban.AnswerText, tbl_Jawaban.Correct,
tbl_Level.QuestionPoints " & _
"FROM ((tbl_Level INNER JOIN (tbl_Katagori INNER JOIN tbl_Pertanyaan ON
tbl_Katagori.idCategory = tbl_Pertanyaan.idCategory) ON tbl_Level.idLevel = tbl_Pertanyaan.idLevel) INNER JOIN tbl_Jawaban ON tbl_Pertanyaan.idQuestion =
(tbl_Pertanyaan.idQuestion = tbl_Respons.idQuestion) " & _
"Where (((tbl_Respons.idPlayer) = " & idPlayer & ")) " & _
"ORDER BY
tbl_Pertanyaan.DisplayOrderNumber"
objRs.Open sSql, objCon, 1, 3
Me.lstSummary.AddItem ("Final Score " & Score)
Do While Not objRs.EOF
Me.lstSummary.AddItem ("")
Me.lstSummary.AddItem ("Pertanyaan: " & objRs!QuestionText & " yang bernilai " &
objRs!QuestionPoints)
Me.lstSummary.AddItem ("Jawaban Anda: " & objRs!AnswerText)
If objRs!Correct = True Then
Me.lstSummary.AddItem ("Anda menjawab dengan benar")
End If
objRs.MoveNext Loop
Call Module1.CloseConnection Exit Sub
errHandler:
MsgBox Err.Description, vbCritical 'Close Connection
Module1.CloseConnection
End Sub
Private Sub Form_Load() Call GameOver
End Sub
Private Sub Form_Unload(Cancel As Integer) Unload Me
Dim frm As New frmCategoryFlash frm.idPlayer = idPlayer
frm.Show End Sub
Private Sub lstSummary_Click()
Script Modul Koneksi Database ( Module1.bas )
Public objCon As New ADODB.Connection Public objRs As New ADODB.Recordset Dim sPath As String
Public Sub OpenConnection()
sPath = App.Path & "\dbGame.mdb" objCon.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & sPath & ""
objCon.Open End Sub
Public Sub CloseConnection() objCon.Close
End Sub