473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Code using check boxes to select more than answer

Hi folks!

Can anyone please help me with this?

I am developing a Quiz program but I am stuck with "multiple answers".
Basically I need some sort of code that would select multiple answers
using check boxes.

For example, a question such as

Which two of the following are relational databases?
A. Oracle
B. UML
C. ODBC
D. Ingres

It should track as A and D.

Can anyone please show a code that would track them two answers?

Also, how does the question bank (in the form of a database) looks
for; i.e. How do you store multiple answers in a database so VB tracks
those answers?

Thanks for your help
Jul 17 '05 #1
3 5170
> Can anyone please show a code that would track them two answers?

no one will show you the complete code, as people donot have enough
time for writing the whole code, be specific yaar.
Jul 17 '05 #2
you can see this group for help

http://groups.google.com/groups?dq=&...8f4fce6e006648
Jul 17 '05 #3
"Mohammed Mazid" <ka******@hotmail.com> wrote in message
Hi folks!

Can anyone please help me with this?

I am developing a Quiz program but I am stuck with "multiple answers".
Basically I need some sort of code that would select multiple answers
using check boxes.


See if you can learn from the following code. Add a Checkbox to a new
form and set its Index property to 0, then add a Command button to the
form and paste in the code below. I've left Debug statements in, so
watch the debug window for clues.

HTH
LFS

Option Explicit

Private Type MyRecordType
A As String
B As String
C As String
D As String
E As String
F As String
Q As String
Z As Long
End Type

Private Type MyQuestionType
A As String
B As String
C As String
D As String
Q As String
Z As Long
End Type

Dim Records(0 To 2) As MyRecordType
Dim Question As MyQuestionType
Dim QCount As Long

Private Sub Form_Load()
Dim i

Randomize
Show

' These are your DB records
With Records(0)
.Q = "Which of these are colors"
.A = "Red" ' 1
.B = "White" ' 2
.C = "Blue" ' 4
.D = "Car" ' 8
.E = "House" ' 16
.F = "Plane" ' 32
.z = 7 ' 1 + 2 + 4 (Right answers)
End With

With Records(1)
.Q = "Which of these are numbers"
.A = "Two"
.B = "One"
.C = "Tree"
.D = "Red"
.E = "Plant"
.F = "Man"
.z = 3
End With

With Records(2)
.Q = "Which of these are mostly water"
.A = "Lake"
.B = "River"
.C = "Car"
.D = "Key"
.E = "House"
.F = "Fan"
.z = 3
End With

Command1.Move 120, 1800, 1200, 480

' Make more checkboxes
For i = 0 To 3
If i Then
Load Check1(i)
Check1(i).Visible = True
End If
Check1(i).Move 220, i * 300 + 400, 4000, 300
Next i

GenerateQ
ShowQ

End Sub

Private Sub Command1_Click()
Dim z, i

Select Case Command1.Caption
Case "Guess"
' Tally answer
For i = 0 To 3
If Check1(i).Value = vbChecked Then
z = z Or (2 ^ i)
End If
Next

If z = Question.z Then
Caption = "Correct!"
Else
Caption = "Wrong"
End If
Command1.Caption = "Next"

Case Else ' "Next"
GenerateQ
ShowQ
End Select

End Sub
Private Sub ShowQ()
With Question
Cls
PSet (90, 90)
Print .Q

Check1(0).Caption = .A
Check1(0).Value = vbUnchecked
Check1(1).Caption = .B
Check1(1).Value = vbUnchecked
Check1(2).Caption = .C
Check1(2).Value = vbUnchecked
Check1(3).Caption = .D
Check1(3).Value = vbUnchecked
End With

Command1.Caption = "Guess"
Caption = "Answer question"

End Sub
Private Sub GenerateQ()
Dim R As MyRecordType
Dim quiz(0 To 3) As String
Dim Txt As String
Dim Cnt As Long, z As Long, used As Long
Dim Que As Long
Dim blank As MyQuestionType

' Pull next question from records
QCount = QCount + 1
If QCount > 2 Then QCount = 0
R = Records(QCount)

' Init Question
Question = blank
Question.Q = R.Q
Debug.Print vbCrLf & "Correct ansers:"

' Pick random # of right answers
Cnt = Int(Rnd * 3) + 1

Do While Cnt

' Pick random answer
z = 2 ^ (Int(Rnd * 6))
' Test if a 'correct' answer AND not used
If (R.z And z) > 0 And (used And z) = 0 Then

' Saved picked
used = used Or z

' Pick random unused spot
Do
Que = Int(Rnd * 4)
Loop Until Len(quiz(Que)) = 0

' Move to Quiz
Select Case z
Case 1
quiz(Que) = R.A
Case 2
quiz(Que) = R.B
Case 4
quiz(Que) = R.C
Case 8
quiz(Que) = R.D
Case 16
quiz(Que) = R.E
Case 32
quiz(Que) = R.F
End Select

Debug.Print Que, quiz(Que)
' Decrement answer counter
Cnt = Cnt - 1
' Test if all 'correct' answers picked
If used = R.z Then Cnt = 0
End If

Loop

'Remove all other correct answers
used = used Or R.z

Debug.Print Question.Q

' fill with guesses
Cnt = 0
For Que = 0 To 3

If Len(quiz(Que)) = 0 Then
' Pick guess (wrong answer)
Do
z = 2 ^ (Int(Rnd * 6))
Loop While (used And z) > 0

' Mark as used
used = used Or z

' Move to Quiz
Select Case z
Case 1
quiz(Que) = R.A
Case 2
quiz(Que) = R.B
Case 4
quiz(Que) = R.C
Case 8
quiz(Que) = R.D
Case 16
quiz(Que) = R.E
Case 32
quiz(Que) = R.F
End Select

Else
' Tally right answers
Cnt = Cnt Or (2 ^ Que)
End If

Debug.Print Que, quiz(Que), 2 ^ Que
Next
Debug.Print "Right value >", , Cnt
'Move to Question
With Question
.A = quiz(0)
.B = quiz(1)
.C = quiz(2)
.D = quiz(3)
.z = Cnt
End With

End Sub


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
2
by: Ben | last post by:
My current project requires me to create part of a form that is created on the fly. The project consists a list of entries to an event. The name and address and such is easy. The design is detup so...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
3
by: somethings.amiss | last post by:
I searched google groups for an answer but found none that I could completely understand. I have a table. It contains fields such as 'client,date,hours,project,employee.' I have a form that...
2
by: simon.wilkinson | last post by:
Hi, I am trying to update all Select boxes on a page dynamically using javascript, I simple want to change the selected item in each select box when a tick box is pressed on the page. Each...
11
by: Patrick | last post by:
Trying this question again in a different way and expanding it to another newsgroup. Looking for how I would do this. For an html form; Say I have three check boxes A, B, and C . When I click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.