[Gambas-user] Function Len in gambas2

Simonart Dominique simonart.dominique at ...11...
Wed Apr 1 23:50:15 CEST 2009


vlahonick vlahonick a écrit :
> 
> hi again...sorry about the delay in my reply :D
> but i really didnt understand ur example here....
> of course now i realise that even the textbox2.text had the reasult i wanted the problem will
> be in the letters appering because of their bytes...
> but the main problem is not solved yet....
> still in the textbox2.text appears what i am writing in the textbox1.text and not what i want...
> and abou the example u gave me with if then else end if is a bad idea because if for example we want to
> converter a word i have to put many boxes and the user to write a letter in every box to have in that many other boxes a result....
> (anyway i tried this but just didnt work...)
> so plz if u can tell me how i can make with two boxes every character i wrote in the first box to appear what i want in the second box....
> what i wrote wrong???why at the 2nd box appears what i am writing in the 1st box???
> plz solve this and then if this problem is solved but in the second or first textbox the charactes doesnt appears in the way the should i will try to set somehow that they are UTF-8 characters so they have more bytes...
> ty again for ur replies :D:D:D
> 
> vlahonick...LOVE AND GREETINGS FROM GREECE :D
> also u can see some of my work in the www.vlahonick.freehost.gr (of course u dont gonna understand many because site is in greek but u can try download my games->www.vlahonick.freehost.gr/downloads.html and press Παιχνίδια=games)
> 
> here my code for one more time :
> 
> ' Gambas class file
> 
> PUBLIC SUB _new()
> 
> END
> 
> PUBLIC SUB Form_Open()
> 
> END
> 
> PUBLIC SUB Button1_Click()
> DIM nI AS Integer
> DIM sAnyChar AS String
> TextBox2.text = ""
>    FOR nI = 1 TO Len(TextBox1.Text)
>       sAnyChar = Mid(TextBox1.Text, nI, 1)
>       TextBox2.Text = TextBox2.Text & Gronverter(sAnyChar)
>    NEXT 
> END
> 
> FUNCTION Gronverter(sInChar AS String) AS String
> DIM sRetChar AS String = sInChar
> 
> IF sInChar = "α" THEN sRetChar = "a"
> IF sInChar = "β" THEN sRetChar = "v"
> IF sInChar = "γ" THEN sRetChar = "g"
> IF sInChar = "δ" THEN sRetChar = "d"
> IF sInChar = "ε" THEN sRetChar = "e"
> IF sInChar = "ζ" THEN sRetChar = "z"
> IF sInChar = "η" THEN sRetChar = "ι"
> IF sInChar = "θ" THEN sRetChar = "th"
> IF sInChar = "ι" THEN sRetChar = "i"
> IF sInChar = "κ" THEN sRetChar = "k"
> IF sInChar = "λ" THEN sRetChar = "l"
> IF sInChar = "μ" THEN sRetChar = "m"
> IF sInChar = "ν" THEN sRetChar = "n"
> IF sInChar = "ξ" THEN sRetChar = "x"
> IF sInChar = "ο" THEN sRetChar = "o"
> IF sInChar = "π" THEN sRetChar = "p"
> IF sInChar = "ρ" THEN sRetChar = "r"
> IF sInChar = "σ" THEN sRetChar = "s"
> IF sInChar = "τ" THEN sRetChar = "t"
> IF sInChar = "υ" THEN sRetChar = "i"
> IF sInChar = "φ" THEN sRetChar = "f"
> IF sInChar = "χ" THEN sRetChar = "h"
> IF sInChar = "ψ" THEN sRetChar = "ps"
> IF sInChar = "ω" THEN sRetChar = "o"
> RETURN sRetChar
> 
> END
> 
> PUBLIC SUB Button2_Click()
> 
>   TextBox1.text = ""
>   TextBox2.text = ""
> END
> 
>>

Hi,

You have to use the String class because each greek 
character is 2 bytes long.
Change the SUB Button1_Click() as below and all will be 
fine! (I've tested it)

PUBLIC SUB Button1_Click()
DIM nI AS Integer
DIM sAnyChar AS String
TextBox2.text = ""
    FOR nI = 1 TO String.Len(TextBox1.Text)
       sAnyChar = String.Mid(TextBox1.Text, nI, 1)
       TextBox2.Text = TextBox2.Text & Gronverter(sAnyChar)
    NEXT
END





More information about the User mailing list