宮崎県延岡市 | スマイルカラーソフトウェア | ユーザースタイルに合わせたプログラミングでお客様に幸せをお届けします。

Shift_JIS から JIS に変換

普段使うことはないのですが、たまに必要になることがあるのです。 1文字ずつ、Asc 関数で数値にして呼び出してください。

Public Function GetJIS(ByVal SJIS As Integer) As Integer
    Select Case SJIS
        Case 0 To 255
            GetJIS = SJIS
            Exit Function
    End Select
    
    Dim intLow  As Integer, intHigh As Integer
    Dim strTemp As String
    
    ' Shift JIS を 16進数文字列にします
    strTemp = "0000" & Hex(SJIS)
    ' 下位バイトを取得します
    intLow = CInt("&H" & Right(strTemp, 2))
    ' 上位バイトを取得します
    intHigh = CInt("&H" & Left(strTemp, Len(strTemp) - 2))
    
    If intHigh < &HA0 Then
        intHigh = intHigh - &H70
    Else
        If intHigh < &HF0 Then
            intHigh = intHigh - &HB0
        Else
            GetJIS = intHigh * &H100 + intLow
            Exit Function
        End If
    End If
    intHigh = intHigh * 2
    If intLow >= &H80 Then
        intLow = intLow - 1
    End If
    If intLow >= &H9E Then
        intLow = intLow - &H5E
    Else
        intHigh = intHigh - 1
    End If
    intLow = intLow - &H1F
    GetJIS = intHigh * &H100 + intLow
End Function