'===========================================================================
' Subject: QUIZ GENERATOR                     Date: 07-30-93 (18:57)       
'  Author: Adam Davila                        Code: QB, QBasic, PDS        
'  Origin: QBTIPS_O.DOC                     Packet: MISC.ABC
'===========================================================================
'>        I'm endeavoring to write a 
'>program that will quiz me on 
'>    nursing concepts and would welcome 
'>any suggestions. I want

'Here's a little something I threw together.  Keep in mind, I just
'litteraly threw it together.  It has not been optimized, so don't
'anybody reading this start throwing "That's not efficient"'s at me.

'Feel free to use this in your program.  Just leave my name somewhere.
'And let me know when you finish your program.  It looks like something I
'could use.

'This is really two programs.  One called MAKEQUES.BAS, which makes the
'questions and answers file.  The second one, LABDOC.BAS, is the one that
'picks the questions and answers.  I have not made a routine to keep
'questions from popping up more than once.  I thought I'd leave that up
'to you as practice. :> <G>

'Here is MAKEQUES.BAS

' Wherever you see a **_**  Unwrap what is after that.
DECLARE SUB WriteData (Question$, Answer1$, Answer2$, Answer3$,CorrectA$, CorrectText$)
OPEN "Question.dat" FOR APPEND AS #1
Start:
CLS
PRINT "Please enter the Question to be asked: (Enter to end) "
LINE INPUT "", Question$
IF Question$ = "" THEN
   CLOSE
   END
END IF
PRINT "Please enter 3 wrong answers to this question (Use CR to start new line):"
LINE INPUT "", Answer1$
LINE INPUT "", Answer2$
LINE INPUT "", Answer3$
PRINT "Please enter the correct Answer:"
LINE INPUT "", CorrectA$
PRINT "Enter the text you wish to display when answer is correct:"
INPUT "", CorrectText$
CALL WriteData(Question$, Answer1$, Answer2$, Answer3$, CorrectA$ , CorrectText$)
GOTO Start

SUB WriteData (Question$, Answer1$, Answer2$, Answer3$, CorrectA$ , CorrectText$) STATIC
PRINT #1, CHR$(7) ' Delimiter: Tells you where each record starts
PRINT #1, Question$   ' Write the Data to the file #1
PRINT #1, Answer1$    ' ""                         ""
PRINT #1, Answer2$    ' ""                         ""
PRINT #1, Answer3$    ' ""                         ""
PRINT #1, CorrectA$   ' ""                         ""
PRINT #1, CorrectText$' ""                         ""
END SUB

'  Page Break for ABCREAD, Start of next code.

'This is LABDOC.BAS.  This program is the quiz generator.

DECLARE SUB WriteResponse (Locater!, Choice!, Question$)
' Lab Doctor
' By Adam Davila
RANDOMIZE TIMER ' Initialized random # generator
Start:
CLS
GOSUB GetRecords
Locater = INT(RND * 4) + 4 ' Generates the random location of answer
' The above had 4 added to it so that there would be 4 emtpy lines
' after the question
PRINT Question$
IF Locater = 4 THEN   ' The next 4 IF-THENs place the wrong answers
    LOCATE 5
    PRINT Locater - 2; Answer1$
    PRINT Locater - 1; Answer2$
    PRINT Locater - 0; Answer3$
END IF
IF Locater = 5 THEN
    LOCATE 4
    PRINT Locater - 4; Answer1$
    LOCATE 6
    PRINT Locater - 2; Answer2$
    LOCATE 7
    PRINT Locater - 1; Answer3$
END IF
IF Locater = 6 THEN
     LOCATE 4
     PRINT Locater - 5; Answer1$
     LOCATE 5
     PRINT Locater - 4; Answer2$
     LOCATE 7
     PRINT Locater - 2; Answer3$
END IF
IF Locater = 7 THEN
     LOCATE 4
     PRINT Locater - 6; Answer1$
     LOCATE 5
     PRINT Locater - 5; Answer2$
     LOCATE 6
     PRINT Locater - 4; Answer3$
END IF
LOCATE Locater               'Locate the Answer
PRINT Locater - 3; CorrectA$ 'Print the Answer
LOCATE 10, , 1
PRINT ">> ";
Choice$ = ""
DO WHILE Choice$ = ""
   Choice$ = INKEY$
LOOP
PRINT Choice$
LOCATE , , 0' ** Turns Cursor off **
Choice = VAL(Choice$) ' Change the string to an integer
IF Choice = Locater - 3 THEN 'If the answer is right, then print
    LOCATE 12, 1             ' the correct answer text.
    PRINT CorrectText$
END IF
IF Choice <> Locater - 3 THEN  ' If anything other than the right
    LOCATE 12, 1               ' answer if entered, beep and print
    BEEP                       ' the below statement
    PRINT "I'm sorry.  That's not correct"
END IF
CALL WriteResponse(Locater, Choice, Question$)
LOCATE 20, 1, 1
PRINT "Another Question >> ";
Choice$ = ""
DO WHILE Choice$ = ""
  Choice$ = INKEY$
LOOP
IF UCASE$(Choice$) = "Y" GOTO Start
LOCATE , , 0
PRINT Choice$
END

GetRecords:
OPEN "question.dat" FOR INPUT AS #1
DO WHILE NOT EOF(1)
   LINE INPUT #1, Delimiter$
   IF Delimiter$ = CHR$(7) THEN Found = Found + 1
LOOP


GenerateRND:
Selected = INT(RND * (Found + 1))
IF Selected = 0 THEN GOTO GenerateRND

SEEK #1, 1 ' Start reading at the beggining of the file
DO WHILE NOT EOF(1)
    LINE INPUT #1, Delimiter$
    IF Delimiter$ = CHR$(7) THEN FoundIt = FoundIt + 1
    IF FoundIt = Selected THEN
       LINE INPUT #1, Question$
       LINE INPUT #1, Answer1$
       LINE INPUT #1, Answer2$
       LINE INPUT #1, Answer3$
       LINE INPUT #1, CorrectA$
       LINE INPUT #1, CorrectText$
    END IF
LOOP
CLOSE
RETURN

SUB WriteResponse (Locater, Choice, Question$)
OPEN "response.dat" FOR APPEND AS #1
PRINT #1, CHR$(7)'Delimiter
PRINT #1, Question$
PRINT #1, "Answer was #"; Locater - 3
PRINT #1, "Response was #"; Choice
CLOSE
END SUB
