Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:55 06 May 2024 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 : Compatibility of 4.5 and 5.3 code.

Author Message
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:13am 02 Apr 2017
Copy link to clipboard 
Print this post

In an effort to make code written for MMbasic v5.3 run under the MMbasic.exe v4.5 interpreter I have found what I believe might be a snag.

In 5.3 you dimension and assign initial values to variables like this:
OPTION EXPLICIT : DIM a=22, b=33, c$="Hi there."

Q1: Will 4.5 fail if you try to DIM other than array variables?
DIM a, b, c$

Q2: Will 4.5 fail if you try to assign initial values in a DIM statement?
DIM a=22, b=33, c$="Hi there."

Q3: Under 4.5 should you just assign initial values in separate statements, without using DIM, like this?
'DIM a, b, c$
a=22:b=33:c$="Hi there."

Q4: In an attempt to include conditional statements which will select versions based on where the code is running will the following work?
'OPTION EXPLICIT:DIM MM 'comment this line out for 4.5, leave in for 5.3

MM=4.5 'substitute 4.5 or 5.3 for different versions

if MM=4.5 then
a=22:b=33:c$="Hi there."
else
DIM a=22, b=33, c$="Hi there."
endif


Paul in NY
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 04:13pm 02 Apr 2017
Copy link to clipboard 
Print this post

You can do it the 'slow and steady' way to work for both versions.
  Quote   DIM a,b,c$
a=
22: b=33: c$="Hi there."


You think you have problems,
With MMEDit, I have to cater for 6 different devices, all with multiple versions of MMBasic on them.

Jim
VK7JH
MMedit   MMBasic Help
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 09:57pm 02 Apr 2017
Copy link to clipboard 
Print this post

Hi Jim. The reason I asked this question is that the manual for 4.5 does not mention using DIM to declare simple variables. It says:
  Quote  DIM var(dim) , [var(dim)]...
Specifies a variable that is an array with one or more dimensions. The
variables can be numbers or strings with multiple declarations separated
by commas.

I guess that if DIM will work with simple variables then Geoff just must have figured that nobody would bother to use it to pre-declare variables because he hadn't introduced OPTION EXPLICIT yet.

Paul in NY
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:56am 04 Apr 2017
Copy link to clipboard 
Print this post

Some more interesting tidbits.

1. Using a "?" as an abbreviation for "PRINT" is interesting. If you follow the "?" with a quoted string no space is required but if you follow the "?" with a variable name you have to include a space after the "?". In other words this code
?"-----------":k=4:?k
produces
[2]k=4:?k
Error: Invalid character
but this code
?"-----------":k=4:? k ' space has been added after the "?"
produces the expected
-----------
4


2. Version 4.5 will apparently follow the old microsoft convention of allowing a single variable name to be used simultaneously for different types. In other words you can have an H$ and an H! (float single precision) and they are different variables! I think Geoff "separated" the variable name from the type designator after this version. This means that you have to use the type designator when you call the string variable even if there is no float variable with the same name.

For example:
H$="eleven":H=11:? H$:? H:H$="twenty two":H=H+11:? H$:? H
produces
eleven
11
twenty two
22

and this
i$="this is another string":?"-------------"::? i
produces
-------------
0
instead of the possibly expected
-------------
this is another string
Very interesting.

Paul in NY
Edited by Paul_L 2017-04-05
 
Print this page


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

© JAQ Software 2024