Define
DescriptionDefine.<type> [<variable> [= <expression>], <variable> [= <expression>], ...]
Assign the same data type to a series of variables.
Without this keyword, variables are created with the default type of PureBasic which is the type INTEGER. As a reminder, the type INTEGER is:
4 bytes (with a 32-bit compiler) ranging from -2147483648 to + 2147483647
8 bytes (with a 64-bit compiler) ranging from -9223372036854775808 to +9223372036854775807
Define is very flexible because it also allows you to assign a different type to a particular variable within a series.
Define can also be used with arrays, the lists and the maps.
Example: Serial assignment
Define.b a, b = 10, c = b*2, d ; these 4 variables will be byte typed (.b)
Example: Mix of individual and serial assignments
Define.q a, b.w, c, d, st.s = "ok" ; a, c, and d are Quad (.q), b is a Word (.w) and st a String (.s) Debug SizeOf(a) ; will print 8 Debug SizeOf(b) ; will print 2, because it doesn't have the default type Debug SizeOf(c) ; will print 8 Debug SizeOf(d) ; will print 8 Debug st ; will print ok
DescriptionDefine <variable>.<type> [= <expression>] [, <variable>.<type> [= <expression>], ...]
Alternative possibility for the variable declaration using Define.
Example
Define MyChar.c Define MyLong.l Define MyWord.w Debug SizeOf(MyChar) ; will print 2 Debug SizeOf(MyLong) ; will print 4 Debug SizeOf(MyWord) ; will print 2