[Gambas-user] (no subject)
Doriano Blengino
doriano.blengino at ...1909...
Wed Apr 1 19:34:11 CEST 2009
Charlie Reinl ha scritto:
>
>>> first: tell us what version of Gambas you are using.
>>> second: am I right, you are writing a kind of CONVERTER ?
>>>
>>> if so this is what I would write quickly.
>>>
>>> FUNCTION myConvert(sInChar AS String) AS String
>>> DIM sRetChar AS String = sInChar ' makes the return value to the given
>>> value
>>> ' now make you changes
>>> IF sInChar = "a" THEN sRetChar = "0"
>>> IF sInChar = "b" THEN sRetChar = "1"
>>> IF sInChar = "c" THEN sRetChar = "2"
>>> IF sInChar = "d" THEN sRetChar = "3"
>>> IF sInChar = "e" THEN sRetChar = "4"
>>> IF sInChar = "f" THEN sRetChar = "5"
>>> IF sInChar = "g" THEN sRetChar = "6"
>>> IF sInChar = "h" THEN sRetChar = "7"
>>> IF sInChar = "i" THEN sRetChar = "8"
>>> IF sInChar = "j" THEN sRetChar = "9"
>>> IF sInChar = "0" THEN sRetChar = "a"
>>> IF sInChar = "1" THEN sRetChar = "b"
>>> IF sInChar = "2" THEN sRetChar = "c"
>>> IF sInChar = "3" THEN sRetChar = "d"
>>> IF sInChar = "4" THEN sRetChar = "e"
>>> IF sInChar = "5" THEN sRetChar = "f"
>>> IF sInChar = "6" THEN sRetChar = "g"
>>> IF sInChar = "7" THEN sRetChar = "h"
>>> IF sInChar = "8" THEN sRetChar = "i"
>>> IF sInChar = "9" THEN sRetChar = "j"
>>> RETURN sRetChar
>>> END
>>>
One could also write a single long string, with couples of chars.
Borrowing from the code above:
sConvert = "?a0b1c2 d3e4f5g6 h7....."
note the spaces in the middle. A routine then can do:
pos=instr(sConvert, sInChar)
return mid(sConvert, pos+1,1) ' if pos=0, then the first character
is returned...
This is faster to write... and perhaps easier to read/mantain. Of
course, it works only for single characters; but variations on this
theme could let it work for other kind of translations.
Regards,
Doriano
More information about the User
mailing list