Dimension Updated: Jan 6, 2012 This section describes how to create user variables and how to run code when an instance of any qualified type is created using a QUALIFIED-TYPE_Init subroutine. Dimension Statements -- Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now that we have what we can dimension, let's look at how to do it. DIM user_symbol As type[, user_symbol As type[, etc]] is the general syntax with examples above and in sample downloads. A shorter version of DIM for specific types: Unsigned Integers: DEFBYTE, DEFWORD, DEFDWORD Signed Integers: DEFSHORT, DEFINT, DEFLNG, DEFINT64 Floating Numbers: DEFSNG, DEFDBL, DEFREAL10 Strings: DEFSTR DEFINT i,j,k,m,n DEFSTR j$,k$,r$,s$,t$ quickly dimensions some scratch numeric and string variables. All strings and numbers -- both variables and arrays -- are initialized to null or zero upon application startup. An initial value may be assigned to the only (or last item) in DEF... DEFINT i, j, k, m, n = 10 DEFSTR j$ = "HotBasic Rocks" DEFSTR ques = "Is the HotBasic HotBabe competition international?" DEFSTR resp = "Yes" At startup, i, j, k and m equal zero, n equals 10 and STRING's j$, ques and resp have assigned values. CONST i = 10 'is actually two statements: DIM i As DOUBLE: i=10 DOUBLE? Yes, that is the default which can be changed with $OPTION DIM INTEGER CONST i = 10 'now i is a 4-byte INTEGER value = 10 $OPTION DIM REAL10 'v1 and v2 dimensioned as REAL10 CONST v1 = 0.5 CONST v2 = 1.5 Summary: Think about what you want to happen when you use CONST. For example, do you really want an integer value like 10 to be stored in a DOUBLE variable? Will your program run slower due to unneeded floating to integer conversions? Create Syntax ~~~~~~~~~~~~~ CREATE = DIM in HotBasic with the additional ability to nest CREATE code blocks and implicitly define parent-child relationships in $APPTYPE GUI. $AppType GUI: $TypeCheck ON 'CREATE and END CREATE are single-statement source code lines CREATE form As FORM caption = "HotBasic Create syntax" width = 300 height = 100 CREATE ed As EDIT top = 10 left = 10 height = 20 width = form.clientwidth - 20 text = "Now I can use an IDE!" color = rgb(200,200,255) enabled = true END CREATE showmodal END CREATE END SELF syntax as presented in the Custom Objects chapter may also be used in CREATE blocks. For example, style = self.style OR 1 is the same as style = form.style OR 1 Local Variables ~~~~~~~~~~~~~~~ Any qualified type dimensioned in a SUB or FUNCTION is "local". The same user symbols may be dimensioned in different procedures. As the compiler Symbol Table shows, new symbols are created by adding the SUB/FUNCTION name as a prefix to "local" user symbols. Thus the local variables will always have unique names. However, these items may be accessed anywhere in source code *outside* the procedure if the full item name is used. Example: In "SUB MATRIX", we "DIM i as long". Variable i is referred to as "i" in SUB MATRIX and as MATRIXi, if necessary, elsewhere in source code and will appear as MATRIXi in the Symbol Table. STATIC = DIM at present in HotBasic. How to Run Code to "Initialize" a DIM/CREATE Instance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are two ways to initilize a newly created instance of a user variable, type or Custom Object. Constructor syntax may be used to set default values for TYPE or Custom Object members. Also, if a QUALIFIED-TYPE_Init SUBROUTINE is defined, you can run code when a new instance is dimensioned. Please note that the qualified type is upper-case. Example: =====obj_init.bas declare sub FORM_Init 'FORM is upper-case here sub FORM_Init showmessage "I made a FORM!" end sub create form As FORM end create form.showmodal END =====obj_init.bas Other more advanced Custom Object examples may be examined in cpuid.inc, sblabels.inc and shellex.inc in your include (inc) sub-directory. + Penthouse (Registered) version Copyright 2003-2012 James J Keene PhD Original Publication: Oct 9, 2003