PDA

View Full Version : unwanted type conversion


Heinz
02-13-2007, 04:03 PM
I have a problem with a unwanted type conversion in the following case:

string$="Test 111";
c$="";
c$=c$+chr(string$[6]); // c$="1"
c$=c$+chr(string$[7]); // c$=2 and not "11" !
c$=c$+chr(string$[8]); // c$=3 and not "111"

The example above is a bit simplified part of a parser and what I would like to do is copy the numbers digit by digit into the string c$. The first digit works fine and according to the watch window the variable type is character as it should be however when he should append the second "1" he suddenly converts both character variables into integer variables and adds them together :((
Any ideas why the variables are converted respectively how I could avoid the conversion in this case?

kornalius
02-13-2007, 04:37 PM
You need to use the % operator instead of the + operator. The + operator will convert a string to integer value if possible. The % won't, it will treat all values as strings and concatenate them together.</p>

c$ = c$ % chr(string$[6]);</p>

Heinz
02-14-2007, 07:39 AM
Works perfectly! Thanks a lot!