Lesson 4 Homework
Copyright 2007 Shoptalk Systems
All rights reserved

Return to Table of Contents

We've covered the essential widgets that Run BASIC supports.  Now we will set you loose using some of these to create a web program.

Multiple Choice Test

Now let's cover some addition features of Run BASIC that can help you to tackle the homework project you'll be tasked with, which is a multiple choice test taker.

READ and DATA

Most implementations of BASIC have a feature for embedding information in a program and reading that information called READ and DATA.  To use this you list numbers or strings in a DATA statement and use the READ statement to get them one or more at a time.  Here is a simple example:

  for x = 1 to 3
    read a$
    print a$
  next x
  data "one", "two", "three"

Note: If you try to read more items than you have then Run BASIC will stop with a runtime exception.  Try this code:

  for x = 1 to 3
    read a$
    print a$
  next x
  data "one", "two"

You can read numeric values also, like so:

  for x = 1 to 3
    read a
    print "3 x "; a; " = "; 3*a
  next x
  data 4, 9, 10.5

You can have as many DATA statements as you need.  Take for example:

  for x = 1 to 3
    read a$
    print a$
  next x
  data "one"
  data "two"
  data "three"

You can read more than one item at a time with a READ statement, like so:

  read a$, b$, c$
  print a$
  print b$
  print c$
  data "one", "two", "three"

If you need to use the data over and over again you can use the RESTORE statement.  For example:

  for x = 1 to 3
    read a$
    print a$
  next x
  restore
  read first$, second$, third$
  print first$; " "; second$; " "; third$
  data "one", "two", "three"

Finally, it can be useful to have a way to read to the end of all your data without knowing how many items are in the list.  One way to do this is to put some data at the end that is special so you can test it to see if you're at the end.  Here is an example.

[loopBack]
  read item$
  if item$ = "EndOfData" then [stopLooping]
  print item$
  goto [loopBack]
[stopLooping]
  data "This", "is", "a", "test", "EndOfData"

Bring on the project!

Okay, now that you have a convenient way to have a set of data in your programs, use this technique along with some widgets to create a program to ask a series of multiple choice questions.  At the end of the test rate the performance of the test taker (ie. 7 of 9 correct).

Use the PRINT statement to ask each question.  Use the RADIOGROUP statement as a way for the user to choose an answer.  Use the LINK state to accept the choice once and move onto the next question.

Optionally, instead of storing the information in DATA statement use disk files.