Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:40 27 Nov 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 : MMBasic VAR SAVE

Author Message
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 05:48am 25 Nov 2023
Copy link to clipboard 
Print this post

Hi All

If I put a command in my program:
VAR SAVE TxValue
as the only variable I want to save, do I need to do anything else before turning the power off?
I am getting a zero value in TxValue when I put this at the start of the program:
VAR RESTORE

Can this be placed anywhere in the program, or does it have to be in
Sub MM.STARTUP.

Second question, how important is case with Options from the command line ?
Edited 2023-11-25 15:49 by Dinosaur
Regards
Hervey Bay Qld.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9307
Posted: 06:01am 25 Nov 2023
Copy link to clipboard 
Print this post

I have a feeling that you have to define all the variables BEFORE calling VAR RESTORE.
If a variable has not been defined, and you try to restore its value via VAR RESTORE, it will fail, as there is no defined variable for the interpreter to update in the variable name table.

I might have that totally wrong, and modern versions of the FM might automatically CREATE the variable, if it does not exist during a VAR RESTORE, but I do remember in the past having to define and initialize the variables in the code BEFORE doing a VAR RESTORE before it would work.

Again, I am only going on my memory for this, and I might have that wrong, but it would not hurt to define "TxValue" first, and THEN issue the VAR RESTORE command.
Smoke makes things work. When the smoke gets out, it stops!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 08:16am 25 Nov 2023
Copy link to clipboard 
Print this post

You need to define arrays but not simple variables. You should call VAR SAVE when the variable has a value that needs saving. It is not some sort of automatic system that keeps a variable saved as it changes
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 09:29am 25 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Thanks for the response guys.
What I did was:

CLEAR
OPTION EXPLICIT
OPTION DEFAULT NONE
DIM AS STRING IP$,Tyd$,Err$
Dim as Float TxValue

Dim Integer CalTime,mSec,StepNbr,StartTime,CommFlag
Dim Integer StartTime0,Delay0                     'variables for  each Task
Dim Integer StartTime1,Delay1
Dim Integer StartTime2,Delay2
Dim Integer StartTime3,Delay3
Dim Integer StartTime4,Delay4

Then all the subs, the main one being:

SUB Initialize
   ON Error Ignore
   VAR Restore
   Print "Var Restored;";TxValue
   If MM.Watchdog Then
       Print "Watchdog reboot happened"
       Err$ = "WatchDog"
   EndIf
   StartTime0 = mSec                             'So that next delay is correct
   StartTime1 = mSec
   StartTime2 = mSec
   StartTime3 = mSec
   StartTime4 = mSec
   WatchDog 300000                               '5 min before reboot
End Sub

If the order of execution is correct then will have to find other reasons for it not working.
I did have some problems with different version of my program loading from a different folder
and wondering why it did that.
If I open a file in MMEdit, then press Transfer to MMCC and then RUN, it should run the program
open in the editor.
Will put the backups well away from the directory structure and try again.

Should the declarations be AFTER the MM.STARTUP ?
Edit again:There is something basic I am missing.
If I power down the program starts from the very beginning. (the print statements show me that)
If I Ctrl C out of the program and then type RUN, I get a completely different start point ??

Print "Nbr of Variables= ";MM.INFO(VARCNT) produces 0

FOUND IT: FreeBasic habit of "Dim AS Float" should be DIM FLOAT
and you can't put any statements inside the MM.STARTUP other than the "RTC GETTIME"

I will get there.
Edited 2023-11-25 20:11 by Dinosaur
Regards
Hervey Bay Qld.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 896
Posted: 12:15pm 25 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  
If I power down the program starts from the very beginning. (the print statements show me that)
If I Ctrl C out of the program and then type RUN, I get a completely different start point ??

There is a difference between restarting MMBasic and restarting your program.

A restart of MMBasic is initiated by power being applied, the RST button being pressed or the CPU RESTART command. Each of these will cause MMBasic to restart.
The MM.STARTUP routine is searched for and if found any code in it is then executed.
If OPTION AUTORUN ON is set then any program in the program memory is run,
otherwise the command prompt is shown.

The RUN command will clear any variables and then run the program in memory, but does not search for MM.STARTUP. So you only get MM.STARTUP if MMBasic is actually restarted.
Latest F4 Latest H7
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 07:34pm 25 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Thank you for that information.

So, the real question for first time users of MMBasic is:
Which documentation applies to my setup, so I don't pester members with mundane questions.

I appreciate the time spent creating extensive doc's (which MMBasic certainly has).
But if I use a Rpi-Pico W and happen to pick the Webmite image ??
Regards
Hervey Bay Qld.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6099
Posted: 08:33pm 25 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  Hi All

Thank you for that information.

So, the real question for first time users of MMBasic is:
Which documentation applies to my setup, so I don't pester members with mundane questions.

I appreciate the time spent creating extensive doc's (which MMBasic certainly has).
But if I use a Rpi-Pico W and happen to pick the Webmite image ??


Since you have a WEBmite, that is the best manual to start with.
https://geoffg.net/webmite.html
Scroll down to the bottom of the page.

It is also a very good idea to read the latest beta/RC threads to see whats in the next version.

Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


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

© JAQ Software 2024