Results 1 to 7 of 7

Thread: Unicode

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    4

    Angry

    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
    Thinh

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    4
    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)
    Thinh

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    4

    Smile

    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
    Thinh

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    4

    Lightbulb

    what i meant was that it take keystrokes (from any program ) and when it finds "a and `", it will replace.
    Thinh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width