Results 1 to 4 of 4

Thread: trying to think modular

  1. #1

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526

    Question

    I'm working on my first program in VB6, it's a program that will automatically pull up random questions from a text file full of multiple choice questions for the A+ quiz and test me on the material.

    So far, I've got a routine to load all the questions into arrays (thanks to the help of Andrew Empson) and I put this routine into the Form_Load. I then have the code that randomly picks and displays the question and multiple choice answers and when you hit the "submit answer" command button, the program can tell if check boxes you've selected for the multiple choice are right or wrong.

    And this is where I'm stuck. I'm going to turn the "submit answer" command button into a "next question" command button, but I don't know how to get back to the Form_Load from there. Obviously, I also don't want to reload the text file of questions into the arrays each time I hit the Form_Load. Where the heck is the GOTO statement in this modular world?


    mikeycorn


  2. #2
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77

    Smile

    I think that the best way to make this is to call a subroutine that ask the question.

    if your button name for "next question" is BtnNextQuestion, the code like this :

    sub Form_Load ()
    LoadingQuestion
    AskingQuestion
    end sub

    sub BtnNextQuestion_Click
    AskingQuestion
    end sub

    Sub LoadingQuestion()
    ' put here the code to load all the questions
    end sub

    Sub AskingQuestion()
    ' put here the code to ask the next question
    end sub
    KWell

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Hi MikeyCorn

    Kwell's pretty much summed it up, but it may be a little hard to understand if you're fresh from Qbasic.

    Here's what you need to do...

    Have a button called Command1 on your form along with the check boxes.

    Add this to the end of your Form_Load event

    Code:
    Call LoadQuestion
    Command1.Caption="Submit Answer"
    In the Command1_Click event you could do something like

    Code:
    If Command1.Caption="Submit Answer" Then
      If CheckAnswer(QuestionNumber)=True Then
        Msgbox("Correct!")
      Else
        Msgbox ("Incorrect.")
      End If
      Command1.Caption="Next Question"
    Else
      Call LoadQuestion
      Command1.Caption="Submit Answer"
    End If
    Then make a new Function called 'CheckAnswer' by typing this in at the beginning of your code (in General)

    Code:
    Function CheckAnswer(ByVal QuestionNumber) as Boolean
      'Put the code here to check if the answer to Question(QuestionNumber) is correct
      If TheAnswer=True Then  
        CheckAnswer=True
      Else
        CheckAnswer=False
      End If
    End Function
    Finally, make a new function called 'LoadQuestion' like this, also typing it in the General section of your form.

    Code:
    Sub LoadQuestion()
      'Load a new question and change the variable QuestionNumber to its index
      'Clear all of the check boxes and things
    End Sub
    Andrew Empson
    vb6(ent) SP4

  4. #4

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    EXCELLENT! Thank you both for taking the time to help . . . I've got alot to chew on now and it will probably be a while before I'm back. :-)

    When this project's done, it'll be fun sharing it with y'all.


    mikeycorn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width