Is it possible to convert Unicode to ANSI in text box KeyPress Event?
or by typeing ansi character converting to unicode
:afrog:
Printable View
Is it possible to convert Unicode to ANSI in text box KeyPress Event?
or by typeing ansi character converting to unicode
:afrog:
Unfortunatenaly Unicode is already translated to ANSI by Windows before it comes to a regular VB6 textbox (as it is ANSI only).
Private Sub Form_Load()
Dim strUnicode As String, strANSI As String
Text1.Font.Charset = 178
strUnicode = ChrW(1594) & ChrW(1613)
strANSI = StrConv(strUnicode, vbFromUnicode, 1025)
Text1.Text = StrConv(strANSI, vbUnicode)
End Sub
something like above but convert ansi to unicode when u typing in keypress event
Code:Function CUni(str1 As String) As String
Dim Char, struni As String
Dim ch1 As Integer
For i = 1 To Len(str1)
Char = Left(str1, 1)
Select Case Char
'Case " ": ch1 = &H20
Case "H": ch1 = &H622
Case "h": ch1 = &H627
Case "f", "F": ch1 = &H628
Case "`": ch1 = &H67E
Case "j", "J": ch1 = &H62A
Case "e", "E": ch1 = &H62B
Case "[": ch1 = &H62C
Case "]": ch1 = &H6286
Case "p", "P": ch1 = &H62D
Case "o", "O": ch1 = &H62E
Case "n", "N": ch1 = &H62F
Case "b", "B": ch1 = &H630
Case "v", "V": ch1 = &H631
Case "c", "C": ch1 = &H632
Case "\": ch1 = &H698
Case "s", "S": ch1 = &H633
Case "a", "A": ch1 = &H634
Case "w", "W": ch1 = &H635
Case "q", "Q": ch1 = &H636
Case "x", "X": ch1 = &H637
Case "z", "Z": ch1 = &H638
Case "u", "U": ch1 = &H639
Case "y", "Y": ch1 = &H63A
Case "t", "T": ch1 = &H641
Case "r", "R": ch1 = &H642
Case ";": ch1 = &H6A9
Case "'": ch1 = &H6AF
Case "g", "G": ch1 = &H644
Case "l", "L": ch1 = &H645
Case "k", "K": ch1 = &H646
Case ",": ch1 = &H648
Case ">": ch1 = &H623
Case "<": ch1 = &H624
Case "i", "I": ch1 = &H647
Case "d", "D": ch1 = &H6CC
Case "M": ch1 = &H626
Case "m": ch1 = &H621
Case "0": ch1 = &H6F0
Case "1": ch1 = &H6F1
Case "2": ch1 = &H6F2
Case "3": ch1 = &H6F3
Case "4": ch1 = &H6F4
Case "5": ch1 = &H6F5
Case "6": ch1 = &H6F6
Case "7": ch1 = &H6F7
Case "8": ch1 = &H6F8
Case "9": ch1 = &H6F9
Case Else: ch1 = Asc(Char)
End Select
'List1.AddItem ChrW(ch1)
str1 = Right(str1, Len(str1) - 1)
CUni = CUni + ChrW(ch1)
Next i
End Function
As mentioned by Merri standard Textboxes cannot display Unicode.
Merri has authored a series of controls including a textbox (UniText) that do support Unicode but I understand it's not 100% finished. If you have look at his code you will understand that it is an incredibly complicated thing to achieve in vb6.
Finishing it would require commercial resources, which I do not have (nor am willing to go for, especially with a language this old).
Anyway, it seems you have already turned on Arabic. This method:Enables Arabic display and writing as well as long as the keyboard is set to Arabic as well. Using IME does not work and it will be pain-in-the-bottom to fix it.Code:Text1.Font.Name = "Arial"
Text1.Font.Size = 10
Text1.Font.Charset = 178 ' Arabic ANSI
Then, this:Simply allows placing a string stored as Unicode into the textbox on a computer using any locale. If this trick wasn't used the string data would be processed using computer's default locale thus resulting into question marks when hitting characters it does not detect.Code:Text1.Text = StrConv(StrConv(ChrW$(1594) & ChrW$(1613), vbFromUnicode, 1025), vbUnicode)
What happens here is that first Unicode string containing Arabic is turned into Arabic ANSI string. Then it is converted to Unicode using "incorrect", computer's default locale. However, when this string is given to VB6's textbox an automatical Unicode to ANSI conversion takes place. The resulting string is the correct Arabic ANSI string and it then displays correctly (as long as Font.Charset is correct).
ok leave the unicode can we create a font and replace all 256 ascii character
with arabic character set the font proprity for the text box and use the font we have created
to write arabic
Arabic characters take on different shapes depending on their position in a text string and on the surrounding characters.
Arabic script is cursive. Most characters of a word are connected to each other, as in English handwriting.
Characters can be joined to form ligatures.
A character can be represented with a vowel or diacritic mark written over or under it.
Shapes of the Arabic Characters
Arabic code pages can contain from one to four shapes for each character or ligature, depending on the implementation.
The four possible shapes of an Arabic character are:
Isolated
The character is not linked to either the preceding or the following character.
Final
The character is linked to the preceding character but not to the following one.
Initial
The character is linked to the following character but not to the preceding one.
Middle
The character is linked to both the preceding and following characters.
i think 4 variables needed and checking the left and right position of a character and matching them with those key in vairables and replacing them when needed
I may have no idea here if this is where your problem is but try some pseudocode.
Code:if previouschar = " " then 'initial or isolated
if nextchar = " " then ' isolated
else ' initial
end if
else ' middle or final
if nextchar = " " then ' final
else ' middle
end if
end if