GB與BIG5內碼轉換COM原代碼
發(fā)表時間:2023-08-13 來源:明輝站整理相關軟件相關文章人氣:
[摘要]這個COM用到了一個VC的資源文件。就是字典。大家可以去61.134.75.70/download/gb2big5.zip下載 原代碼如下:'////////////////////////...
這個COM用到了一個VC的資源文件。就是字典。
大家可以去61.134.75.70/download/gb2big5.zip下載
原代碼如下:
'//////////////////////////////////////////
'中文名稱:GB與BIG5內碼互換控件
'英文名稱:GB2BIG5
'作者:Blood
'版本:1.0
'制作時間:2002.3.5
'版權所有 Blood 2002 - 2003
'//////////////////////////////////////////
Option Explicit
'定義變量
Dim BIG5Data As Variant
Dim GBData As Variant
'定義自定義類型,用來處理編碼的高低字問題
Type ChineseTypeA
loChar As Byte
hiChar As Byte
End Type
Private BIG5Type(&HA1 To &HFF, &H40 To &HFE) As ChineseTypeA '對應于BIG5字庫
Private GBType(&HA7 To &HFF, &HA1 To &HFE) As ChineseTypeA '對應與GB字庫
'//////////////////
'公共函數(shù)開始
'//////////////////
'BIG5轉換到GB的函數(shù)
Function BIG5TOGB(strSource As String) As String
Dim I As Long, Y As Long
'定義數(shù)組,用來存放BIG5和GB內碼數(shù)據(jù)
Dim bteBIG5() As Byte
Dim bteGB() As Byte
'如果輸入的內容為空,則退出函數(shù)
If strSource = "" Then
BIG5TOGB = ""
Exit Function
End If
'將BIG5數(shù)組的類型從Unicode編碼轉換為系統(tǒng)缺省碼
bteBIG5 = StrConv(strSource, vbFromUnicode)
'確定BIG5數(shù)組的下標,用來循環(huán)將所有的BIG5內容轉換為GB內碼
Y = UBound(bteBIG5)
ReDim bteGB(0 To Y)
For I = 0 To Y
If I = Y Then
bteGB(I) = bteBIG5(I)
Exit For
End If
If bteBIG5(I) < &HA1 Or bteBIG5(I + 1) < &H40 Then
bteGB(I) = bteBIG5(I)
Else
bteGB(I) = BIG5Type(bteBIG5(I), bteBIG5(I + 1)).loChar
bteGB(I + 1) = BIG5Type(bteBIG5(I), bteBIG5(I + 1)).hiChar
I = I + 1
End If
Next I
'將系統(tǒng)缺省碼轉換為Unicode編碼
BIG5TOGB = StrConv(bteGB, vbUnicode)
'重新初始化GB數(shù)組,以釋放內存
Erase bteGB
End Function
'GB轉換到BIG5的函數(shù)
Function GBTOBIG5(strSource As String) As String
Dim I As Long, Y As Long
'定義數(shù)組,用來存放BIG5和GB內碼數(shù)據(jù)
Dim bteGB() As Byte
Dim bteBIG5() As Byte
'如果輸入的內容為空,則退出函數(shù)
If strSource = "" Then
GBTOBIG5 = ""
Exit Function
End If
'將GB數(shù)組的類型從Unicode編碼轉換為系統(tǒng)缺省碼
bteGB = StrConv(strSource, vbFromUnicode)
'確定GB數(shù)組的下標,用來循環(huán)將所有的BIG5內容轉換為GB內碼
Y = UBound(bteGB)
ReDim bteBIG5(0 To Y)
For I = 0 To Y
If I = Y Then
bteBIG5(I) = bteGB(I)
Exit For
End If
If bteGB(I) < &HA1 Or bteGB(I + 1) < &HA1 Then
bteBIG5(I) = bteGB(I)
Else
If bteGB(I) < &HB0 And bteGB(I + 1) >= &HA1 Then
bteBIG5(I) = GBType(bteGB(I) + 6, bteGB(I + 1)).loChar
bteBIG5(I + 1) = GBType(bteGB(I) + 6, bteGB(I + 1)).hiChar
Else
bteBIG5(I) = GBType(bteGB(I), bteGB(I + 1)).loChar
bteBIG5(I + 1) = GBType(bteGB(I), bteGB(I + 1)).hiChar
End If
I = I + 1
End If
Next I
'將系統(tǒng)缺省碼轉換為Unicode編碼
GBTOBIG5 = StrConv(bteBIG5, vbUnicode)
'重新初始化BIG5數(shù)組,以釋放內存
Erase bteBIG5
End Function
'//////////////////
'公共函數(shù)結束
'//////////////////
'類初始化
Private Sub Class_Initialize()
Dim I As Long
Dim J As Long
Dim iLen As Long
'從資源文件中讀取GB與BIG5的字庫
GBData = LoadResData(102, "CUSTOM") '//讀取GB字庫
BIG5Data = LoadResData(101, "CUSTOM") '//讀取BIG5字庫
For I = &HA1 To &HFE
For J = &H40 To &HFE
BIG5Type(I, J).loChar = BIG5Data(iLen)
BIG5Type(I, J).hiChar = BIG5Data(iLen + 1)
iLen = iLen + 2
Next J
Next I
iLen = 0
For I = &HA7 To &HFE
For J = &HA1 To &HFE
GBType(I, J).loChar = GBData(iLen)
GBType(I, J).hiChar = GBData(iLen + 1)
iLen = iLen + 2
Next J
Next I
End Sub