Skip to content

SizeOfType

See Also: SizeOfString, SizeOfWString, Data Types, Variables and Constants

Purpose

SizeOfType returns the size in bytes of the specified data type. It can be used with both fundamental types and user-defined struct types.

This is typically needed for passing structs to External_Function calls.

Return Type

Integer

Syntax

(SizeOfType({type}))

Where:

Example 1

This sample shows how to determine the size of the string data type.

Function SizeOfString
    Move (SizeOfType(string)) to iSize
    Function_Return iSize
End_Function

Example 2

This sample shows how to determine the size of a structured data type.

Struct tPoint
    Integer iXPos
    Integer iYPos
End_Struct

Function SizeOf_tPoint returns Integer
    Integer iSize
    Move (SizeOfType(tPoint)) to iSize
    Function_Return iSize
End_Function

Notes

A common mistake is to pass a variable of a particular data type instead of the data type itself. For example:

Procedure OnClick
    Integer iCounter iTypeSize
    Move (SizeOfType(iCounter)) to iTypeSize
End_Procedure

This code will result in compiler error 54 "Invalid symbol in expression". The corrected version of the above code is shown below, passing the data type itself:

Procedure OnClick
    Integer iCounter iTypeSize
    Move (SizeOfType(integer)) to iTypeSize
End_Procedure