Q(uick)BASIC Statement: DEFCUR
Quick View
DEFCUR
A BASIC declaration that sets the default data type for variables, DEF FN functions, and FUNCTION procedures
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- DEFINT letterrange [,letterrange]…
- DEFLNG letterrange [,letterrange]…
- DEFSNG letterrange [,letterrange]…
- DEFDBL letterrange [,letterrange]…
- DEFCUR letterrange [,letterrange]…
- DEFSTR letterrange [,letterrange]…
Description/Parameter(s)
- The argument letterrange has the syntax:
letter1[-letter2] | letter1 and letter2 are any of the uppercase or lowercase letters of the alphabet. |
Usage Notes
- DEFtype sets the default data type. For example, in the following program fragment, Message is a string variable:
- DEFSTR A-Q
- ⋮
- Message = "Out of stack space."
- The case of the letters in letterrange is not significant. These three statements are equivalent:
- DEFINT I-N
- DEFINT I-N
- DEFINT I-N
- A type-declaration character (%, &, !, #, @ or $) always takes precedence over a DEFtype statement. DEFtype statements do not affect record elements.
Important
- I%, I&, I!, I#, I@, and I$, all are distinct variables, and each may hold a different value.
Differences from BASICA
- BASICA handles default data types differently. BASICA scans each statement before executing it. If the statement contains a variable without an explicit type (indicated by %, &, !, #, @ or $), the interpreter uses the current default type. In contrast, the current version of BASIC scans the text once only and after a variable appears in a program line, its type cannot be changed.
Example
This example finds the cube root of an input value. It uses the ABS function to test if the current guess is accurate. The DEFDBL statement is used to establish the default for the variables.
DEFDBL A-Z
Precision = .0000001#
CLS 'Clear the screen.
INPUT "Enter a value: ", Value 'Prompt for input.
'Make the first two guesses.
X1 = 0#: X2 = Value
'Loop until the difference between guesses is
'less than the required precision.
DO UNTIL ABS(X1 - X2) < Precision
X = (X1 + X2) / 2#
' Adjust the guesses.
IF X * X * X - Value < 0# THEN
X1 = X
ELSE
X2 = X
END IF
LOOP
PRINT "The cube root is "; X
Sample Output:
Enter a value: 27 The cube root is 2.99999997206032