Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:17 01 Aug 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 : Unexpected Text

     Page 1 of 2    
Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 12:51am 27 May 2019
Copy link to clipboard 
Print this post

I am trying to make a small change to some code and have this error
[34] Else Rain = Cint(Rain)
Error: Unexpected text: Rain Æ ‡Rain)

I was using GFX term so I tried MMEdit with the same result
does anyone know what is causing this?

edit...I even tried using a different computer to do the edit and got the same error.Edited by palcal 2019-05-28
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 02:28am 27 May 2019
Copy link to clipboard 
Print this post

Hi.

Without seeing the rest of the code, it would appear that it does not like the text after the ELSE command. The text displayed in the message looks like the "tokenised" version of "Rain = Cint(Rain)".

Have you got the formatting for the IF THEN ELSE correct? (Hard to tell without a bit more code visible - or what the before and after code looks like )

Regards

Gerard (vk3cg/vk3grs)
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 03:02am 27 May 2019
Copy link to clipboard 
Print this post

What I am trying to do is, if the rain value is less that 10 print to 1 decimal place else no decimal place.
A larger snippet of code
If Rain < 10 Then
Rain = Cint(Rain*10)/10
Else Rain = Cint(Rain)
EndIf
R$=Str$(rain,3)

This fails with the error, the coding is also wrongly formatted Str$(Rain,3) would
not give the decimal place
So I changed the way I did things to this
If Rain <10 Then
R$ = Str$(Rain,1,1)
Else R$ = Str$(Rain,3)
EndIf

This also fails with this error
[34] Else R$ = Str$(rain,3)
Error: Unexpected text: R$ Æ ¤rain,3)
Edited by palcal 2019-05-28
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 03:11am 27 May 2019
Copy link to clipboard 
Print this post

OK I have it working
I changed the code so that ELSE is on a separate line.
I thought it was OK to have
Else R$ = Str$(Rain,3)

all on one line.
I now have
Else
R$ = Str$(Rain,3)

and it works OK

"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 03:19am 27 May 2019
Copy link to clipboard 
Print this post

G'Day palcal

It's nice to see someone else tripping over the IF THEN ELSE MAYBE thing.
I have been using BASIC in various forms for many years and I still get it wrong. I think the rules keep changing.

Peter
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 03:32am 27 May 2019
Copy link to clipboard 
Print this post

Yes, the ELSE needs to be on a line of its own. I'm a little late to this thread, so you have it sorted now, but the interpreter does not seem to really like having commands after the ELSE keyword. I also had this problem, but ever since I have put the ELSE on its own line, I have never had that problem again.
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 03:50am 27 May 2019
Copy link to clipboard 
Print this post

Thanks to all.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 04:11am 27 May 2019
Copy link to clipboard 
Print this post

If you want to have the code on the same line as the IF THEN ELSE, the following format will also work (note: there is no ENDIF).

If Rain < 10 Then R$ = Str$(Rain,1,1) Else R$ = Str$(Rain,3)


Regards

Gerard (vk3cg/vk3grs)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 04:31am 27 May 2019
Copy link to clipboard 
Print this post

You could also do a single line by using a :
Else : R$ = Str$(Rain,3)

That is a method I often use when I have a lot of elseif's and simple code following.

Jim
VK7JH
MMedit
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 05:56am 27 May 2019
Copy link to clipboard 
Print this post

OK thanks.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 11:32am 27 May 2019
Copy link to clipboard 
Print this post

  palcal said   I am trying to make a small change to some code and have this error
[34] Else Rain = Cint(Rain)
Error: Unexpected text: Rain Æ ‡Rain)


There is
ELSEIF
or
ELSE IF
Geoff Graham - http://geoffg.net
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 12:19am 28 May 2019
Copy link to clipboard 
Print this post

Good morning

Since we are admitting confusion about IF etc, something like this had me wacked a few weeks ago. I eventually gave up with the excuse that it was too slow for what I wanted but it still bugs me.

A = 2
B = 22

If A = B Then GoTo X
Else
Print "NOT EQUAL"
End If
GoTo OUT

X: Print "EQUAL"


OUT:

It does not print NOT EQUAL
If I change B to 2 it prints EQUAL

I know, "WHEN ALL ELSE FAILS, TRY READING THE INSTRUCTIONS"
BUT I DID.

Peter
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 01:51am 28 May 2019
Copy link to clipboard 
Print this post

Hi Peter,

The manual says about your IF statement: 'This type of IF statement is all on one line'

I would have expected then that the ELSE statement would have thrown an error? I'll Try it out later when I can.

Bill
Keep safe. Live long and prosper.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 03:32am 28 May 2019
Copy link to clipboard 
Print this post

I ran the program and got the same result as you. The lines following the IF statement are not being executed when the IF condition is not true.

The manual also says:

  Quote  The ‘THEN statement’ construct can be also replaced with:
GOTO linenumber | label’.


So I expect that it should be either: THEN or GOTO and having both might confuse the interpreter so I removed the THEN from the statement:

  Quote  If A = B GoTo X


and got the same result. It does not seem to be working as I expected. This may be a question for Geoff.

This version works as expected:

  Quote  A = 2
B =
22

IF A = B THEN
PRINT "EQUAL"
ELSE
PRINT "NOT EQUAL"
END IF


OUT:



Bill
Keep safe. Live long and prosper.
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 04:03am 28 May 2019
Copy link to clipboard 
Print this post

Hi.

If the IF command has an expression following the THEN then it is considered to be an IF statement with all parts on the same line.

As you have a GOTO following the THEN (or just a GOTO without the THEN), this is considered a one line IF statement. The ELSE on the following line will tried to be matched to a preceding IF - but as it cannot find a match it just ignores the statements from the ELSE to the ENDIF.

Some options for writing the statement:

A = 2
B = 22

If A = B Then GoTo X Else Print "NOT EQUAL"
GoTo OUT

X: Print "EQUAL"

OUT:


A = 2
B = 22

If A = B Then
GoTo X
Else
Print "NOT EQUAL"
Endif
GoTo OUT

X: Print "EQUAL"

OUT:
Edited by seco61 2019-05-29

Regards

Gerard (vk3cg/vk3grs)
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 04:14am 28 May 2019
Copy link to clipboard 
Print this post

Hi seco61,

Yes, as above, the IF statement is considered as a single line statement but as you say the ELSE on the following line will be tried to be matched to a preceding IF.

As there isn't one, wouldn't you expect it to throw an error rather that ignore the following lines?

I would still expect:

IF A = B GOTO X

to work.

Bill
Keep safe. Live long and prosper.
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 04:27am 28 May 2019
Copy link to clipboard 
Print this post

G'Day seco61 & Bill

Your second example looks a lot like mine except GOTO has been moved down.
The manual says the THEN statement can be replaced by GOTO????
My code is only meant to display the problem. The actual code was full of IFs etc.
But it does seem to have demonstrated some confusion about this area.

Peter
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 04:46am 28 May 2019
Copy link to clipboard 
Print this post

Hi Peter and Bill.

My understanding is that "IF expr GOTO label" is also considered a one line IF statement, hence the same behaviour.

As regards reporting an error, it is a LONG time since I actually looked at the interpreter code, but I know being able to report this as an error could be quite difficult when you consider the sequential nature of the interpreter and the ability for code to be GOTO'd etc...



Regards

Gerard (vk3cg/vk3grs)
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 04:55am 28 May 2019
Copy link to clipboard 
Print this post

To me it reads as a multiline IF statement. The only complication is the GOTO but since it is not working, my interpretation is a bit sus.

Thank heavens for Cab. Sav.

Peter
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 12:21am 29 May 2019
Copy link to clipboard 
Print this post

Good morning sec061 & Bill

I bet you thought I had gone away
Your second bit runs but when equal it runs once and when not equal runs continuously.
Why am I not surprised?
I got out my David I Schneider Handbook of BASIC 1988. It only confuses me.
I am plucking up the courage to insert a GOSUB / RETURN just for fun.

Peter
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025