Difference between revisions of "DEFSNG"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>SMcNeill
(style guidelines)
Line 1: Line 1:
The '''DEFSNG''' statement defines all designated undefined variables AS [[SINGLE]] variables.  
+
The [[DEFSNG]] statement defines all variables with names starting with the specified letter (or letter range) AS [[SINGLE]] variables.
 +
 
 +
 
 +
==Legacy support==
 +
* '''DEF''' statements ([[DEFDBL]], [[DEFSNG]], [[DEFLNG]], [[DEFINT]], [[DEFSTR]]) were used when storage space was a concern in older computers, as their usage could save up typing. Instead of <span style="font-family: Courier New, monospace, Courier; background: #dddddd">'''DIM a AS SINGLE, a2 AS SINGLE, a3 AS SINGLE'''</span>, simply having <span style="font-family: Courier New, monospace, Courier; background: #dddddd">'''DEFSNG A'''</span> in the code before using variables starting with letter '''A''' would do the same job.
 +
* '''For clarity, it is recommended that you declare variables with meaningful names'''.
  
  
 
{{PageSyntax}}
 
{{PageSyntax}}
:: '''DEFSNG ''letter'''''[-''range'']
+
: [[DEFSNG]] {{Parameter|letter}}[-{{Parameter|range}}], {{Parameter|letter2}}[-{{Parameter|range2}}], [...]
 +
 
 +
 
 +
{{PageDescription}}
 +
* Undeclared variables with no type suffix are of type [[SINGLE]] by default.
 +
* {{Parameter|letter}} (or {{Parameter|range}}) can be from A-Z or any other range, like '''G-M'''.
 +
* You can also use commas for specific undefined variable first letters.
 +
* Variables [[DIM]]ensioned as another variable type or that use type suffixes are not affected by [[DEFSNG]].
 +
* [[DEFSNG]] 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).
 +
* '''Warning: QBasic keyword names cannot be used as numerical variable names with or without the type suffix.'''
 +
 
  
 +
==QBasic/QuickBASIC==
 +
* QBasic's IDE would add DEF statements before any [[SUB]] or [[FUNCTION]]. QB64 (like QBasic) 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 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.
  
* The variable first letters can be from A-Z or any other range.
 
* You can also use commas for specific untyped variable first letters.
 
* Variables [[DIM]]ensioned as another variable type or that use type suffixes are not defined otherwise.
 
* DEFSNG is normally the Qbasic default type assignment for undefined variables without type suffixes.
 
* DEFSNG 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).
 
* '''Qbasic's IDE may add 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!'''
 
* '''Warning: Qbasic keyword names cannot be used as numerical variable names with or without the type suffix!'''
 
  
 +
{{Parameter|Example:}}
 +
{{CodeStart}}
 +
{{Cl|DEFSNG}} A, F-H, M
  
''Example:'' DEFSNG A-D, S
+
'With the above, all variables with names starting with A, F, G, H and M
 +
'will be of type SINGLE, unless they have a type suffix
 +
'indicating another type or they are {{Cl|DIM|dimensioned}} differently
 +
{{CodeEnd}}
  
  
''See also:''
+
{{PageSeeAlso}}
* [[DEFINT]], [[DEFDBL]], [[DEFLNG]], [[DEFSTR]]
+
* [[DEFDBL]], [[DEFLNG]], [[DEFINT]], [[DEFSTR]]
 
* [[_DEFINE]]
 
* [[_DEFINE]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Revision as of 16:09, 18 September 2017

The DEFSNG statement defines all variables with names starting with the specified letter (or letter range) AS SINGLE variables.


Legacy support

  • DEF statements (DEFDBL, DEFSNG, DEFLNG, DEFINT, DEFSTR) were used when storage space was a concern in older computers, as their usage could save up typing. Instead of DIM a AS SINGLE, a2 AS SINGLE, a3 AS SINGLE, simply having DEFSNG A in the code before using variables starting with letter A would do the same job.
  • For clarity, it is recommended that you declare variables with meaningful names.


Syntax

DEFSNG letter[-range], letter2[-range2], [...]


Description

  • Undeclared variables with no type suffix are of type SINGLE by default.
  • letter (or range) can be from A-Z or any other range, like G-M.
  • You can also use commas for specific undefined variable first letters.
  • Variables DIMensioned as another variable type or that use type suffixes are not affected by DEFSNG.
  • DEFSNG 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).
  • Warning: QBasic keyword names cannot be used as numerical variable names with or without the type suffix.


QBasic/QuickBASIC

  • QBasic's IDE would add DEF statements before any SUB or FUNCTION. QB64 (like QBasic) will change all variable types in subsequent sub-procedures to that default variable type without giving a "Parameter Type Mismatch" warning or adding 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:

DEFSNG A, F-H, M 'With the above, all variables with names starting with A, F, G, H and M 'will be of type SINGLE, unless they have a type suffix 'indicating another type or they are dimensioned differently


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page