Repository navigation
Var
Home › Variable Declarations › Var
Declares a variable whose type is implied from the initializer expression
[Static] Var [Shared] symbolname = expression[, symbolname = expression]Var declares a variable whose type is implied from the initializer expression. It is illegal to specify an explicit type in a Var declaration. The initializer expression can be either a constant or any variable of any type.
Note: WString is not supported with Var, due to the fact that there is no var-len WString type. This isn't likely to change, due to the complexities involved with handling Unicode.
Since the type of the variable is inferred from what you assign into it, it's helpful to know how literals work. Any literal number without a decimal point defaults to Integer. A literal number with a decimal point defaults to Double. See Literals for further information.
All ZString expressions, including string literals and dereferenced ZString Ptrs, will be given the String variable type.
Explicit suffixes may be used on literal variables, to change/clarify their type. See Literals and Variable Types for some more information about suffixes that can be used on literals.
Note: Suffixes must appear on the initializer, not on the variable. Trying to use Var with a variable that has a suffix will throw a compile error.
- New to FreeBASIC
- Only valid in the -lang fb dialect.
Var a = Cast(Byte, 0)
Var b = Cast(Short, 0)
Var c = Cast(Integer, 0)
Var d = Cast(LongInt, 0)
Var au = Cast(UByte, 0)
Var bu = Cast(UShort, 0)
Var cu = Cast(UInteger, 0)
Var du = Cast(ULongInt, 0)
Var e = Cast(Single, 0.0)
Var f = Cast(Double, 0.0)
Var g = @c '' integer ptr
Var h = @a '' byte ptr
Var s2 = "hello" '' var-len string
Var ii = 6728 '' implicit integer
Var id = 6728.0 '' implicit double
Print "Byte: ";Len(a)
Print "Short: ";Len(b)
Print "Integer: ";Len(c)
Print "Longint: ";Len(d)
Print "UByte: ";Len(au)
Print "UShort: ";Len(bu)
Print "UInteger: ";Len(cu)
Print "ULongint: ";Len(du)
Print "Single: ";Len(e)
Print "Double: ";Len(f)
Print "Integer Pointer: ";Len(g)
Print "Byte Pointer: ";Len(h)
Print "Variable String: ";Len(s2)
Print
Print "Integer: ";Len(ii)
Print "Double: ";Len(id)
SleepCategory: Variable Declarations
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing