RATS 11
RATS 11

QUERY( options )   list of variables

 

QUERY prompts a user to input values for variables. It is handy for writing general RATS applications that change slightly from one run to the next. QUERY displays a dialog box with the prompt and a text box for the reply. DBOX is a more powerful, but more complicated, instruction for getting user input, as it allows you to create custom dialog boxes.

Parameters

list of variables

This can be any collection of INTEGER, REAL, COMPLEX, STRING or LABEL variables or array elements. You may not use an array itself. You must introduce any variable prior to using it in a QUERY instruction, with DECLARE for instance.

Options

PROMPT="string" or STRING variable ["Enter Information"]

This displays a prompt on the screen as a message to the user. It can either be a string enclosed in quotes (") or a STRING variable.

 

STATUS=INTEGER variable set to 0 or 1 status [unused].

If you use the option STATUS, QUERY does not give you an error if there is not enough data to fill all the variables. Instead, it sets your STATUS variable to 0. If the QUERY is successful, it sets the status variable to 1.

 

VERIFY=expression returning non-zero value if valid input [none]

ERRORMESSAGE=message to display if VERIFY result is zero [invalid]

You can use VERIFY to check whether the user has provided a valid response. RATs will check that the information is in the correct form (for instance, it will catch the user inputting a string when a number is needed), but you need to use the VERIFY option if you want to test that a value is within the proper range. By using this, you can prevent the user from ok’ing an illegal value.

 

The default error message is “Illegal Value”. If you use VERIFY, it’s a good idea to include an error message and to make it as informative as possible.

 

INITIALIZE/[NOINITIALIZE]

If INITIALIZE, the text box is filled with the current value of the variable. This only works if there is just one variable. By default, the input field is blank.

User Responses to a QUERY

In response to QUERY, the user can type either constants or expressions. For example, a user could type in a date field such as 1947:1. If QUERY requests more than one variable, the values can be separated by commas or blanks.

 

If you request a STRING, QUERY accepts the whole line as the value.

Examples

These show two uses of QUERY in to set up the early part of a RATS session.

 

declare integer ninput

query(prompt="How many observations")  ninput

allocate ninput

 

declare integer year  period  nfore

query(prompt="Final Year and Period of Data?")  year  period

query(prompt="How Many Forecast Steps?")  nfore

allocate year:period+nfore


 

This is a bit fancier example. It

 

1.Initializes the input to 1

2.Checks that the input number is in the range 1 to %NREG. If not, it issues the message showing the valid range.

 

declare integer nrestr

compute nrestr=1

compute errmsg="Value must be >=1 and <="+%nreg

query(prompt="How many restrictions?",initialize,$

   verify=(nrestr>=1.and.nrestr<=%nreg),errmsg=errmsg) nrestr

 


Copyright © 2025 Thomas A. Doan