Navigation:  thinBasic Modules > Core > General >

SizeOf

Previous pageReturn to chapter overviewNext page

 

Description

 

Returns the size of a variable or a variable type.

 

Syntax

 

n = SizeOf (Variable)

 

Returns

 

Number

 

Parameters

 

Name

Type

Optional

Meaning

Variable

Any

No

Any variable name or variable type

 

Remarks

 

Variable can be a single variable name or an UDT or any UDT element in any nested UDT structures.

Variable types can be any of the supported thinBasic variable types.

Variable can also be an array or an array element.

 

Restrictions

 

Expressions will generate a runtime error. It can be possible to understand expression size at runtime but it has be decided to leave this limitation.

 

See also

 

Examples

 

First example

USES "console"

Alias console_writeline As WL

 

Dim sFormat As String = "#####"

 

wl "Some basic data size"

wl repeat$(70, "-")

wl USING$("Size of BYTE                           is: " & sFormat, SIZEOF(Byte)         )

wl USING$("Size of INTEGER                        is: " & sFormat, SIZEOF(Integer)      )

wl USING$("Size of WORD                           is: " & sFormat, SIZEOF(WORD)         )

wl USING$("Size of DWORD                          is: " & sFormat, SIZEOF(DWORD)        )

wl USING$("Size of LONG                           is: " & sFormat, SIZEOF(Long)         )

wl USING$("Size of QUAD                           is: " & sFormat, SIZEOF(QUAD)         )

wl USING$("Size of SINGLE                         is: " & sFormat, SIZEOF(Single)       )

wl USING$("Size of DOUBLE                         is: " & sFormat, SIZEOF(Double)       )

wl USING$("Size of EXT                            is: " & sFormat, SIZEOF(EXT)          )

wl USING$("Size of CURRENCY                       is: " & sFormat, SIZEOF(Currency)     )

wl USING$("Size of STRING (strings are pointers)  is: " & sFormat, SIZEOF(String)       )

Dim MyString As String

wl USING$("Size of MyString (empty variable)      is: " & sFormat, SIZEOF(MySTRING)     )

MyString = "ABCDEF"

wl USING$("Size of MyString (filled with ABCDEF)  is: " & sFormat, SIZEOF(MySTRING)     )

 

wl repeat$(70, "-")

wl "Press any key to finish"

waitkey

 

 

Second example

Uses "console"

 

Dim v1 As Byte

Dim v2 As Word

Dim v3 As Integer

 

Dim v4 As DWord

Dim v5 As Long

Dim v6 As Quad

 

PrintL "SizeOf() different numeric data types"

PrintL

PrintL "-Data---------Size (bytes)-----------"

PrintL "Byte........:"SIZEOF(v1)

PrintL "Word........:"SIZEOF(v2)

PrintL "Integer.....:"SIZEOF(v3)

PrintL "DWord.......:"SIZEOF(v4)

PrintL "Long........:"SIZEOF(v5)

PrintL "Quad........:"SIZEOF(v6)

 

Dim v10 As Single

Dim v11 As Double

Dim v12 As Ext

Dim v13 As Cur

 

PrintL "-Data---------Size (bytes)-----------"

PrintL "Single......:"SIZEOF(v10)

PrintL "Double......:"SIZEOF(v11)

PrintL "Ext.........:"SIZEOF(v12)

PrintL "Cur.........:"SIZEOF(v13)

 

PrintL "---------------------------------------------------------"

PrintL "Now working with an array of LONGs"

PrintL "-Data-----------------------------Size (bytes)-----------"

Dim someArray(10As Long

PrintL "Size of single array element....:" & SIZEOF(someArray(10))

PrintL "Size of full array..............:" & SIZEOF(someArray())

 

PrintL

PrintL "_____________________________________"

PrintL "---     Press a key to finish     ---"

 

waitkey