Dimension
Updated: Apr 16, 2005

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
  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


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.

STATIC = DIM at present in HotBasic.


###########

+  Penthouse (Registered) version

Copyright 2003-2005 James J Keene PhD
Original Publication: Oct 9, 2003
