Getting Input

 

Next Topic

 

The WIL Tutorial

§         Topic by Topic

§         The Tutorial Course

§         The Complete WIL Tutorial

 

Getting started

Using WIL

Reference

Notes

 

Now, let's look at ways of getting input from a user and making decisions based on that input. The most basic form of input is a simple Yes/No response, and, indeed, there is a WIL function called AskYesNo:

Syntax:

AskYesNo (title, question)

Parameters

(s) title title of the question box.

(s) question question to be put to the user.

Returns:

(i) @YES or @NO, depending on the button pressed.

 

You should be familiar with the standard syntax format by now; it shows us that AskYesNo has two required parameters. The Parameters section tells us that these parameters both take strings, and tells us what each of the parameters means.

You will notice that there is also a new section here, called Returns. This section shows you the possible values that may be returned by this function. All functions return values. We weren't concerned with the values returned by the Run and Display functions. But with AskYesNo, the returned value is very important, because we will need that information to decide how to proceed. We see that AskYesNo returns an integer value.

An integer is a whole (non-fractional) number, such as 0, 1, or 2 (the number 1.5 is not an integer, it is a floating point number). We also see that the integer value returned by AskYesNo is either @YES or @NO. @YES and @NO are predefined constants in WIL. All predefined constants begin with an @ symbol. Look up a list of all predefined constants.

Even though the words Yes and No are strings, it is important to remember that the predefined constants @YES and @NO are not string variables. (Actually, @YES is equal to 1, and @NO is equal to 0. Don't worry if this is confusing; you really don't need to remember or even understand it.)

 

image\gflag5_shg.gif
Tutor Example continued...

 

Now, let's modify our WIL program as follows:

 

AskYesNo("Really?", "Play Solitaire now?")

Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")

 

1. Edit tutor.wbt - Delete the Display statement.
Add
AskYesNo.
Delete semi-colon from the
Run.

2. Save the file.

3. Run the wbt by double-clicking on the filename..

 

image\golftee_shg.gif Next…

and run it. You should have gotten a nice dialog box which asked if you wanted to play Solitaire:

 

image\tutbut2_shg.gif

 

but no matter what you answered, it started Solitaire anyway. This is not very useful. We need a way to use the Yes/No response to determine further processing. First, we need to explore the concept and use of variables.