Variable

From QB64 Wiki
Revision as of 07:08, 11 November 2010 by imported>Cyperium (Created page with 'A '''variable''' is a "container" that can store a value, either numerical or string and it can later be changed by the program (as opposed to constants). All numeric…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A variable is a "container" that can store a value, either numerical or string and it can later be changed by the program (as opposed to constants).


All numerical variables defaults to 0 and all string variables defaults to "".


Variables are used to keep track of information that is attained through the program flow, either by user input, calculations or by other ways of communicaton (as with I/O, memory, TCP/IP or files).


Variables in QB64 can be any name except the names of keywords and may not contain spaces or non-alphabetical/non-numerical characters (except "." and "_"), if numerical characters are used in the name at least one alphabetical character has to be used before the numerical character, the same applies to ".", in case a "." is used in the name at least one character has to follow the "." (numerical or alphabetical).


Assigning values to variables can be done by the = assignment symbol (variable1.number = 500, for example).


Arrays is a special usage of variables that can hold many values in one variable by specifying a index enclosed in paranteses.



Examples

Example of different usages of variables:

max = 1000 DIM d(max) FOR c = 1 TO max d(c) = c + d(c - 1) NEXT PRINT "Show the result of the addition from 1 to n (1+2+3...+n)" PRINT "n = (0-" + LTRIM$(STR$(max)) + "): "; INPUT "", n IF n <= max AND n >= 0 THEN PRINT d(n) ELSE PRINT "Invalid value (only 0 to" + STR$(max) + " is permitted)."

Show the result of the addition from 1 to n (1+2+3...+n) n = (1-1000): 10 55



See also



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