PDA

View Full Version : Can not get my IF THEN statement to work



Rhatidbwoy
- 29th October 2005, 23:20
I am trying to check values within the ram and all that I am getting is a continuous count. Is there something that I am doing wrong or what could be a reason for the problem that I am having.



VARINC:
B7 = B7 + 1
goto check

VARDEC:
B7 = B7 - 1
goto check

CHECK:
if B6 = $31 and B7 < $35 then twenf '25
twenf:
poke B6,$32: poke B7,$35

if B6 = $32 and B7 > $35 then fift '15
fift:
poke B6,$31: poke B7,$35

if B6 = $32 and B7 < $30 then nint '19
nint:
poke B6,$31: poke B7,$39

if B6 = $31 and B7 >$39 then twent '20
twent:
poke B6,$32: poke B7,$30

goto cs

arniepj
- 31st October 2005, 12:12
If your code is as shown,the if statements mean nothing as each line after the if statement is scanned during each run cycle.The if statement label code needs to be located else where in the program so as it is scanned only when the if is true.

Rhatidbwoy
- 31st October 2005, 14:18
meaning the line to follow the if then statement needs to be else were to make the statement do what it is suppose to do. Ok that makes a little sense when thinking about it. I tried pulling the line labels that would make the statement true elsewhere in my program and same results. it looks something like this:

CHECK:
if B6 = $31 and B7 < $35 then twenf '25
if B6 = $32 and B7 > $35 then fift '15
if B6 = $32 and B7 < $30 then nint '19
if B6 = $31 and B7 >$39 then twent '20
goto cs

twenf:
poke B6,$32: poke B7,$35:goto cs

fift:
poke B6,$31: poke B7,$35:goto cs

nint:
poke B6,$31: poke B7,$39:goto cs

twent:
poke B6,$32: poke B7,$30:goto cs

this make sense to having the if then statement work rather than the other one, but I still get no response to how I think that the the if then statement should work. I am still falling out of my limits when i do the scrolling of me wanted value of 15 to 20.

P.S. the whole program is attached

arniepj
- 31st October 2005, 16:46
if B6 = $31 and B7 < $35 then
poke B6,$32: poke B7,$35
endif
if B6 = $32 and B7 > $35 then
poke B6,$31: poke B7,$35
endif
if B6 = $32 and B7 < $30 then
poke B6,$31: poke B7,$39
endif
if B6 = $31 and B7 >$39 then
poke B6,$32: poke B7,$30
endif
goto cs

bartman
- 31st October 2005, 21:06
If you really are using PicBasic and NOT PicBasic Pro then any ENDIF and ELSE statements won't work for you. Keep that in mind when writing your program. You need to work around that. Some of the solutions presented won't work "as is" for that reason.

Rhatidbwoy has the right idea in his example.

Bart

AMay
- 7th November 2005, 20:14
I have never been able to get an "If - Then" command to work using more that one condition in PIC Basic. That is no A and B. Only A, then another question.

If I want to test a as 10 plus b at 20 for calling x:
loop:
if a = 10 then isb
loopb:

isb:
if b = 20 then x
goto loopb

bartman
- 8th November 2005, 02:34
AND and OR are valid PicBasic commands used with IF/THEN and the proper syntax is "IF A=1 AND B=2 THEN" so if your's aren't working I don't think that is the reason. I'm just not good enough at reading other people's code to sort out the why.

Sorry.

Bart

Kamikaze47
- 21st November 2005, 16:45
shouldnt the line "if B6 = $31 and B7 < $35 then twenf" read:

if B6 = $31 and B7 < $35 then GOTO twenf ?

or is the GOTO not required when using an if statement?

dw_pic
- 2nd February 2006, 17:09
To my knowledge, "with picbasic, not pro"

The picbasic compiler will see the added "goto" as a undeclared symbol and choke on it.

the action is a goto, but the syntax is

if X = true then label

dw

Rhatidbwoy
- 2nd February 2006, 17:27
The problem that I have with the statement is that when it is executed to the goto from the IF...THEN I used poke. When writing to a VAR I do not need the poke, but when I need to write to a address on the chip, per-say, that is when I would use the poke or peek. Example: POKE $86,0 for writing to the chip ;

(NOT CORRECT)
twenf:
poke B6,$32: poke B7,$35:goto cs

(CORRECT)
twenf:
B6 = $32 : B7 = $35 : goto cs

OR

twenf:
B6 = $32
B7 = $35
goto cs