Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:26 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Vartable and string length settings

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 06:23am 25 Jul 2018
Copy link to clipboard 
Print this post

posting and update to my learning how the vartable works

strings filled at dim time do not seem to take the lenght
but strings filled later do.

also any information on the parts ?===? unknown would help.


'This code is gleamed from TassyJim short array code and help from Geoff, matherp and other bits from THeBackShed group
' Thanks again for helping me to some what understand things for me not knowing much about c. But learning as I go.
'
'
'OPTION COLOURCODE ON
'OPTION DISPLAY 24,132
Print "use OPTION DISPLAY 24,132 easier to see it"
Pause 2000
Option base 1
Option EXPLICIT

Dim mmite=137
Dim mdow$(7) =("SUN","MON","TUE","WED","THR","FRI","SAT") length 3 ' it looks like the length is not in affect in table
Dim d$(4) =("One","Two","Three","Four") length 5 'same here
Dim word$(2)=("SBC","137") length 3 'and here too
Dim test1!(2,2,2,2,2,2,2) 'array's 8 levels in vartbl but can do only 7 ???
Dim fsc ' defaults to float
Dim fn%=100, c!=4, r$(fn%) length 1, day%(fn%), count%(4),dy%
Dim rstat%(4) = (1,1,1,1), relay%(4) = (10,9,7,6), ry%, t$(5) length 8

For ry%=1 To 4 'a counter ref to look at
count%(ry%)=2^ry%
Next ry%

r$(1)="A":r$(2)="B":r$(3)="3":r$(4)="D" ' but here length is in affect

Dim s$(4)=("12345","acbde","This ","is s.") length 5 ' again not in affect here

t$(1)="12345678":t$(2)="abcdefgh":t$(3)="1234":t$(4)="ABCD":t$(5)="1234ABCD" ' but is in affect here

For fsc=1 To fn%
day%(fsc)=fsc
Next fsc

'lets look at vars in the table
Dim g%,n%,p%, ascii$,last%=Peek(VARTBL,0)

Do
clr
locate 1,4:Print "Name"
locate 1,19:Print "Type Lev"
locate 1,29:Print "|<----- dimensions 8 levels --------->|"
locate 1,71:Print "? ============== ?"
locate 1,92:Print "val/adr"
locate 1,103:Print "? ======= ?"
For g%=0 To 63 'look through up to 64 variables
ascii$=""
For n% = 0 To 35
p%=Peek(VARTBL,n%+g%*64)
If p%=0 Then Exit For 'build variable name (end at chr$(0))
Select Case Chr$(p%)
Case "A" To "Z","0" To "9"
ascii$=ascii$+Chr$(p%)
End Select
Next n%
ascii$=ascii$+Space$(17-Len(ascii$)) 'varname is upto 32
Print Str$(g%,2);" ";ascii$;

Print Hex$(Peek(VARTBL,32+g%*64),2);" "; ' type 1 is number 2 is string 4 is int, not sure what anything else is
Print Hex$(Peek(VARTBL,33+g%*64),2);" "; ' 0 main, 1 ... levels in subs / functions

Print Hex$(Peek(VARTBL,35+g%*64),2);Hex$(Peek(VARTBL,34+g%*64),2);" "; ' looks like 8 levels of dimensions
Print Hex$(Peek(VARTBL,37+g%*64),2);Hex$(Peek(VARTBL,36+g%*64),2);" "; ' seems I can only use the 7 them ??
Print Hex$(Peek(VARTBL,39+g%*64),2);Hex$(Peek(VARTBL,38+g%*64),2);" ";
Print Hex$(Peek(VARTBL,41+g%*64),2);Hex$(Peek(VARTBL,40+g%*64),2);" ";
Print Hex$(Peek(VARTBL,43+g%*64),2);Hex$(Peek(VARTBL,42+g%*64),2);" ";
Print Hex$(Peek(VARTBL,45+g%*64),2);Hex$(Peek(VARTBL,44+g%*64),2);" ";
Print Hex$(Peek(VARTBL,47+g%*64),2);Hex$(Peek(VARTBL,46+g%*64),2);" ";
Print Hex$(Peek(VARTBL,49+g%*64),2);Hex$(Peek(VARTBL,48+g%*64),2);" ";

Print Hex$(Peek(VARTBL,50+g%*64),2);" "; ' size and/or ??

For n%=51 To 55
Print Hex$(Peek(VARTBL,n%+g%*64),2);" "; ' no idea
Next n%

Print " ";
Print Hex$(Peek(VARTBL,59+g%*64),2);Hex$(Peek(VARTBL,58+g%*64),2); 'type at 32 will define how to decode using little e
Print Hex$(Peek(VARTBL,57+g%*64),2);Hex$(Peek(VARTBL,56+g%*64),2);" "; 'address of string and arrays or values of float & init

For n%=60 To 63
Print Hex$(Peek(VARTBL,n%+g%*64),2);" "; ' no idea
Next n%

'Print Hex$(Peek(VARTBL,63+g%*64),2);Hex$(Peek(VARTBL,62+g%*64),2); ' lets try using little e
'Print Hex$(Peek(VARTBL,61+g%*64),2);Hex$(Peek(VARTBL,60+g%*64),2);" ";' here

Print

If Instr(1,ascii$,"LAST") Then Exit For
Next g%
hexdump
Loop
End

Sub hexdump
Local a%,b%,d1$,h$,g%,n%
locate 24,1: Print "0 or RET to exit"
locate 24,78:Print "low address ------^^^^"
Input "low ADR word in hex A000",h$
If h$="0" Or h$="" Then End

a%=Val("&HA000"+h$)

Do
For n% =0 To 15
D1$=""
Print"|"; Hex$(a%,8);" | ";
For g%=0 To 15
b%=Peek(BYTE a%)
Print Hex$(b%,2);" ";
b%=b% And &H7F ' mask out upper bit
If b%=>&h21 And b%<=&H7E Then
d1$=d1$+Chr$(b%)
Else
d1$=d1$+"."
End If
a%=a%+1
Next g%
Print " | ";d1$;" |"
Next n%
Print
If getkey() Then Exit Do
Loop
End Sub

Function getkey()
Local k$
Print "ESC to exit"
k$=""
getkey=0
Do While k$=""
k$=Inkey$
If k$=Chr$(&H1B) Then getkey=1
Loop
End Function

Sub clr
Print Chr$(27)+"[f" : Print Chr$(27)+"[2J"
End Sub

Sub locate x,y
Print Chr$(27)+"["+Str$(X)+";"+Str$(Y)+"f";
End Sub


Understanding more as I (we) go THANKS
Quazee

 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 09:02pm 27 Jul 2018
Copy link to clipboard 
Print this post

Geoff
Look at mdow$(7) in the DIM statement each is 3 bytes and the length is at 3.
but when I look at mdow$ vartable address they are 256 apart not the 4 I was
expecting. The same goes for any string arrays filled in the DIM statement.

Now R$ and T$ are only defined by Dim and filled later. The lengths are as
expected when viewing the vartable address for them. 2 bytes for each R$
and 9 each for T$.

I changed the way MDOW$ is filled and it works as expected.


2018-07-28_065643_vartbl-work.pdf

The test code

'This code is gleamed from TassyJim short array code and help from Geoff and matherp and other bits from THeBackShed
' Thanks again for helping me to some what understand things for me not knowing much about c. But learning as I go.
'
'
'OPTION COLOURCODE ON
'OPTION DISPLAY 24,132
Print "use OPTION DISPLAY 24,132 easier to see it"
Pause 2000
Option base 1
Option EXPLICIT

Dim mmite=137

' 1st way of doing it
Dim mdow$(7) =("SUN","MON","TUE","WED","THR","FRI","SAT") length 3 ' it looks like the length is not in affect in table

' 2nd way of doing it
'Dim mdow$(7) length 3 ' now changing how it is filled
'mdow$(1) ="SUN":mdow$(2)="MON":mdow$(3)="TUE":mdow$(4)="WED":mdow$(5)="THR":mdow$(6)="FRI":mdow$(7)="SAT"
Dim d$(4) =("One","Two","Three","Four") length 5 'same here
Dim word$(2)=("SBC","137") length 3 'and here too
Dim test1!(2,2,2,2,2,2,2) 'array's 8 levels in vartbl but can do only 7 ???
Dim fsc ' defaults to float
Dim fn%=100, c!=4, r$(fn%) length 1, day%(fn%), count%(4),dy%
Dim rstat%(4) = (1,1,1,1), relay%(4) = (10,9,7,6), ry%, t$(5) length 8

For ry%=1 To 4 'a counter ref to look at
count%(ry%)=2^ry%
Next ry%

r$(1)="A":r$(2)="B":r$(3)="3":r$(4)="D" ' but here length is in affect

Dim s$(4)=("12345","acbde","This ","is s.") length 5 ' again not in affect here

t$(1)="12345678":t$(2)="abcdefgh":t$(3)="1234":t$(4)="ABCD":t$(5)="1234ABCD" ' but is in affect here

For fsc=1 To fn%
day%(fsc)=fsc
Next fsc

'lets look at vars in the table
Dim g%,n%,p%, ascii$,last%=Peek(VARTBL,0)

Do
clr
locate 1,4:Print "Name"
locate 1,19:Print "Type Lev"
locate 1,29:Print "|<----- dimensions 8 levels --------->|"
locate 1,70:Print "size ? ========== ?"
locate 1,92:Print "val/adr"
locate 1,103:Print "? ======= ?"
For g%=0 To 63 'look through up to 64 variables
ascii$=""
For n% = 0 To 35
p%=Peek(VARTBL,n%+g%*64)
If p%=0 Then Exit For 'build variable name (end at chr$(0))
Select Case Chr$(p%)
Case "A" To "Z","0" To "9"
ascii$=ascii$+Chr$(p%)
End Select
Next n%
ascii$=ascii$+Space$(17-Len(ascii$)) 'varname is upto 32
Print Str$(g%,2);" ";ascii$;

Print Hex$(Peek(VARTBL,32+g%*64),2);" "; ' type 1 is number 2 is string 4 is int, not sure what anything else is
Print Hex$(Peek(VARTBL,33+g%*64),2);" "; ' 0 main, 1 ... levels in subs / functions
Print Hex$(Peek(VARTBL,35+g%*64),2);Hex$(Peek(VARTBL,34+g%*64),2);" "; ' looks like 8 levels of dimensions
Print Hex$(Peek(VARTBL,37+g%*64),2);Hex$(Peek(VARTBL,36+g%*64),2);" "; ' seems I can only use the 7 them ??
Print Hex$(Peek(VARTBL,39+g%*64),2);Hex$(Peek(VARTBL,38+g%*64),2);" ";
Print Hex$(Peek(VARTBL,41+g%*64),2);Hex$(Peek(VARTBL,40+g%*64),2);" ";
Print Hex$(Peek(VARTBL,43+g%*64),2);Hex$(Peek(VARTBL,42+g%*64),2);" ";
Print Hex$(Peek(VARTBL,45+g%*64),2);Hex$(Peek(VARTBL,44+g%*64),2);" ";
Print Hex$(Peek(VARTBL,47+g%*64),2);Hex$(Peek(VARTBL,46+g%*64),2);" ";
Print Hex$(Peek(VARTBL,49+g%*64),2);Hex$(Peek(VARTBL,48+g%*64),2);" ";

Print Hex$(Peek(VARTBL,50+g%*64),2);" "; ' size and/or ??

For n%=51 To 55
Print Hex$(Peek(VARTBL,n%+g%*64),2);" "; ' no idea
Next n%

Print " ";
Print Hex$(Peek(VARTBL,59+g%*64),2);Hex$(Peek(VARTBL,58+g%*64),2); 'type at 32 will define how to decode using little e
Print Hex$(Peek(VARTBL,57+g%*64),2);Hex$(Peek(VARTBL,56+g%*64),2);" ";'address of $'s and arrays or values of float & init

For n%=60 To 63
Print Hex$(Peek(VARTBL,n%+g%*64),2);" "; ' no idea
Next n%

'Print Hex$(Peek(VARTBL,63+g%*64),2);Hex$(Peek(VARTBL,62+g%*64),2); ' lets try using little e
'Print Hex$(Peek(VARTBL,61+g%*64),2);Hex$(Peek(VARTBL,60+g%*64),2);" ";' here

Print

If Instr(1,ascii$,"LAST") Then Exit For
Next g%
hexdump
Loop
End

Sub hexdump
Local a%,b%,d1$,h$,g%,n%
locate 24,1: Print "0 or RET to exit"
locate 24,78:Print "low address ------^^^^"
Input "low ADR word in hex A000",h$
If h$="0" Or h$="" Then End

a%=Val("&HA000"+h$)

Do
For n% =0 To 15
D1$=""
Print"|"; Hex$(a%,8);" | ";
For g%=0 To 15
b%=Peek(BYTE a%)
Print Hex$(b%,2);" ";
b%=b% And &H7F ' mask out upper bit
If b%=>&h21 And b%<=&H7E Then
d1$=d1$+Chr$(b%)
Else
d1$=d1$+"."
End If
a%=a%+1
Next g%
Print " | ";d1$;" |"
Next n%
Print
If getkey() Then Exit Do
Loop
End Sub

Function getkey()
Local k$
Print "ESC to exit"
k$=""
getkey=0
Do While k$=""
k$=Inkey$
If k$=Chr$(&H1B) Then getkey=1
Loop
End Function

Sub clr
Print Chr$(27)+"[f" : Print Chr$(27)+"[2J"
End Sub

Sub locate x,y
Print Chr$(27)+"["+Str$(X)+";"+Str$(Y)+"f";
End Sub


 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 01:43pm 28 Jul 2018
Copy link to clipboard 
Print this post

OK, I have had a look at the source and I can see what causes this issue. Essentially, the initialising strings prevents the interpreter from "seeing" the LENGTH keyword.

Thanks, another bug found. I will fix it in the next beta.

Geoff
Geoff Graham - http://geoffg.net
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 01:39pm 29 Jul 2018
Copy link to clipboard 
Print this post

I have had a chance to look into this and it is a misunderstanding regarding the documentation and not a bug.

The correct method of defining a variable is:
DIM [type] var [array dimensions] [length] [type] [= initialiser]

The LENGTH qualifier must come before the type qualifier which must come before the initialising values (which are last).

For example, these are all OK:
DIM mdow$(7) LENGTH 3 = ("SUN","MON","TUE","WED","THR","FRI","SAT")
DIM mdow(7) LENGTH 3 AS STRING = ("SUN","MON","TUE","WED","THR","FRI","SAT")
DIM STRING mdow(7) LENGTH 3 = ("SUN","MON","TUE","WED","THR","FRI","SAT")


These are NOT OK:
DIM mdow$(7) = ("SUN","MON","TUE","WED","THR","FRI","SAT") LENGTH 3
DIM mdow(7) AS STRING LENGTH 3 = ("SUN","MON","TUE","WED","THR","FRI","SAT")


The manual does list these requirements but it is not as clear as it could be so I will update it.

It could be argued that AS STRING LENGTH 3 makes more sense than LENGTH 3 AS STRING or an error should be generated and I will look into it but it is not a high priority. Especially as most people use the alternative syntax of DIM STRING var LENGTH n

Geoff

Edited by Geoffg 2018-07-30
Geoff Graham - http://geoffg.net
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 09:37pm 29 Jul 2018
Copy link to clipboard 
Print this post

Hi Geoff, just to clarify, since LENGTH is only meaningful with type STRING:

1. the type STRING can be declared before the LENGTH in two ways:
a. DIM varnam$(nn) LENGTH nn [=("aa","bb", .... ,"nn")]
b. DIM STRING varnam LENGTH nn [=("aa","bb", .... ,"nn")]

2. otherwise the type STRING must appear after the LENGTH like this:
DIM varnam(nn) LENGTH nn AS STRING [=("aa","bb", .... ,"nn")]

3. putting the LENGTH anyplace else will breaken das sprigenwerk und ist verboten:
DIM varnam$(nn) [=("aa","bb", .... ,"nn")] LENGTH nn
DIM varnam(nn) AS STRING LENGTH 3 [=("aa","bb", .... ,"nn")]

Have I got that right????

Sometimes documentation of a computer program is more complicated than making the program work. I was asked to help edit the original documentation for the first Clipper and for Marty Rinehardt's book about dBase 4 and it was amazing how much confusion I generated when I tried to explain what was really happening.

If you want me to I would be glad to help generate confusion for you.

Paul in NY
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 11:57pm 29 Jul 2018
Copy link to clipboard 
Print this post

Yes Paul, you have it exactly right.
Geoff Graham - http://geoffg.net
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 12:21am 30 Jul 2018
Copy link to clipboard 
Print this post


THANKS

Good only a mis-read of the manual. Now to go fix my programs.

Been doing it wrong for awhile.

Maybe add and example of its usage like the other Dim statements.
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 03:54am 30 Jul 2018
Copy link to clipboard 
Print this post

Hey Geoff, I just stumbled on something else. Your internal editor seems to barf on long program lines. I fed it a single line containing 198 characters, buried in a long program, which had a syntax error. It wouldn't scroll properly.

Things that make you go hmmmmmmm ...

Paul in NY
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 12:31pm 30 Jul 2018
Copy link to clipboard 
Print this post

  Paul_L said  Your internal editor seems to barf on long program lines. It wouldn't scroll properly.

From the Micromite Manual (page 56):
  Quote  The editor will work with lines wider than the screen but characters beyond the screen edge will not be visible. You can split such a line by inserting a new line character and the two lines can be later rejoined by deleting the inserted new line character.

It is not as good as horizontal scrolling but the editor already takes up quite a lot of flash and I needed what was left for other functions.
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2463
Posted: 03:41pm 30 Jul 2018
Copy link to clipboard 
Print this post

geoff: i've been using an editor called "nano" that comes with linux (at least with the mint flavour i've been experimenting with recently). nano handles lines wider than the terminal screen by just horizontally scrolling the single line that is being edited (ie, that has the cursor on it), when you move off the line it snaps back to the normal non-scrolled state.

it does look a little odd at first, but you get used to it after a while and it is far better than nothing. might be worth having a look at.


cheers,
rob :-)
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 07:08am 31 Jul 2018
Copy link to clipboard 
Print this post

  Geoffg said  From the Micromite Manual (page 56):
  Quote  The editor will work with lines wider than the screen but characters beyond the screen edge will not be visible. You can split such a line by inserting a new line character and the two lines can be later rejoined by deleting the inserted new line character.

It is not as good as horizontal scrolling but the editor already takes up quite a lot of flash and I needed what was left for other functions.

I agree with your desire to limit the use of flash for the inbuilt editor.

In lieu of a scrolling editor would it be possible to somehow add a real line-continuation character into the language? It might be a good idea to let the colon ":" act as a statement delimiter when in the middle of a line
for i=1 to 99:print i;:next
but to change its function when found at the end of line to become a line-continuation character.
for i=1 to 99: print:
"The quick brown fox jumped over something.";i:next


I know that looks weird. A better example would be a long confabulation of conditional tests.
if (A and B) or (C and D) or (E and F) or (G and H) or (I and J) or (K and L) or (M and N) or (O and P) or (Q and R) or (S and T) or (U and V) or (W and X) or (Y and Z) then 'EOL
XYZ 'EOL
else 'EOL
ZYX 'EOL
endif 'EOL
which could be re-written as
if :
(A and B) or :
(C and D) or :
(E and F) or :
(G and H) or :
(I and J) or :
(K and L) or :
(M and N) or :
(O and P) or :
(Q and R) or :
(S and T) or :
(U and V) or :
(W and X) or :
(Y and Z) then 'EOL
XYZ 'EOL
else 'EOL
ZYX 'EOL
endif 'EOL

I don't believe this will turn the interpreter into an optimizing pre-compiler. It just means that when the interpreter sees the combination of ":"+{CR}+{LF}" it will strip those characters and continue concatening, (is that really a word), the next line from the program file.

Sorry ... just thinking again. I have to learn to stop that.

Paul in NY
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 07:17am 31 Jul 2018
Copy link to clipboard 
Print this post

Another thought ...

This line continuation character could easily exceed any single program line length limitation which might exist in the interpreter. If the interpreter encounters an excessive line length it would have to crash the present code and show an error message such as:
  Quote  YOUR VERBOSITY HAS EXCEEDED MY COGNITIVE CAPABILITIES IN LINE nnn.
I CAN'T CONTINUE PROCESSING YOUR DUMB CODE UNTIL YOU SHORTEN THIS LINE.


Paul in NY
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2463
Posted: 03:15pm 31 Jul 2018
Copy link to clipboard 
Print this post

strictly speaking, a continuation character does not need to be handled by the interpreter at all - just by the editor. when the editor loads a program from flash into RAM (as it does before editing) it could break up long lines and insert the continuation characters itself down the left as required ("|" would visually be a good candidate to use).

similarly, when saving, the editor could interpret a "|" in column 1 as a continuation marker and join the lines back together again before writing out to flash.

i guess the problem is that this does introduce quite some extra complexity, hence uses precious flash space. and it 'solves' a problem that really isn't that much of a problem anyway - i've just done some testing, and as long as you keep the cursor within the first 80 characters of a line you can split up long lines, as well as join short lines together to create long lines. you just can't see what is happening off to the right of the 80 column screen.

i did also find a little 'annoyance' in the editor - if you create a very long line (more than 255 characters i presume), when you exit and save from the editor you get an "Error: Line is too long" error message, and any program lines beyond the offending line are lost. but then i can't think of any sensible way that this situation could be recovered from.


a better approach may be to simply discourage programmers from creating lines longer than 80 characters. perhaps have mmedit generate a warning for long lines, or flag them in a different colour within its own editor.


cheers,
rob :-)
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 04:55pm 31 Jul 2018
Copy link to clipboard 
Print this post

Hi Rob,

I wasn't referring specifically to code written in the internal MMBasic editor or in MMEdit.

I usually write my code in notepad++, then load it into MMEdit principally to format it, then reload it into notepad++ to continue editing.

I was referring to an actual line continuation character which would be included in the notepad++ output file, loaded into the DOS MMBasic interpreter, never looked at with the MMBasic editor, and run. I presume that, under these conditions, the interpreter itself would then have to patch each continued lines together before running them. I am, as you can see, developing some complicated code under DOS.

Back in the 1980s there was a BASIC interpreter, manufactured by Micro Systems Software of Boca Raton FL, and included in their DOSPLUS operating system, which ran on Radio Shack computers. It used the colon, ":", as a line continuation character in just this way. It did not have labels, multi line if or case constructions, sub-routines or defined functions. It required line numbers which were called by GOTO or GOSUB. Yhe line continuation character enabled you to produce nicely readable code.

Paul in NY
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025