PDA

View Full Version : Dim Variations



Charles Pegge
17-03-2009, 18:18
Dim uses smart syntax to accept variables and initialisers in a variiety of formats - to suit all tastes :)







' DIM VARIATIONS

uses "oxygen"
dim src as string
src = "

basic

'----------------
'POST DEFINE TYPE
'================

dim i,j,k as long

'---------------
'PRE DEFINE TYPE
'===============

dim as long i,j,k

'-----------
'MIXED TYPES
'===========


dim as long i,j,k, as string s,t


'----------
'MULTI LINE
'==========

dim as long i,j,k,
as string s,t


dim as long,
i,
j,
k

'--------------
'INITIAL VALUES
'==============

dim as long,
i = 1,
j = 2,
k = 42

'-------------------------
'SPREAD LINES AND COMMENTS
'=========================

dim as long,

i = 1, ' these can be spread over many lines

'--------
j = 2, ' with intervening comments

'--------

k = 42 '

'--------------------
'MULTIPLE ASSIGNMENTS
'====================

dim as long a(10) => (2,4,6,8,10,12,42,99)
print `Answer: ` + a(7)
"
o2_asmo src

'msgbox 0, o2_view src

if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec

Petr Schreiber
17-03-2009, 19:36
Charles,

your O2H is very impressive, I know it will deliver good amount of horsepower for time critical applications ;)
I just tried more "ThinBasicish" version of your


dim as long i,j,k, as string s,t


that means


dim i,j,k as long, s,t as string

thinking it might confuse O2H ... no it didn't, worked perfectly :occasion:


Petr

Charles Pegge
17-03-2009, 22:34
Well Petr I always felt that dim statements are quite restrictive, and there's no perfect agreement between different dialects of BASIC. If the type has not been determined at the begining of the list then it collects all the names and their assignment expressions and looks ahead. The second important rule is that if a comma appears at the end of a line (ignoring comments) then the statement continues.
Comments and blank lines are skipped, which gives you greater flexibility than using traditional underscores.