Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:05 17 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 : Saving and recalling variables from SD card

Author Message
frnno967
Senior Member

Joined: 02/10/2020
Location: United States
Posts: 105
Posted: 03:07am 12 Jan 2021
Copy link to clipboard 
Print this post

sub saveconfig
open "settings.cfg" for output as #7
print #7, comporttype$
print #7, rs232%
print #7, linefeedstate$
print #7, linefeeds%
print #7, modeminitstring$
close #7
end sub

sub loadconfig
open "settings.cfg" for input as #7
line input #7, comporttype$
line input #7, rs232%
line input #7, linefeedstate$
line input #7, linefeeds%
line input #7, modeminitstring$
close #7
end sub


When I use the above subroutines in my code, I find that the variables are not read back from the SD card correctly. It seems like it can't save or recall the INT variables correctly. Is this correct behavior, or a bug?

Thank you.
Jay Crutti: Ham Radio Operator, K5JCJ. Computer Enthusiast. Musician. Engineer.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 05:10am 12 Jan 2021
Copy link to clipboard 
Print this post

As the manual says:

  Quote  LINE INPUT #nbr, string-variable$
Reads an entire line from the console input into 'string-variable$'.
'prompt$' is a string constant (not a variable or expression) and if specified
it will be printed first


LINE INPUT is expecting a string. Try:

INPUT #7, rs232%

Or if you do want to use LINE INPUT try:

LINE INPUT #7, a$ : rs232% = VAL(a$)

Bill
Edited 2021-01-12 16:33 by Turbo46
Keep safe. Live long and prosper.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 06:46am 12 Jan 2021
Copy link to clipboard 
Print this post

Agreed.  The problem is your rs232% which is an integer, and you can't line-input an integer, only strings.

As well as above, you could change the 2nd line in your code examples to:

Print #7,STR$(rs232%) to save, and...

Line Input #7, A$:rs232%=VAL(A$) as Bill posted above to read it back.

EDIT: You will need to do the same for your linefeeds% integers too.
Edited 2021-01-12 16:48 by Grogster
Smoke makes things work. When the smoke gets out, it stops!
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 07:51am 12 Jan 2021
Copy link to clipboard 
Print this post

+1, except

Print #7,STR$(rs232%)

may as wwell be

Print #7,rs232%

i.e. as it is already.

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 08:19am 12 Jan 2021
Copy link to clipboard 
Print this post

  Quote  It seems like it can't save or recall the INT variables correctly. Is this correct behavior, or a bug?


What version of MMBasic? Look at BIN2STR$ and STR2BIN that were specifically designed for this purpose
 
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