|
-
Sep 19th, 2000, 10:02 AM
#1
Thread Starter
New Member
hi, i'm wondering how can I display out the unicode characters. i'm writing a keyboard type of program that will need to use the unicode characters but i don't know where to start..thnx
-
Sep 19th, 2000, 11:10 AM
#2
Frenzied Member
VB does fully support unicode, it's just that it doesn't support it very well, All VB strings are in unicode and the chrW function can convert an integer into a unicode character.
So
Code:
Str = "Hello, this " & ChrW(364) & "Is a unicode character"
will give you a string containing the unicode character 364(which is just a number I made up and I don't know which character it is)
But VBs Default Font isn't a unicode font, So you'll have to change the font property of anything you want to write unicode out to into.
Unfortunatley None of the Objects with Caption or Text Properties can Take unicode strings, the only way is to print out what you want manually using the TextOutW API, Put this in a standard Module
Code:
Private Declare Function TextOutW Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Any, ByVal nCount As Long) As Long
Public Sub PrintUnicode(Target As Object, str As String)
TextOutW Target.hdc, Target.ScaleX(Target.CurrentX, Target.scalemod, vbPixels), Target.ScaleY(Target.CurrentY, Target.ScaleMode, vbPixels), StrPtr(str), Len(str)
End Sub
you can use this to print Unicode text to Forms and Pictureboxes, To Print str to Form1 do this
Code:
PrintUnicode Form1, str
Hope it helps
-
Sep 19th, 2000, 02:08 PM
#3
Thread Starter
New Member
i got a Run-time error '438'. Object doesn't support this property or method. Pointing to this line:
TextOutW Target.hdc, Target.ScaleX(Target.CurrentX, Target.scalemod, vbPixels), Target.ScaleY(Target.CurrentY, Target.ScaleMode, vbPixels), StrPtr(str), Len(str)
-
Sep 19th, 2000, 02:10 PM
#4
Frenzied Member
My Bad
Code:
TextOutW Target.hdc, Target.ScaleX(Target.CurrentX, Target.scalemode, vbPixels), Target.ScaleY(Target.CurrentY, Target.ScaleMode, vbPixels), StrPtr(str), Len(str)
missed out an e
-
Sep 19th, 2000, 02:24 PM
#5
Thread Starter
New Member
thnx, it works.
But the problem now is i don't know where to start.
Basically what I'm trying to do is when the user type "a" and "`", those two characters will be replace by "à". Any ideas? Thnx
-
Sep 19th, 2000, 02:53 PM
#6
Frenzied Member
If you use VB6's Replace Function, this uses the Form a little bit like a Textbox, it catches Keypresses and keeps a string of what the text in the form is, then prints it out on the form, It also uses the replace function to replace a` with à
Code:
Dim MyText As String
Private Sub Form_KeyPress(KeyAscii As Integer)
'Check if it's a backspace
Select Case KeyAscii
Case Asc(vbBack)
If Len(MyText) Then MyText = Left(MyText, Len(MyText) - 1)
KeyAscii = 0
Case Else
MyText = MyText & Chr(KeyAscii)
End Select
'Replace any a`a with às
MyText = Replace(MyText, "a`", ChrW(224))
'put the text on the form
Printtext
End Sub
Private Sub Printtext()
Form1.Cls
PrintUnicode Me, MyText
End Sub
It's not exactly a work of art, but it's a start.
-
Sep 19th, 2000, 03:23 PM
#7
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|