![]() |
Forum Index : Microcontroller and PC projects : Com port problem
![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
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 KingdomPosts: 1702 |
Thanks Jean, that did make it a lot easier to understand |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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] |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
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 KingdomPosts: 1702 |
Thanks Peter, I renamed the variable and it passed Onto the next fault now ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
deleted - sorted it |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
What does Error: Invalid variable mean? in this context [440] For y = 1 To 9 'move data up array Error: Invalid variable |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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 ZealandPosts: 9590 |
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. Smoke makes things work. When the smoke gets out, it stops! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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... |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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] |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
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 KingdomPosts: 1702 |
ahh that makes sense Thanks ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Deleted - I'm an idiot - not reading properly |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9590 |
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! |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |