PDA

View Full Version : need a Unicode working example



fkapnist
26-11-2018, 16:58
I am new to thinBasic (and programming in general). I need to know how to display a string of foreign characters (such as Greek or Russian) in a simple text field or message box. I have looked through this forum and I found mostly excuses for why thinBasic can't handle Unicode. However "Uzulo" has posted a good working solution. It requires running as "thinbasicc test.txt" to actually work, but that is okay since nothing else on this forum works for Unicode.

https://www.thinbasic.com/community/showthread.php?12698-Does-ThinAir-supports-Unicode&p=93079#post93079

The only problem is that Uzulo complicated his code by adding boxes, colors, and other bells and whistles that confuse a newbie like me. I want to only display a string of foreign characters. Period. I need that snippet of code. What do I extract from Uzulo's code without breaking it? I can only learn from working examples that I may modify. Memorizing code rules or lengthy syntax does not really work for me (or for Rapid Application Development). Thanks.

DirectuX
26-11-2018, 17:33
I need to know how to display a string of foreign characters (such as Greek or Russian) in a simple text field or message box.

Hi fkapnist,
and welcome !

This code works for me :


Dim nButEo = "Ŝanĝiĝu... Ĝis!"
Dim nButRu = "Что ж, закроем!"
Dim nButFa = "!ﺪﯿﻨﻜﺑ ﻪﺘﺴﺑ"
Dim nButKr = "창문을 닫기!"
Dim nButYi = "!ןכאַמוצ רעטצנעפֿ"
Dim nButAr = "Պատուհան փակել"
Dim nButHi = "खिड़की बंद करे ।"
Dim nButJa = "まど を 閉じる。"

MsgBoxW (0,nButEo)
MsgBoxW (0,nButRu)
MsgBoxW (0,nButFa)
MsgBoxW (0,nButKr)
MsgBoxW (0,nButYi)
MsgBoxW (0,nButAr)
MsgBoxW (0,nButHi)
MsgBoxW (0,nButJa)

help page is here : https://www.thinbasic.com/public/products/thinBasic/help/html/msgboxw.htm

fkapnist
26-11-2018, 18:18
Thank you. I am an absolute beginner. When I run the code as it is, I get: " Unknown Keyword MSGBOXW " So I went to the help file you link to and searched for "Keyword." But I got "thinBasic_GetKeywordSpeficic" which I think is a misspelling and it shows nothing but a blank page. In programming it seems that the easiest things are often the hardest, and the hardest are achieved by accident...





Hi fkapnist,
and welcome !

This code works for me :


Dim nButEo = "Ŝanĝiĝu... Ĝis!"
Dim nButRu = "Что ж, закроем!"
Dim nButFa = "!ﺪﯿﻨﻜﺑ ﻪﺘﺴﺑ"
Dim nButKr = "창문을 닫기!"
Dim nButYi = "!ןכאַמוצ רעטצנעפֿ"
Dim nButAr = "Պատուհան փակել"
Dim nButHi = "खिड़की बंद करे ।"
Dim nButJa = "まど を 閉じる。"

MsgBoxW (0,nButEo)
MsgBoxW (0,nButRu)
MsgBoxW (0,nButFa)
MsgBoxW (0,nButKr)
MsgBoxW (0,nButYi)
MsgBoxW (0,nButAr)
MsgBoxW (0,nButHi)
MsgBoxW (0,nButJa)

help page is here : https://www.thinbasic.com/public/products/thinBasic/help/html/msgboxw.htm

fkapnist
26-11-2018, 18:56
To be specific, I want to use this example file:


DIM RetCode AS LONG
DIM tOut1 AS LONG = 10
DIM tOut2 AS LONG = 5
DIM Msg AS STRING

Msg = "Hi everybody." & $crlf & _
"This message will be on screen for " & tOut1 & " seconds." & $CRLF & _
"Your can click on this message or wait for timeout." & $CRLF & _
"Different return codes will be generated for different actions"

RetCode = Alert("thinBasic Alert", Msg, tOut1)

Alert("thinBasic RetCode", "Alert returned " & RetCode, tOut2)

But I want to replace the Latin characters with Greek for example:


DIM RetCode AS LONG
DIM tOut1 AS LONG = 10
DIM tOut2 AS LONG = 5
DIM Msg AS STRING

Msg = "Γειά σου πώς είσαι." & $crlf & _
"This message will be on screen for " & tOut1 & " seconds." & $CRLF & _
"Πιέστε το μενού ή κάντε κλικ στο μήνυμα αυτό." & $CRLF & _
"Different return codes will be generated for different actions"

RetCode = Alert("thinBasic Alert", Msg, tOut1)

Alert("thinBasic RetCode", "Alert returned " & RetCode, tOut2)

What is needed to display the correct language characters?

:confused:

DirectuX
26-11-2018, 19:05
When I run the code as it is, I get: " Unknown Keyword MSGBOXW "

which version of ThinBasic do you use ?
I ran the code with this preview version : https://www.thinbasic.biz/projects/thinbasic/thinBasic_1.10.6.0.zip


I went to the help file you link to and searched for "Keyword."
it is a direct link to the MSGBOXW man page, you don't need to make a search. If you want to search it , search MSGBOXW instead of Keyword
Also thinBasic_GetKeywordSpeficic has a blank page for me too.

DirectuX
26-11-2018, 19:51
What is needed to display the correct language characters?


I don't know other answer than the previous msgboxw





RetCode = Alert("thinBasic Alert", Msg, tOut1)

Alert("thinBasic RetCode", "Alert returned " & RetCode, tOut2)


The Alert keyword (https://www.thinbasic.com/public/products/thinBasic/help/html/alert.htm?zoom_highlightsub=alert) is not described as an utf8-aware function. To the extent of my (weak) knowledge I think it will not do the job as you want. That is maybe why in this post https://www.thinbasic.com/community/showthread.php?12698-Does-ThinAir-supports-Unicode&p=93079#post93079 the script declares windows functions to do this.

DirectuX
26-11-2018, 20:29
I managed to get this

9912

with this code:


'---Script created on 11-26-2018 18:28:52 by
DIM RetCode AS LONG
DIM tOut1 AS LONG = 10
DIM tOut2 AS LONG = 5
DIM Msg AS STRING

Msg = "ĥ꜠󯵠𾲠栳⩮"

Alert("thinBasic Alert", Msg, tOut1)


I think ThinAir saves script file in utf8.
I pre-converted the string to ansi, it's why it displays weird in thinAir. Curiously, in my trying utf8toans$() does not the job.

script file : 9913

fkapnist
27-11-2018, 01:46
I upgraded to version 10.6 of thinBasic. In \SampleScripts\UI\RichEdit\ I found that RichEdit_002.tBasic (TinyWord - RichEdit sample) has full Unicode support with a large selection of fonts. Ui\Sdk\ DIALOG_UNICODE.tbasic will display foreign language characters.


This works in version 10


Dim nButEo = "Ŝanĝiĝu... Ĝis!"
Dim nButRu = "Что ж, закроем!"
Dim nButFa = "!ﺪﯿﻨﻜﺑ ﻪﺘﺴﺑ"
Dim nButKr = "창문을 닫기!"
Dim nButYi = "!ןכאַמוצ רעטצנעפֿ"
Dim nButAr = "Պատուհան փակել"
Dim nButHi = "खिड़की बंद करे ।"
Dim nButJa = "まど を 閉じる。"

MsgBoxW (0,nButEo)
MsgBoxW (0,nButRu)
MsgBoxW (0,nButFa)
MsgBoxW (0,nButKr)
MsgBoxW (0,nButYi)
MsgBoxW (0,nButAr)
MsgBoxW (0,nButHi)
MsgBoxW (0,nButJa)

I tried pre-saving the alert message with ANSI encoding as you did. It worked okay for Greek but Russian came out ????????.... I have Greek installed as a second language in my Windows PC.

DirectuX
27-11-2018, 09:39
It worked okay for Greek but Russian came out ????????.... I have Greek installed as a second language in my Windows PC.
I confirm here all languages printed out ok.
*maybe* (it's a guess of what I would check) :
your default font don't support russian
or
you have to add russian in control panel \ languages
or
you have to select russian in control panel \ region \ administration


RichEdit_002.tBasic (TinyWord - RichEdit sample) has full Unicode support with a large selection of fonts. Ui\Sdk\ DIALOG_UNICODE.tbasic will display foreign language characters.
Nice, you've got you solution !?