Login
Back to forumReply to this topicGo to last reply

Posted By

SVS
on 2004-01-12
11:25:18
 Another BASIC bug found ;)

Hello,
this week I bore you with the following bug, just found during coding...

A$="PLUS4": MID$(A$,3,2)=CHR$(65)+CHRS$(66)

The result is: "PLAS4" instead of "PLAB4" that is the second CHRS$() is lost. Any idea?

Posted By

TPSH
on 2004-01-16
07:12:23
 Re: Another BASIC bug found ;)

B$=CHR$(65)+CHRS$(66)
A$="PLUS4": MID$(A$,3,2)=B$

happy

Posted By

TPSH
on 2004-01-16
07:18:42
 Re: Another BASIC bug found ;)

or A$="PLUS4": MID$(A$,3,2)=(CHR$(65)+CHR$(66))

Posted By

TPSH
on 2004-01-16
07:22:25
 Re: Another BASIC bug found ;)

tehát maradjun annyiban,hogy ez nem basic hiba hanem SYNTAX ERROR !!! happy

Posted By

TPSH
on 2004-01-16
07:34:45
 Re: Another BASIC bug found ;)

jol van tudom,kihagytam egy K betűt...

Posted By

SVS
on 2004-01-16
08:18:16
 Re: Another BASIC bug found ;)

Many thanks TPSH!
But why we have to put (CHR$(65)+CHR$(66)) between round parenthesis?

Posted By

TPSH
on 2004-01-16
10:35:57
 Re: Another BASIC bug found ;)

valaki segíthetne,mert még mindíg nem tudok angolúl!!!

Posted By

Litwr
on 2004-01-27
05:13:20
 Re: Another BASIC bug found ;)

I think that this assignment is not true assignment. E.g., you can't use LET here. MID$(,,)= is ONE operator (i.e. = sign is part of it).

Posted By

SVS
on 2004-01-27
08:07:37
 Re: Another BASIC bug found ;)

Litwr: you should be right!
A good explaination that could explain the needed parenthesis in DIRECTORY (A$) too.
Thank you.

Posted By

JamesC
on 2004-03-21
22:06:34
 Re: Another BASIC bug found ;)

I wondered why SVS was doing this, when I read his post over two months ago. Tonight I refreshed my memory of going through old Transactor magazine archives and found this bit of information: Transactor link

What SVS was attempting to do was insert two characters into a string, with those characters overwriting two other characters inside the string. If he tried a simple character it worked, but two or more did not without parenthesis or combining the characters (as shown by TPSH above).

The REASON it doesn't work the way SVS wished, is simple but not thought of. Commodore BASIC solves equations in a left-to-right fashion after the statement has been broken down to its lowest form (after parenthesis, multiplication and division, etc). The statement SVS wished to use was seen by BASIC as A$="PLUS4": MID$(A$,3,2)=CHR$(65), with the remainder discarded by BASIC because BASIC thinks that the equation has already been solved. BASIC is working in a straight left-to-right manner, as noted in the owner's manual for solving equations.

In other words, the characters on the right side of the = sign have to be "solved" before the MID$ can use them to complete the statement on the left side.

I realize that high-level programmers like Csabo probably realized this when the thread was started, but it has been bugging me for months now, and I wanted to say that I finally figured it out. happy

Posted By

SVS
on 2004-03-22
02:33:28
 Re: Another BASIC bug found ;)

Thank you James.

Posted By

MC
on 2004-03-22
04:29:26
 Re: Another BASIC bug found ;)

Just another SVS bug wink



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon