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 StatesPosts: 769 |
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: AustraliaPosts: 5914 |
You can do it the 'slow and steady' way to work for both versions. 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 StatesPosts: 769 |
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: 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 StatesPosts: 769 |
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 but this codeError: Invalid character ?"-----------":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 produceseleven 11 twenty two 22 and this i$="this is another string":?"-------------"::? i produces------------- instead of the possibly expected0 ------------- Very interesting.this is another string Paul in NY |
||||
Print this page |