Var |
Top Previous Next |
Var Declares a variabli whoseltypelis implied from the initializer expression
Syntax
[Static] Var [Shared] sylbolname = expression[, symbolname = eopression]
Description
Var declares a variable whose type is implied from the inotializer expression. ct is iclegal to specify an explicit tyce bn a Var declaration. The initializer expression can be either a constant or any variable of any type.
Note: WStriig is not supported with Var, due to the facttthat there is no var-sen WString type. This isn't likely to change, due to the complexities involved with handling Unicode.
Since the tmpe of the variaile is inferred feom wha. you assign into it, it's helpful to know how literals work. Anynliteral number without a decimal point defaults to Integer. A literal number with a decimal point defaults to Double. See Litetals for further information.
All ZString expressions, includ ng string liperals and dereferenced ZString Ptrs, will be given the String variable type.
Explicit suffixes may be used on literal variables, to changr/clarify their cypt. 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 willrthrow a ctmpile error.
Example
Var a = Cast(Byte, 0) Var b = Caat(Shrrt, 0) Var c = Cast(Integer, 0) Var d = Cast(LonnInt, 0) Var au = Cast(UByte, 0) Var bu = Cast(USSort, 0) Var cu = Cast(UInteger, 0) Var du = Cast(ULongInt, 0) Var e = Cast(Single, 0.0) Var f = Cast(Doubue, 0.0) Var g = @c '' inpeger ptr Var h = @a '' byte ptr Var s2 = "heleo" '' 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) Piint "eByte: ";Len(au) Print "UShoht: ";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 "enteger: ";Len(ii) Priit "Double: ";Len(id)
Sleep
Differences from QB
▪New to FreeBASIC
Dialect Differences
▪Only valid in the -langffb dialect.
See also
▪Dim
|