Difference between revisions of "DEFINE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>SMcNeill
m (-)
 
(33 intermediate revisions by 5 users not shown)
Line 1: Line 1:
_DEFINE lets you define a range of variables according to their first character as a datatype.
+
{{DISPLAYTITLE:_DEFINE}}
 +
[[_DEFINE]] defines a set of variable names according to their first character as a specified data type.
  
  
''Syntax:'' _DEFINE range or letter[, range2 or letter2[, range3 or letter3[, ...]]] [[AS]] datatype
+
{{PageSyntax}}
 +
:[[_DEFINE]] {{Parameter|letter}}[{{Parameter|-range}}, ...] [[AS]] [{{KW|_UNSIGNED}}] data[[type]]
  
  
* Range is in the form firstletter-endingletter (like A-C) or just define a single letter as a datatype.
+
{{Parameters}}
* Datatypes: [[INTEGER]], [[SINGLE]], [[DOUBLE]], [[LONG]], [[STRING]], [[_BIT]], [[_BYTE]], [[_INTEGER64]], [[_FLOAT]]   
+
* Variable start ''letter range'' is in the form firstletter-endingletter (like A-C) or just a single letter.
* Can also use the prefix [[_UNSIGNED]] for positive numerical values only.
+
* ''Data types'': [[INTEGER]], [[SINGLE]], [[DOUBLE]], [[LONG]], [[STRING]], [[_BIT]], [[_BYTE]], [[_INTEGER64]], [[_FLOAT]], [[_OFFSET]], [[_MEM]]   
 +
* Can also use the [[_UNSIGNED]] definition for positive whole [[INTEGER]] type numerical values.
  
  
 +
{{PageDescription}}
 +
* '''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 [[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.
  
  
''Example:'' _DEFINE A-C, F [[AS]] [[UNSIGNED]] [[INTEGER]]
+
{{PageExamples}}
 +
''Example:'' Defining variables that start with the letters A, B, C or F as unsigned integers, including the ''Add2'' [[FUNCTION]].
 +
{{CodeStart}} '' ''
 +
{{Cl|_DEFINE}} A-C, F {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|INTEGER}}
  
 +
{{Cl|PRINT}} Add2(-1.1, -2.2)
  
 +
{{Cl|END}}
  
''Explanation:'' Variables that start with the letters A, B, C or F will now be defined as a unsigned integers. Unsigned integers can only take positive values and ordinary integers can also take negative values.
+
{{Cl|FUNCTION}} Add2 (one, two)
 +
Add2 = one + two
 +
{{Cl|END FUNCTION}} '' ''
 +
{{CodeEnd}}
 +
{{OutputStart}}65533
 +
{{OutputEnd}}
 +
: ''Explanation:'' Unsigned integers can only return positive values while ordinary [[INTEGER|integers]] can also return negative values.
  
  
 +
{{PageSeeAlso}}
 +
* [[DEFSTR]], [[DEFLNG]], [[DEFINT]], [[DEFSNG]], [[DEFDBL]]
 +
* [[DIM]], [[REDIM]]
 +
* [[COMMON]], [[SHARED]]
 +
* [[_UNSIGNED]]
  
  
 
+
{{PageNavigation}}
''See also:'' [[DEFSTR]], [[DEFLNG]], [[DEFINT]], [[DEFSNG]], [[DEFDBL]], [[_UNSIGNED]], [[ABS]], [[SGN]]
 
 
 
''Referance:'' [[Mathematical Operations]]
 
 
 
 
 
 
 
 
 
==Navigation:==
 
 
 
[[Keyword_Reference_-_Alphabetical|Go to Keyword Reference - Alphabetical]]
 
 
 
[[Keyword Reference - By usage|Go to Keyword Reference - By usage]]
 

Latest revision as of 16:48, 5 September 2017

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


Syntax

_DEFINE letter[-range, ...] AS [_UNSIGNED] datatype


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:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page