Results 1 to 1 of 1

Thread: vb6 - storing chinese/jap character in INI file.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    121

    vb6 - storing chinese/jap character in INI file.

    i have figure out how to store chinese/japanese character in INI. the codes are as follow. hope it helps.

    VB Code:
    1. Public Enum CodeEnum
    2.    cgNone = 0
    3.    cgANSI = 1
    4.    cgUTF8 = 2
    5.    cgUTF16 = 3
    6.    cgHTML = 4
    7. End Enum
    8.  
    9.  
    10. 'the function to convert the input character to some encoding,
    11. 'you can convert the encoding back to the character
    12. Public Function Uni_VB(ByVal sText As String) As String
    13.    Dim lLen             As Long
    14.    Dim i                As Long
    15.    Dim sChar            As String
    16.    Dim lChar            As Integer
    17.    Dim CodeEnum         As CodeEnum
    18.  
    19.    lLen = Len(sText)
    20.  
    21.    If lLen Then
    22.       For i = 1 To lLen
    23.          sChar = Mid$(sText, i, 1)
    24.          lChar = AscW(sChar)
    25.          If (lChar >= &H0) And (lChar <= &HFF) Then
    26.             Select Case CodeEnum
    27.                Case cgNone
    28.                   Uni_VB = Uni_VB & Chr$(34)
    29.                Case cgANSI
    30.  
    31.                Case cgUTF16
    32.                   Uni_VB = Uni_VB & " & " & Chr$(34)
    33.             End Select
    34.             CodeEnum = cgANSI
    35.             Uni_VB = Uni_VB & sChar
    36.          Else
    37.             If CodeEnum = cgANSI Then
    38.                Uni_VB = Uni_VB & Chr$(34)
    39.             End If
    40.             CodeEnum = cgUTF16
    41.             'Uni_VB = Uni_VB & " & ChrW$(&H" & Hex$(lChar) & ")"
    42.             Uni_VB = Uni_VB & "  &H" & Hex$(lChar) & "|"
    43.          End If
    44.       Next
    45.  
    46.       If CodeEnum = cgANSI Then
    47.          Uni_VB = Uni_VB & Chr$(34)
    48.       End If
    49.  
    50.    End If
    51. End Function
    52.  
    53. 'usage:
    54.    'to insert into ini file
    55.     str1 = TextBox1.Text
    56.     fstr = Uni_VB(str1)
    57.     'Debug.Print fstr
    58.     iniFile$ = "C:\CP.ini"
    59.     WriteToINI "Section", "Key", fstr, iniFile$
    60.  
    61. 'to display it:
    62. iniFile$ = "C:\CP.ini"
    63.     szaTemp = Space(lSize)
    64.     lRet = GetPrivateProfileString("Section", "Key", "", szaTemp, lSize, iniFile$)
    65.     szaTemp = Left(szaTemp, lRet)
    66.  strCode = Split(szaTemp, "|")
    67.  fstr = fstr & ChrW$(strCode(i))
    68. TextBox2.Text = fstr
    Last edited by fang_eve; Jan 25th, 2007 at 08:02 PM.

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