DEFINE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_DEFINE}} _DEFINE defines a set of variable names according to their first character as a specified data type. {{PageSyntax}} :_DEFINE {{Parameter|letter}}[{{Parameter|-range}}, ...] AS [{{KW|_UNSIGNED}}] datatype {{Parameters}} * Variable start ''letter range'' is in the form firstletter-endingletter (like A-C) or just a single letter. * ''Data types'': INTEGER, SINGLE, DOUBLE, LONG, STRING, _BIT, _BYTE, _...")
 
m (QBasic capitalisation)
Tag: visualeditor
Line 16: Line 16:
* '''When a variable has not been defined or has no type suffix, the value defaults to a [[SINGLE]] precision floating point value.'''
* '''When a variable has not been defined or has no type suffix, the value defaults to a [[SINGLE]] precision floating point value.'''
* _DEFINE sets the [[type]] of all variable names with the starting letter(s) or letter ranges  when encountered in the progression of the program (even in conditional statement blocks not executed and subsequent [[SUB]] procedures).  
* _DEFINE sets the [[type]] of all variable names with the starting letter(s) or letter ranges  when encountered in the progression of the program (even in conditional statement blocks not executed and subsequent [[SUB]] procedures).  
* '''NOTE: Many Qbasic keyword variable names CAN be used with a [[STRING]] suffix ($)! You cannot use them without the suffix, use a numerical suffix or use [[DIM]], [[REDIM]], [[_DEFINE]], [[BYVAL]] or [[TYPE]] variable [[AS]] statements.'''
* '''NOTE: Many QBasic keyword variable names CAN be used with a [[STRING]] suffix ($)! You cannot use them without the suffix, use a numerical suffix or use [[DIM]], [[REDIM]], [[_DEFINE]], [[BYVAL]] or [[TYPE]] variable [[AS]] statements.'''
* '''Qbasic's IDE''' added DEF statements before any [[SUB]] or [[FUNCTION]]. '''QB64''' (like QB) will change all variable types in subsequent sub-procedures to that default variable type without giving a [[ERROR Codes|"Parameter Type Mismatch"]] warning or adding the proper DEF statement to subsequent procedures. If you do not want that to occur, either remove that DEF statement or add the proper DEF type statements to subsequent procedures.
* '''QBasic's IDE''' added DEF statements before any [[SUB]] or [[FUNCTION]]. '''QB64''' (like QB) will change all variable types in subsequent sub-procedures to that default variable type without giving a [[ERROR Codes|"Parameter Type Mismatch"]] warning or adding the proper DEF statement to subsequent procedures. If you do not want that to occur, either remove that DEF statement or add the proper DEF type statements to subsequent procedures.
* May also affect [[$INCLUDE]] procedures.
* May also affect [[$INCLUDE]] procedures.



Revision as of 09:54, 29 April 2022

_DEFINE defines a set of variable names according to their first character as a specified data type.


Syntax

_DEFINE letter[-range, ...] AS [[[:Template:KW]]] datatype


Template:Parameters


Description

  • When a variable has not been defined or has no type suffix, the value defaults to a SINGLE precision floating point value.
  • _DEFINE sets the type of all variable names with the starting letter(s) or letter ranges when encountered in the progression of the program (even in conditional statement blocks not executed and subsequent SUB procedures).
  • NOTE: Many QBasic keyword variable names CAN be used with a STRING suffix ($)! You cannot use them without the suffix, use a numerical suffix or use DIM, REDIM, _DEFINE, BYVAL or TYPE variable AS statements.
  • QBasic's IDE added DEF statements before any SUB or FUNCTION. QB64 (like QB) will change all variable types in subsequent sub-procedures to that default variable type without giving a "Parameter Type Mismatch" warning or adding the proper DEF statement to subsequent procedures. If you do not want that to occur, either remove that DEF statement or add the proper DEF type statements to subsequent procedures.
  • May also affect $INCLUDE procedures.


Examples

Example: Defining variables that start with the letters A, B, C or F as unsigned integers, including the Add2 FUNCTION.

  
_DEFINE A-C, F AS _UNSIGNED INTEGER

PRINT Add2(-1.1, -2.2)

END

FUNCTION Add2 (one, two)
Add2 = one + two
END FUNCTION  
65533
Explanation: Unsigned integers can only return positive values while ordinary integers can also return negative values.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link