Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:27 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 : Questions about OPTION EXPLICIT

Author Message
Paul_L
Guru

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

I'm a little confused, as usual, by the manuals this time.
  Quote  OPTION DEFAULT FLOAT | INTEGER | STRING | NONE
Used to set the default type for a variable which is not explicitly defined.
If OPTION DEFAULT NONE is used then all variables must have their type
explicitly defined.

When a program is run the default is set to FLOAT for compatibility with
previous versions of MMBasic.

OPTION EXPLICIT
Placing this command at the start of a program will require that every variable
be explicitly declared using the DIM command before it can be used in the
program.

This option is disabled by default when a program is run. If it is used it must
be specified before any variables are used.

I presume that:

1 - OPTION EXPLICIT has to be placed before any variables are defined.
2 - OPTION EXPLICIT may follow other OPTION commands.
3 - If OPTION EXPLICIT is used variables must be defined by DIM or LOCAL.

Am I right so far?

Now, when a variable is defined by LOCAL will that variable be visible to subs and functions called by the SUB or FUNCTION in which the variable is declared? In other words, are local variables inherited by child routines?

Paul in NY
 
Geoffg

Guru

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

  Paul_L said  1 - OPTION EXPLICIT has to be placed before any variables are defined.

No, but it it would sensible to do so.

  Paul_L said  2 - OPTION EXPLICIT may follow other OPTION commands.
3 - If OPTION EXPLICIT is used variables must be defined by DIM or LOCAL.

Yes to both.

  Paul_L said   I'm a little confused, as usual, by the manuals this time.

It is easy to test this type of stuff - just fire up MMBasic and experiment.

  Paul_L said  Now, when a variable is defined by LOCAL will that variable be visible to subs and functions called by the SUB or FUNCTION in which the variable is declared? In other words, are local variables inherited by child routines?

No.
Geoff Graham - http://geoffg.net
 
Azure

Guru

Joined: 09/11/2017
Location: Australia
Posts: 446
Posted: 12:14am 23 Jul 2018
Copy link to clipboard 
Print this post

Yes to 1, 2 and 3.

Did a little testing to check the following answers below were correct.

No to the last point a nested sub does not inherit the 'LOCAL' variables of any parent. To share variables in nested subs they must be passed as a calling argument or be global (declared in DIM's).

To round things out the visibility of 'CONST' is the same, if declared in the main body it is visible to all and if declared inside a sub it is only visible within that sub.
 
Paul_L
Guru

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

Thanks very much Geoff and John.

I think I'm getting old. It's taken 80 years for me to think this. I have used many languages since I learned COBOL and FORTRAN back in the 1950s. Right now I am writing a thing that parses text in LUA and modifying a FoxPro (dBase - sort of) DBMS application,both for a charities, and my geothermal controller program in MMBasic and I find myself writing code in the wrong language.

If you guys ever see me mixing Polish into my posts give me a shout telling me that it's time to hang up my keyboard.

Paul in NY
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 12:07pm 23 Jul 2018
Copy link to clipboard 
Print this post

Lua is certainly good for parsing, but for the sake of not having to learn a new language (one which does have its complexities), why not do it with MMBasic for DOS?

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

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

Hi Lance.

The LUA program is something that I put together about a year ago for a greyhound adoption group and I'm modifying it. MMBasic won't do the job. It reads 25KB long strings and changes text in them, and it's blindingly fast. The FoxPro database file contains 108,000 member activity records for all the Elks clubs in the Hudson Valley area and has been in use since I first wrote the program under dBase in 1992. I'm now doing a small update.

Paul in NY
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 129
Posted: 05:29pm 24 Jul 2018
Copy link to clipboard 
Print this post

You're not getting old Paul.
You're not losin' it because you're usin' it.

Nice to see you using Foxpro. I use it too though I'm not a professional programmer.

I used to confuse writing IIF with IFF (an Air Force term). So hard to spot. I certainly could have used OPTION EXPLICIT back then.




 
Quazee137

Guru

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

Oh my Fortran DBase III and CPM was it was fun then too.


Paul_L
  Quote  If you guys ever see me mixing Polish into my posts give me a shout telling me that it's time to hang up my keyboard.


No way "keep the keyboard" and we'll just Google it.

 
Bill7300
Senior Member

Joined: 05/08/2014
Location: Australia
Posts: 159
Posted: 05:22am 26 Jul 2018
Copy link to clipboard 
Print this post

Unless you type your Polish in backwards,Paul. That should be OK. Reverse Polish Notation has long been an accepted practice in our vocation!
Bill
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 10:20pm 26 Jul 2018
Copy link to clipboard 
Print this post

While writing the far jump resolution code for an assembler at Cornell back in 1957 I inserted some remarks in Polish. IBM bought that assembler from Cornell about 1962. In 1991 I was poking around in the assembler source code for the 3090 assembler that Pan Am had and I found the Polish remarks I had inserted 34 years before.

Apparently none of the army of IBM programmers who had worked on that source code down through the decades could read Polish so they didn't cut or modify my remarks.

Reverse Polish Notation was first invented by Jan Lukasiewicz (pronounced Yan lu-KAshevich) in 1927. Apparently nobody understood it because it was later re-invented by Arthur Burks ... Don Warren ... Jesse Wright ... Fredrich Bauer ... and finally Edsger Dijkstra ... whew.

It really isn't all that complicated. It eliminates the need for parentheses by forcing two operaands to precede each operator. It's used mostly in manipulating the stack. It's also called post fix notation instead of pre fix notation.

a + b becomes a b +
a + b - c becomes a b + c -
(a + b) * c becomes a b + c *
a + b * c becomes b c * a + (note the order of operations precedence)
a + (b * c) becomes b c * a +
a ( (b*c) + (d*e) ) becomes b c * d e * + a *

It takes longer to learn, forces the human to write the first operation first, but it runs faster in a processor.

Only Polacks can intuitively understand it. We really are different.

Pavel Artur Jac Waclaw Lepkowski in NY
Edited by Paul_L 2018-07-28
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:32pm 26 Jul 2018
Copy link to clipboard 
Print this post

Would like to get a little of feedback on declaring Functions.

One example is:-

  Quote  Function BldReq(Ad%,Fc%,A1%,A2%,N1%,N2%) As String
BldReq=
Chr$(Ad%)+Chr$(Fc%)+Chr$(A1%)+Chr$(A2%)+Chr$(N1%)+Chr$(N2%)
BldReq=BldReq+CrcStr(BldReq)
End Function

Function BldReq(Ad As Integer,Fc As Integer,A1 As Integer,A2 As Integer,N1 As Integer,N2 As Integer) As String
BldReq=
Chr$(Ad)+Chr$(Fc)+Chr$(A1)+Chr$(A2)+Chr$(N1)+Chr$(N2)
BldReq=BldReq+CrcStr(BldReq)
End Function



Are these the only two valid ways of declaring the Function?
The second example becomes very long...

Is there a way to treat it like:-

  Quote  Function BldReq(Ad,Fc,A1,A2,N1,N2 As Integer) As String
BldReq=
Chr$(Ad)+Chr$(Fc)+Chr$(A1)+Chr$(A2)+Chr$(N1)+Chr$(N2)
BldReq=BldReq+CrcStr(BldReq)
End Function



I've tried a few variations, but no success with anything bar the first two examples.

Cheers

Phil.

 
Paul_L
Guru

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

Maybe this as well.

Function BldReq$(Ad%,Fc%,A1%,A2%,N1%,N2%)
BldReq=Chr$(Ad%)+Chr$(Fc%)+Chr$(A1%)+Chr$(A2%)+Chr$(N1%)+Chr$(N2%)
BldReq=BldReq+CrcStr(BldReq)
End Function


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