Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:26 08 Jul 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 : Com port problem

     Page 3 of 3    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:47am 14 Aug 2016
Copy link to clipboard 
Print this post

I'd agree with you apart from one problem

HOW am I meant to know what the fault code it puts up means in plain English?

An example [quote]
Error: Variable type not specified[/quote]

I've searched both manuals but they make no mention of what that means
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:53am 14 Aug 2016
Copy link to clipboard 
Print this post

1 ) One of the little tricks to remember is to pronounce the $ as 'string'.

Text$ is TextString.
It helps to keep numbers and strings separated.

2 ) You can not put a string in a number and you can not put a number in a string without help from a function.

Remember those two things and it will make things easier.

Every function that has a $ in the name has to do with strings and will return a string as a result.
Left$ (LeftString), Mid$ (MidString), Right$(RightString) , Chr$(CharacterString) etc..

Hope it helps. :)

And yes add those two lines Matherp suggested.
You'll get errors, but it will save you lots of time later.
Edited by MicroBlocks 2016-08-15
Microblocks. Build with logic.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 06:57am 14 Aug 2016
Copy link to clipboard 
Print this post

You have three options

DIM INTEGER myint1,myint2,
DIM STRING mystring,...
DIM FLOAT myfloat,...

or you can use a suffix

DIM myint1%,myint2% ' % means integer
DIN mystring$,... ' $ means string
DIM myfloat!,... ' ! means float

"Option default none" forces you to choose or else you get the error you note above

 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:43am 14 Aug 2016
Copy link to clipboard 
Print this post

Thanks Jean, that did make it a lot easier to understand
Edited by lew247 2016-08-15
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:02am 14 Aug 2016
Copy link to clipboard 
Print this post

What does this error mean?
[quote][309] Function GetMins(yr, mth, day, hr, min)
Error: Variable type not specified[/quote]
I have declared yr, mth, day, hr and min

IF I try and declare GerMins it says [161] Dim STRING GetMins
Error: A sub/fun has the same name: GETMINS

I'm completely stuck on this one

(given up on the lcd code for the moment - tidying up the outdoor code now)

EDIT: In case it's needed here's the (Geoff's I believe) function
[code]' convert minutes back into the time (as a string)
FUNCTION GetTime$(minutes)
LOCAL hr, min, am$
hr = (minutes \ 60) MOD 24
IF hr = 0 THEN hr = 12
min = minutes MOD 60
GetTime$ = STR$(hr) + ":"
GetTime$ = GetTime$ + RIGHT$("0" + STR$(min), 2) + ":"
GetTime$ = GetTime$ + RIGHT$("0" + STR$(sec), 2) + " " + am$
END FUNCTION [/code]Edited by lew247 2016-08-15
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 08:11am 14 Aug 2016
Copy link to clipboard 
Print this post

you have a function define in line 309 which has the name GetMins

You can't have a variable that has the same name as a function.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:16am 14 Aug 2016
Copy link to clipboard 
Print this post

Thanks Peter, I renamed the variable and it passed
Onto the next fault now
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:34am 14 Aug 2016
Copy link to clipboard 
Print this post

deleted - sorted itEdited by lew247 2016-08-15
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:22am 14 Aug 2016
Copy link to clipboard 
Print this post

What does Error: Invalid variable mean?
in this context

[440] For y = 1 To 9 'move data up array
Error: Invalid variable
Edited by lew247 2016-08-15
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:38am 14 Aug 2016
Copy link to clipboard 
Print this post

It meant I had the DIM setting wrong* in case anyone else comes across something similar
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 10:59pm 14 Aug 2016
Copy link to clipboard 
Print this post

Keep up the good work, lew247!

Perseverance is the key to success, and you are keeping at it and not just giving up when you hit a problem, which is essential to that success.

Perhaps it would be worthwhile writing up a decent glossary of all the different errors that MMBASIC can generate?

"Error: Invalid variable" does assume that you know exactly what the MMBASIC interpreter is trying to tell you.

However, back in the early days of MMBASIC, there was not even these simple text messages for errors. MMBASIC just stopped with something like "Syntax error, Line 246." kind of message. At least now, the interpreter is much more "Intelligent" and can analyse the error and give you more specific text as to what the problem is.

[Quote]HOW am I meant to know what the fault code it puts up means in plain English?

An example:

Error: Variable type not specified.


I've searched both manuals but they make no mention of what that means.[/Quote]

Case in point. That error message IS the plain-English description of the problem. The issue would seem to be with not understanding what that English description of the problem actually MEANS to you, the newcomer. A glossary of all the possible error messages I think would be helpful. I will email Geoff for a full list of all the error messages that MMBASIC can ever spit out. He's still on holiday though, so this might take a few weeks.Edited by Grogster 2016-08-16
Smoke makes things work. When the smoke gets out, it stops!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:20pm 14 Aug 2016
Copy link to clipboard 
Print this post

I agree a description of the error messages for someone who isn't good at programming would be ideal

At the moment I'm really stuck on Geoff's GPS CODE
I had it working perfectly in my program, but once I put the OPTION EXPLICIT and OPTION DEFAULT NONE - it threw up so many errors
Most of the stuff in my own code I've sorted, but until I get this section of GPS code sorted I can't get any further.
To make it easier I just loaded the GPS code in MMEDIT and flashed it and am (VERY) slowly working through it but it's driving me crazy
This is the one thats driving me nuts at the moment "Error: Variable type not specified"
It's relating to a function but all the bits in the function are declared...Edited by lew247 2016-08-16
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:24pm 14 Aug 2016
Copy link to clipboard 
Print this post

To show you what I mean
This is the error
[quote]
[136] Function GetMins(yr, mth, day, hr, min)
Error: Variable type not specified
[/quote]

but here is the DIM statements
[code]
DIM INTEGER min
DIM INTEGER yr
DIM INTEGER mth
DIM INTEGER hr
DIM INTEGER day
[/code]

and this is the function
[quote]' calculate the minutes since midnight 1st Jan 2014
FUNCTION GetMins(yr, mth, day, hr, min)
GetMins = (yr - 14) * (365 * 24 * 60) + ((yr - 13) \ 4) * (24 * 60)
GetMins = GetMins + (md(mth) * (24 * 60))
GetMins = GetMins + ((day - 1) * (24 * 60))
GetMins = GetMins + (hr * 60)
GetMins = GetMins + min
IF (yr - 16) MOD 4 = 0 AND mth > 2 THEN GetMins = GetMins + (24 * 60)
END FUNCTION [/quote]Edited by lew247 2016-08-16
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 11:34pm 14 Aug 2016
Copy link to clipboard 
Print this post

With option explicit you have to define the type of the function parameters and return:

FUNCTION GetMins(yr as integer, mth as integer, day as integer, hr as integer, min as integer) as integer
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:37pm 14 Aug 2016
Copy link to clipboard 
Print this post

ahh that makes sense
Thanks
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:39pm 14 Aug 2016
Copy link to clipboard 
Print this post

Deleted - I'm an idiot - not reading properlyEdited by lew247 2016-08-16
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 01:03am 15 Aug 2016
Copy link to clipboard 
Print this post

MMBASIC has grown to be a quite advanced BASIC compared to what it was in the beginning. With that extra advancement, comes a certain amount of mandatory complexity, but C'est La Vie.

The thing to remember with OPTION EXPLICIT is that it means: "Set the MMBASIC OPTION to EXPLICIT mode, so that ALL variables MUST be specifically defined before you can use them."

That also means the likes of D AS INTEGER and D AS STRING are completely different, but both can be referred to just with "D" in the code. Personally, I like Rob, prefer to use the dollar-sign to ID strings - this has always been how most BASIC's of old have ID'd strings, and you can visually see the difference between D and D$

OPTION EXPLICIT is really best used at the start of your code, when you are writing a new code, becasue adding it to the start of an existing code(that may work fine), will cause MMBASIC to have a hernia, which I think is what happens to many people who try to retroactively add the OPTION EXPLICIT to their code.

When writing NEW code, OPTION EXPLICIT is fantastic to have, because it will stop the code running, if it comes across any variables at all that are not specifically defined(usually at the top of your code), and this DOES help greatly in tracking bugs in your code - but probably only works best when writing new code, and probably works worst if you add it to an old code.
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 3 of 3    
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