Returns the size of a variable or a user-defined type.
SizeOf(a)
a:variable or user-defined type
SizeOf returns the number of bytes a variable or user-defined type occupies.
String variables always return 4, and Variant variables always return 16.
For an array only the size of an element can be determined.
Strings
OpenW 1
Local a$, x%, b As String*10000
a$ = Space$(1000)
Print SizeOf(a$) // prints 4
Print SizeOf(b) // prints 10000
Print Len(a$), Len(b) // prints 1000, 10000
Type variables
OpenW 1
Type test // Packed 1
- String*10 a$
- Byte b(5)
- String*5 c(5)
- UByte d(5)
- Variant e(5)
- Double f(5)
- Word g(5)
- Currency h(5)
- Large j(5)
- Int k(5)
- Float l(5)
- String*10 m$
EndType
Global R As test
Print "b()-Byte", SizeOf(R.b(1))
Print "c()-String*5", SizeOf(R.c(1))
Print "d()-UByte", SizeOf(R.d(1))
Print "j()-Large", SizeOf(R.j(1))
Print "k()-Int", SizeOf(R.k(1))
Print "l()-Float", SizeOf(R.l(1))
Print "m-String*10", SizeOf(R.m$)
SizeOf is compatible with C.
{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}