422,767 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,767 IT Pros & Developers. It's quick & easy.

passing a string in Cyrillic

PhilOfWalton
Expert 100+
P: 1,117
I have a Russian word близко (close) and I want to check that the word is indeed in Cyrillic script

Now I know that the Unicode range for Cyrillic is 0400 to 04FF and the Cyrillic supplementary is from 0500 to 052F

In windows I have added Russian as a language pack, and in Access changed the editor format to Arial (Cyrillic)

I can copy the Cyrillic word into my table OK.

If I try to pass the word so a function to try to attempt some verification, the word appears as ??????. and obviously I can do nothing with it.

Any ideas how to pass words in non Latin languages

Thanks

Phil
Sep 13 '17 #1

✓ answered by Rabbit

Hmm, interesting. You have to use StrConv to convert it to Unicode first.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.     Dim str As String, i As Integer
  3.     str = StrConv(DLookup("Field1", "Table2"), vbUnicode)
  4.     For i = 1 To Len(str) Step 2
  5.         Debug.Print Right("0" & Hex(Asc(Mid(str, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(str, i, 1))), 2)
  6.     Next
  7. End Sub
Which prints this when run against the string you supplied above.
Expand|Select|Wrap|Line Numbers
  1. 0431
  2. 043B
  3. 0438
  4. 0437
  5. 043A
  6. 043E

Share this Question
Share on Google+
6 Replies


Rabbit
Expert Mod 10K+
P: 12,204
Hmm, interesting. You have to use StrConv to convert it to Unicode first.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.     Dim str As String, i As Integer
  3.     str = StrConv(DLookup("Field1", "Table2"), vbUnicode)
  4.     For i = 1 To Len(str) Step 2
  5.         Debug.Print Right("0" & Hex(Asc(Mid(str, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(str, i, 1))), 2)
  6.     Next
  7. End Sub
Which prints this when run against the string you supplied above.
Expand|Select|Wrap|Line Numbers
  1. 0431
  2. 043B
  3. 0438
  4. 0437
  5. 043A
  6. 043E
Sep 13 '17 #2

PhilOfWalton
Expert 100+
P: 1,117
Thank a lot Rabbit, we're there!

Slight change of code, but I am passing this back in case you're interested

I have a table of languages that holds the Unicode language range which I pass to the function:
Expand|Select|Wrap|Line Numbers
  1. Function CheckLanguageOK(Word As String, LanguageLegalFrom As Long, LanguageLegalTo As Long) As Boolean
  2.  
  3.     Dim UnicodeChar As String
  4.     Dim UnicodeValue As Long
  5.     Dim i As Integer
  6.     Dim TestWord As String
  7.  
  8.     If LanguageLegalFrom = 0 Or LanguageLegalTo = 0 Then     ' Language not foun
  9.         Exit Function
  10.     End If
  11.  
  12.     TestWord = StrConv(Word, vbUnicode)
  13.     CheckLanguageOK = -1
  14.  
  15.     For i = 1 To Len(TestWord) Step 2
  16.         UnicodeChar = Right("0" & Hex(Asc(Mid(TestWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TestWord, i, 1))), 2)
  17.         UnicodeValue = Val(UnicodeChar)
  18.  
  19.         If ChangeHexToDecimal("&h" & UnicodeChar) < Val(LanguageLegalFrom) Or ChangeHexToDecimal("&h" & UnicodeChar) > Val(LanguageLegalTo) Then
  20.             CheckLanguageOK = 0
  21.             Exit For
  22.         End If
  23.     Next i
  24.  
  25. End Function
  26.  
Works perfectly

Thanks again
Sep 13 '17 #3

PhilOfWalton
Expert 100+
P: 1,117
Sorry, a supplementary question.
I have the following series of bytes, those beginning with 04 are Cyrillic, and those beginning with 00 are English.

Expand|Select|Wrap|Line Numbers
  1. 0435
  2. 0020
  3. 0434
  4. 0430
  5. 043D
  6. 043D
  7. 044B
  8. 0435
  9. 003C
  10. 002F
  11. 0073
  12. 0070
  13. 0061
  14. 006E
  15.  
At some point I need to strip the English stuff off and just leave the Cyrillic.
How do I convert those numbers to Unicode so that they can be read as a word?

Again thanks

Phil
Sep 14 '17 #4

PhilOfWalton
Expert 100+
P: 1,117
Not to worry. Problem solved

Phil
Sep 14 '17 #5

Rabbit
Expert Mod 10K+
P: 12,204
Cool, just curious, what did you have to do to get it back into the table?
Sep 14 '17 #6

PhilOfWalton
Expert 100+
P: 1,117
Hi Rabbit

The guts of the solution is below

The first bit of code is abbreviated but essentially it is translating an Input string to an Output String using say German as the input language an French as the output language

The translation line would look like this
Expand|Select|Wrap|Line Numbers
  1. IE.Navigate "http://translate.google.com/#" & "de" & "/" & "fr" & "/" & "Cat"
  2.  
Here is part of the code
Expand|Select|Wrap|Line Numbers
  1.  Translate2_Start:
  2.     Set IE = CreateObject("InternetExplorer.Application")
  3.     IE.Visible = 0
  4.  
  5.     ' TO CHOOSE INPUT LANGUAGE
  6.     If Nz(InLanguage) = "" Then
  7.         InLanguage = "auto"
  8.     End If
  9.  
  10.     'Open website
  11.     IE.Navigate "http://translate.google.com/#" & InLanguage & "/" & OutLanguage & "/" & InputStr
  12.  
  13.     DoEvents
  14.  
  15.     Do Until IE.ReadyState = 4
  16.         apWait LanguageTranslateTime, 0                         ' Wait half .05 seconds
  17.         DoEvents
  18.     Loop
  19.  
  20.     OutputStr = Replace(IE.Document.getElementById("result_box").innerHTML, "<span>", "")   ' Get rid of the HTML "<span>"
  21.  
  22.     IE.Quit
  23.  
  24.      If OutputStr > "" Then
  25.         OutputStr = Replace(OutputStr, "</span>", "")           ' Get rid of the HTML "</span>"
  26.         OutputStr = Replace(OutputStr, "&amp;", "&")            ' Replace undescored shortcut letters
  27.  
  28.        TranslatedWord = StrConv(OutputStr, vbUnicode)
  29.         TestWord = ""
  30.         For i = 1 To Len(TranslatedWord) Step 2
  31.             Debug.Print Right("0" & Hex(Asc(Mid(TranslatedWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TranslatedWord, i, 1))), 2)
  32.             TestWord = Right("0" & Hex(Asc(Mid(TranslatedWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TranslatedWord, i, 1))), 2)
  33.             TmpWord = TmpWord & CharW("U" & TestWord, -1)        ' Indicate it's a unicoode character
  34.         Next i
  35.  
  36.             Debug.Print StrConv(OutputStr, vbUnicode)
  37.     End If
  38.  
The second function uses the ChrW$ function to return each 4 digit hex number as a Cyrillic letter (providing you have the Russian Language pack installed?????)

I add the ???? because I can translate into Mongolian (well someone has to) and I don't have the Mongolian language pack installed.
In fact I have just added Bengali as a language, to translate to, but have not added the language pack, and it is coming out OK.

Interesting!

Expand|Select|Wrap|Line Numbers
  1. Public Function CharW(TestWord As Variant, Optional Exact_functionality As Boolean = False) As String
  2.     ' Use a Leading U or u to indicate Unicode values
  3.     ' Exact_functionality returns the Unicode characters for Ascii(128) to Ascii(159) rather than the Windows characters
  4.  
  5.     If UCase(Left$(TestWord, 1)) = "U" Then
  6.         TestWord = Replace(TestWord, "U", "&H", 1, 1, vbTextCompare)
  7.     End If
  8.  
  9.     TestWord = CLng(TestWord)
  10.  
  11.     If TestWord < 256 Then
  12.         If Exact_functionality Then
  13.             CharW = ChrW(TestWord)
  14.         Else
  15.             CharW = Chr(TestWord)
  16.         End If
  17.     Else
  18.         CharW = ChrW(TestWord)
  19.     End If
  20.  
  21. End Function
  22.  
Phil
Sep 15 '17 #7

Post your reply

Sign in to post your reply or Sign up for a free account.