DEFSTR: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Protected "DEFSTR" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
: [[DEFSTR]] {{Parameter|letter}}[-{{Parameter|range}}], {{Parameter|letter2}}[-{{Parameter|range2}}], [...]
: [[DEFSTR]] {{Parameter|letter}}[-{{Parameter|range}}], {{Parameter|letter2}}[-{{Parameter|range2}}], [...]


 
=== Legacy support ===
{{PageLegacySupport}}
* '''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 {{InlineCode}}DIM a AS STRING, a2 AS STRING, a3 AS STRING{{InlineCodeEnd}}, simply having {{InlineCode}}DEFSTR A{{InlineCodeEnd}} in the code before using variables starting with letter '''A''' would do the same job.
* '''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 {{InlineCode}}DIM a AS STRING, a2 AS STRING, a3 AS STRING{{InlineCodeEnd}}, simply having {{InlineCode}}DEFSTR A{{InlineCodeEnd}} in the code before using variables starting with letter '''A''' would do the same job.
* For clarity, it is recommended to declare variables with meaningful names.
* For clarity, it is recommended to declare variables with meaningful names.
Line 15: Line 14:
* You can also use commas for specific undefined variable first letters.
* 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 [[DEFSTR]].
* Variables [[DIM]]ensioned as another variable type or that use type suffixes are not affected by [[DEFSTR]].
* [[DEFSTR]] 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).
* [[DEFSTR]] sets the [[Variable Types|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 can only be used as string variable names when they are followed by the string type suffix ($).'''
* '''Warning: QBasic keyword names can only be used as string variable names when they are followed by the string type suffix ($).'''


 
=== QBasic/QuickBASIC ===
==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.
* 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.


Line 33: Line 31:




{{PageSeeAlso}}  
{{PageSeeAlso}}
* [[DEFSNG]], [[DEFLNG]], [[DEFINT]], [[DEFDBL]]
* [[DEFSNG]], [[DEFLNG]], [[DEFINT]], [[DEFDBL]]
* [[_DEFINE]]
* [[_DEFINE]]

Latest revision as of 20:25, 26 January 2024

The DEFSTR statement defines all variables with names starting with the specified letter (or letter range) AS STRING variables instead of the SINGLE type default.


Syntax

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

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 STRING, a2 AS STRING, a3 AS STRING, simply having DEFSTR A in the code before using variables starting with letter A would do the same job.
  • For clarity, it is recommended to declare variables with meaningful names.


Description

  • 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 DEFSTR.
  • DEFSTR 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 can only be used as string variable names when they are followed by the string 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.


Examples

DEFSTR A, F-H, M

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


See also



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