Hello everyone,

I am new to vb6 though i have done java and abap before. I gotta design an application which is a quiz with a countdown timer.

I have created the countdown timer stuff but how do i create questions and answers? say if i have 20 odd questions (MCQ's)? ain't i go for 20 odd forms? or only one form will do it? Please guide.

Thanks for writing back,

Regards,
Lucky

Recommended Answers

All 3 Replies

Okay, so questions with possible answers are coming from a database/text file/some source right? You only need one form with a label to display the question. Then if it is multiple choice, meaning that user would select one or more answers, then use a hidden check box for that question or if answer is only one possible right answer use a hidden option button.

Now with the hidden controls (optionbutton or checkbox) use the load method and the caption property to load new controls and display the answers, which means you will have to set the index of these hidden controls to zero (0).


Good Luck

Nice and accurate answer but that's what the problem is how do i display different mcq's on the same form and hide the previous one?

Thanks for writing back,

Regards,
Lucky

Okay, for demo purposes only, start a new project, add a label(Label1) and make it large enough to hold the question. Add an option button (Option1), set its index to zero(0), visable=false, Add a command button (command1).

Option Explicit
Dim QandA(1 to 20) As String
Dim HowManyAnswers As Integer
Dim CurrentQuestion As Integer

Private Sub Form_Load()
QandA(1) = "What Is Your Name?, Billy Martin, Sam Jones, Billy Bob Thorton, George Johns, Bob Smith"
QandA(2) = "What is your age?, 10, 15, 20"
'...
CurrentQuestion = 1
Call DisplayQuestion
End Sub

Private Sub DisplayQuestion()
Dim MyArray As String, ForLoopCounter As Integer
MyArray = Split(QandA(CurrentQuestion), ",")
Label1.Caption = MyArray(0)
If HowManyAnswers > 0 Then
  For ForLoopCounter = 1 To HowManyAnswers
    Unload Option1(ForLoopCounter)
  Next ForLoopCounter
End If
For ForLoopCounter = 1 To UBound(MyArray)
  Load Option1(ForLoopCounter)
  Option1(ForLoopCounter).Caption = MyArray(ForLoopCounter)
  Option1(ForLoopCounter).Top = Option1(ForLoopCounter - 1). Top + Option1(ForLoopCounter).Height + 30
  Option1(ForLoopCounter).Visible = True
Next ForLoopCounter
HowManyAnswers = UBound(MyArray)
End Sub

Private Sub Command1_Click()
CurrentQuestion = CurrentQuestion +1
Call DisplayQuestion
End Sub

Granted, this is just a demo of one way you could do it and also note that you would have to figure out how to keep track of which answer is correct and so on.


Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.