Author |
|
Geoffg Guru


Joined: 06 June 2011 Location: Australia
Online Status: Offline Posts: 2488
|
Posted: 13 July 2018 at 9:39pm | IP Logged
|
|
|
Good grief! I don't know where to start. There are so many misunderstandings in your code that I can only give some general pointers.
The first thing that you should do is use the code button to insert your code in your posts. That will retain any indenting which is essential to understanding someone else's code.
This is just a few comments that are obvious:
text 100, 10, str$(nbr_hi) ' this prints 2 ?????????? Of course it will print 2... this is what you set nbr_hi to.
text 130, 10,CtrlVal(nbr_hi) 'Error: Expected a string CtrlVal(nbr_hi) refers to a NUMBERBOX which returns a float number. TEXT expects a string. That is why you got an error.
text 130, 10,CtrlVal(str$(nbr_hi)) 'Error: Expected a number What are you trying to do here? CtrlVal() expects a number as an argument and you are giving it a string!
if str$(Temp) > CtrlVal(nbr_hi) then 'Error: Incompatible types in expression You are trying to compare a string with a number.
You may not realise that CtrlVal() can return a string or a number depending on the control you are querying. For example using CtrlVal() on a TEXTBOX will return a string (because it holds a string) and on a NUMBERBOX it will return a number (because that is what a number box will hold).
My advice is:
- Read the sections dealing with data types and GUI controls in Getting Started with the Micromite and both manuals (Micromite User Manual and Micromite Plus Manual) in detail - I know, that is a lot of reading but you seem to be stabbing in the dark without knowing what is in the manuals.
- Break your program down into small bits and test and understand each bit before trying the next. For example, just have a NUMBERBOX (nothing else) and experiment with getting its value and doing things with its value. Then try a TEXTBOX, LED, etc. When you know how each works you can put them together and they should do their job without any surprises. Trying for a quick route to the final solution inevitably leads to catastrophe.
Geoff
|
Back to Top |
|
|
macca Newbie

Joined: 21 February 2017 Location: Australia
Online Status: Offline Posts: 32
|
Posted: 14 July 2018 at 12:11am | IP Logged
|
|
|
sorry for this I will read and not bother the forum again. some people have the gift and some don't. regards to you and the rest.
|
Back to Top |
|
|
matherp Guru

Joined: 11 December 2012 Location: United Kingdom
Online Status: Offline Posts: 2636
|
Posted: 14 July 2018 at 4:36am | IP Logged
|
|
|
Quote:
I will read and not bother the forum again |
|
|
Please don't get put off from posting if you need help. However, as Geoff says you are really getting into the most complex area of the Micromite and need a bit more background.
The key thing to understand is there are three datatypes supported by MMBasic
Strings Integers Floating Point numbers
You can combine integers and floats in various expressions but it critical you understand what you are trying to achieve in doing so
Strings and numbers can't be combined but can be converted
VAL converts a string to a number STR$ converts a number to a string
For best programming practice always start your code with
OPTION EXPLICIT OPTION DEFAULT NONE
This will force you to declare and type all your variables and makes errors much less likely (albeit at the expense of a bit more effort up front).
The CTRLVAL function is a special case and can return either a string or a number depending on the GUI control with which it is associated. There is no way round this one for any of us except checking the manual.
Edited by matherp on 14 July 2018 at 4:38am
|
Back to Top |
|
|
Grogster Guru


Joined: 31 December 2012 Location: New Zealand
Online Status: Offline Posts: 6457
|
Posted: 14 July 2018 at 9:27am | IP Logged
|
|
|
macca wrote:
sorry for this I will read and not bother the forum again. some people have the gift and some don't. regards to you and the rest.
|
|
|
Please don't mis-read Geoff's post above. He is just trying a bit of 'tough-love' on you, to try to get you to go to the manuals, as that is what they were written for, and pretty much 99% of all your issues can be solved by reading the manuals. 
You are NOT bothering the forums. As you say, some people can pick this stuff up in one pass, but others have more of an issue understanding the logic of how commands work. That is not anything to be ashamed of.
Keep on tinkering, and posting your codes that DON'T work. Use the CODE HTML tags as Geoff suggested. Click the 'code' button just above this text-entry box, just below the 'Size' drop-down menu thing-y, and paste your code in between the two markers that the forum software will plop there for you. 
I had similar problems when I started using the GUI controls, so you are not the only one to have issues. Most of us have crashed and burned in the beginning as we teach ourselves how to use the GUI controls. 
I know EXACTLY the feeling you are having with your CtrlVal issues. As Geoff and matherp point out, CtrlVal's are a unique beast in MMBASIC, and can be different types, and you simply CAN'T make the assumption that a certain control will be a string or a number. You have to be sure of that FIRST, and then make conversions from one to the other with VAL and STR$ as matherp points out.
Don't despair - we are here to help you, so you keep on doing what you're doing.
__________________ Smoke makes things work. When the smoke gets out, it stops!
|
Back to Top |
|
|
Geoffg Guru


Joined: 06 June 2011 Location: Australia
Online Status: Offline Posts: 2488
|
Posted: 14 July 2018 at 11:32am | IP Logged
|
|
|
Sorry for coming across as critical macca. What I was trying to say is that it was not possible to simply correct your code. The solution to getting your program running was for you to understand data types and the manuals are a good place for that.
Understanding a concept in programming can often be like turning on a light - all of a sudden it is much easier to see and understand. So don't give up.
|
Back to Top |
|
|
Quazee137 Senior Member


Joined: 07 August 2016 Location: United States
Online Status: Offline Posts: 178
|
Posted: 14 July 2018 at 1:41pm | IP Logged
|
|
|
@macca
Please keep learning and then posting here. This has been the best forum
on coding and hardware I have been lucky to have found.
All the members here share and help. As for helping sometimes pointing us
to READ THEN MANUAL is far more helpful than giving a fix we may not
understand. Then when we have better knowledge of MMBasic they give even
more by being the best sounding board for ideas/code/hardware you could want!
My Thanks to all here at TBS
Quazee
|
Back to Top |
|
|
bigmik Guru


Joined: 20 June 2011 Location: Australia
Online Status: Offline Posts: 2142
|
Posted: 14 July 2018 at 2:22pm | IP Logged
|
|
|
Hi Macca,
Don’t despair we are not all good at programming..
God knows I am next to useless. Although I get by generally.
What I do is try small sections of code to see what various commands return..
The best ocean swimmers started by paddling in kiddie pools... you really can’t expect a lengthy piece of code to work straight off ..
Even Geoff and Peter, who are amongst the best, if not the best, at coding are still fixing bugs in code they thought were fine when released..
One problem I personally have is misunderstanding what a command means and every time I proof read my code I assume that a command does what I want (not what I told it to)
Try putting print lines before and after a suspect line to print the relevant variables before the code and again after.. add pauses if needed.. this way you can determine if the section of code returns what you thought it would.
Keep on trying you will get there one day.. it is part of the fun and satisfaction at getting a working project.
Regards,
Mick
|
Back to Top |
|
|
macca Newbie

Joined: 21 February 2017 Location: Australia
Online Status: Offline Posts: 32
|
Posted: 15 July 2018 at 8:05pm | IP Logged
|
|
|
Hi and thankyou to Geoff, Grogster, matherp for your encouraging information and thoughts, I will be printing the manuals out as I find trying to read the manuals of the same computer then switching to MMEdit a bit confusing, and yes you are right in what I should be doing "eg. reading the manuals more". I have not giving up just taking a breather and gathering my thoughts. And yes you guy's are the best.
Best Regards I'll get there John
|
Back to Top |
|
|
CaptainBoing Guru


Joined: 07 September 2016 Location: United Kingdom
Online Status: Offline Posts: 752
|
Posted: 17 July 2018 at 4:47pm | IP Logged
|
|
|
macca wrote:
sorry for this I will read and not bother the forum again. some people have the gift and some don't. regards to you and the rest.
|
|
|
Don't be like that forums are designed to be bothered! You should NEVER feel you are "pestering" in a forum if you are genuinely seeking advancement. Anyone who doesn't want to follow a particular thread knows where the close button is.
Just about the only skills any of us were born with was screaming and swimming(ish). Keep on posting - God knows I went through some curves during my time here on this rock and it is only by "bothering" others of a like mind (it was computer clubs back then... which deteriorated into copy-fests and punch-ups over Amiga Vs Atari sadly) that I got as far as I have. Trust me, it will suddenly "click" into place.
Edited by CaptainBoing on 17 July 2018 at 4:50pm
|
Back to Top |
|
|