BUG on specials characters.

zouriteman

Member
Licensed User
Longtime User
I use basic4A last version 1.70
With this code :
sub MYFUNCT(WSTR as String , CCHAR as char)
.... some code ....
If CCHAR = ">" Then
.... some code ...
end if

I have a compilation error :
Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 109
If CCHAR = ">" Then
Word: >

If I replace ">" with " " , it compile OK !

Also, when I read a text file created with Windows Notepad , and lines contains spécial Ascii caracters as "§" , ">" , after reading by File.readList() , these char are replaced by a symbol (a question mark inside a square)
WHY ?

Coming from Turbo-Pascal + Delphi , it is a frequent error to write 'some string' , at place of "some string" : this is detected by the compiler ;
but writing
dim MY_VAR_STRING as String
.... some code ....
MY_VAR_STRING = MY_VAR_STRING + "ABC"
is not détected at compiler time , only at run time with an eror : java.lang.NumberFormatException ;
 
Last edited:

agraham

Expert
Licensed User
Longtime User
This looks like a previous bug that Erel has not quite fixed. Reverse the order of the operands and it should work.
B4X:
If ">" = CCHAR  Then 
    .... some code ...
end if

The funny characters are a UTF8 Byte Order Mark. Either save the file in Notepad as ASCII or if you need accented or other non-ASCII characters download Notepad++ and use that or any other editor that doesn't write a BOM for UTF8.
 

Kevin

Well-Known Member
Licensed User
Longtime User
Coming from Turbo-Pascal + Delphi , it is a frequent error to write 'some string' , at place of "some string" : this is detected by the compiler ;
but writing
dim MY_VAR_STRING as String
.... some code ....
MY_VAR_STRING = MY_VAR_STRING + "ABC"
is not détected at compiler time , only at run time with an eror : java.lang.NumberFormatException ;


I think agraham missed your last one.....

Assuming your problem is not related to using numbers as the value of MY_VAR_STRING, try the following instead:

MY_VAR_STRING = MY_VAR_STRING & "ABC"
 

Kevin

Well-Known Member
Licensed User
Longtime User
No, he edited it in later after I replied which is a "bad thing to do" because while new posts are flagged by sending an email to contributors to the thread edits are not so may be overlooked.

Sorry, I didn't notice the edit. I have much respect for you and your contributions to B4A and wasn't trying to be rude, just trying to help with his last question.

I can't tell if you took offense or not but I apologize if you did. :)
 

zouriteman

Member
Licensed User
Longtime User
THANK YOU AGRAHAM , you are right :

*** this give compiler error ***
If CCHAR = ">" Then
Word: >

*** this compile good ***
if ">" = CCHAR then
 

zouriteman

Member
Licensed User
Longtime User
I think agraham missed your last one.....

Assuming your problem is not related to using numbers as the value of MY_VAR_STRING, try the following instead:

MY_VAR_STRING = MY_VAR_STRING & "ABC"

YES I know that the concatenation operand in Basic4 is & , but my post is for the problem : WHY the compiler does not trap the error ?
The compile say that MY_VAR_STRINg is a string (because Dim) and "ABC" is a string , and these two operands cannot add this together with + sign.
 

agraham

Expert
Licensed User
Longtime User
Basic4android, although it supports strong typing, will also do type coercion for you. If you use an arithmetic operator and the operands do not represent a valid number a runtime error occurs.
B4X:
Dim s As String
s ="4" + "5" ' result "9" coerced to numbers because + is arithmetic operator
s = "4" & "5" ' result "45" concatenated because & is string operator
 
Top