Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:55 24 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 : (DM-MM) fun with the IF statement

Author Message
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 1344
Posted: 07:47am 24 Nov 2011
Copy link to clipboard 
Print this post

G'day Guy's,
For a few days I have really been trying to get around this problem, it is probably an easy one for the more experienced Basic programmers but with my brain fresh with Oshonsoft basic I am having a bit of trouble getting this thing to work.

Ok now with having lines 290 to 310 in the query$ WILL come up the variable I typed in BUT take those lines out and no matter what I type in it will always go the bottom one.
This has got my mind boggling and those 3 lines of code are my crude ways at trying to debug the code. I have tried using the READ DATA commands but I reckon no matter what I try I'm getting every error in the book.

270 INPUT " Type in the Command"; query$
280 '--------------------------------------------------------
290 CLS
300 PRINT TAB(4); query$
310 END
330 IF query$ = "complete" THEN GOTO 3000
340 IF query$ = "auto" THEN GOTO 4000
350 IF query$ = "chdir" THEN GOTO 7000
360 IF query$ = "circle" THEN GOTO 8000

as you guy's will probably see my first project on the DM is making up a help file. I will be putting the code out as it will be open source and hopefully over time with help we will have a help file with example code that everyone can use.

So if you can help me get over this IF/Then hurdle I'll be well on the way to getting somewhere with this project.

Regards Bryan

Edited by Bryan1 2011-11-25
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 08:35am 24 Nov 2011
Copy link to clipboard 
Print this post

I don't have my MM with me at the moment, so I can't test it, but the code looks reasonable.

Are you entering the command in exactly the same case that you are testing?
Ie, are you entering something that isn't all lower case, like Chdir or CHDIR in response to line 270?

Good coding practice would be to take the user input and convert it to all lower (or upper) case.
270 INPUT "Type in the command "; query$
275 query$ = lcase$(query$)

I don't have the manual here either, but the function is lcase() or lcase$() - probably the second.

Standardising the case of the input means you only need one IF statement for each command (as you already have).

This may not fix your IF query, but it will make the program easier to use and debug.

James

Another thought: I see that the 'last line' that it always executes is the highest value line listed.
If the user enters 'chdir', the code branches to line 7000. Is there a GOTO statement before line 8000 to stop the code falling through to line 8000?

Edited by James_From_Canb 2011-11-25
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 09:17am 24 Nov 2011
Copy link to clipboard 
Print this post

  Bryan1 said   G'day Guy's,
For a few days I have really been trying to get around this problem, it is probably an easy one for the more experienced Basic programmers but with my brain fresh with Oshonsoft basic I am having a bit of trouble getting this thing to work.




Try this one Bryan.

Works for me



270 INPUT " Type in the Command"; query$
280 '--------------------------------------------------------
290 CLS
300 PRINT TAB(4); query$
310 PAUSE 1000
330 IF query$ = "complete" THEN GOTO 3000
340 IF query$ = "auto" THEN GOTO 4000
350 IF query$ = "chdir" THEN GOTO 7000
360 IF query$ = "circle" THEN GOTO 8000
400 PRINT "incorrect entry"
410 END
3000 PRINT"Found complete":END
4000 PRINT"Found auto":END
7000 PRINT"Found chdir":END
8000 PRINT"Found circle":END



If the input doesnt match it prints INCORRECT ENTRY if it matches it prints FOUND xxxx (whatever it matched)

Regards,

Mick

Edited by bigmik 2011-11-25
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 1344
Posted: 10:46am 24 Nov 2011
Copy link to clipboard 
Print this post

Hi James,
With your edit I think you hit the nail on the head mate, it was as I didn't have any routine to stop the code going thru was the problem after all.

Thanks very much for that James

Note to Mick : also thanks mate and don't worry too much about that code I sent as it's all sorted.

Cheers Bryan

One happy chappy about to crack one of these.......





 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 11:48am 24 Nov 2011
Copy link to clipboard 
Print this post

Hey Bryan, that looks like a homebrew. Nice!
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 04:31pm 24 Nov 2011
Copy link to clipboard 
Print this post

Bryan,

A couple of thoughts about your program:

You should convert the user input to lower case using the lcase$() function.

If a user wants to look up Help while writing a program - for instance comparing the PRINT and WRITE commands, the user would have to RUN "help.bas" which would clear the current program out of memory.

Again, I'm stuck without my MM Basic manual, so this option may not exist. However, if there is an option to start a program from a particular line (ie RUN 1000), then you could renumber your Help program to start from, say, line 60,000. Then anyone who wanted to use the Help program could merge it into their own code and just type RUN 60000 to kick it off. When the program was completed, the merge statement could be removed.

The advantage is that the code under development would be retained in memory.

James
(stuck in a hospital with an iPad but no MM or development laptop, chock full of drugs that stop me sleeping)
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 1344
Posted: 08:23pm 24 Nov 2011
Copy link to clipboard 
Print this post

Hi James,
One might say I have been reading the V2.7 manual so much it's close to being in my memory.

Now in Storage Commands and Functions

An SD card can have up to 10 files simultaneously open
while the internal flash drive has a maximum of one file open at a time.

So as the help file will be on the SDcard I can't see any problem accessing it while another program is open. anyway as I go alomg and learn more I'll hopefully get around that issue.

Anyway mate hope you have a speedy recovery there and keep that chin up.

Regards Bryan

 
Print this page


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

© JAQ Software 2024