Option Explicit Dim objFSO, objTxt, objWShell Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set objTxt = objFSO.OpenTextFile("Henkan_Test.txt", ForAppending, true, -1) Set objWShell = WScript.CreateObject("WScript.Shell") Dim strInput '入力文字 Dim strChrs() '入力文字を動的配列変数へ ' 入力 myInput ' 文字数チェック(253文字まで) If LenB(strInput) > 507 Then myNagasugi ' 入力文字をテキストへ書込 objTxt.WriteLine "文字列 : " & strInput ' 入力文字を1文字ずつ配列に代入 myHairetu(strInput) ' 文字列を Shit_JIS 符号に変換 myHenkan "Shift_JIS" ' 文字列を Unicode 符号に変換 myHenkan "Unicode " ' 改行 objTxt.WriteBlankLines (1) ' objTxtをクローズしてテキストエディタで開く objTxt.Close objWShell.Run "Henkan_Test.txt" 'オブジェクトを破棄 Set objWShell = Nothing Set objTxt = Nothing Set objFSO = Nothing '********************************************************* '* Sub myInput -- 入力 '********************************************************* Sub myInput strInput = InputBox("変換する文字列を入力", "文字を Shift_JIS,ユニコードで符号化") If IsEmpty(strInput) Then WScript.Quit If strInput = "" Then myInput Else myEcho End If End Sub '********************************************************* '* Sub myEcho -- 入力文字チェック '********************************************************* Sub myEcho Dim intStr, intStrB '文字数、バイト数 intStr = Len(strInput) intStrB = LenB(strInput) If intStr > 253 Then intStr = "254文字 オーバー" If intStrB > 507 Then intStrB = "508バイト オーバー" WScript.Echo " * 変数名 : ", "strInput",vbCrLf, _ " * 値 : ", strInput, vbCrLf, vbCrLf, _ " * 型 : ", TypeName(strInput), vbCrLf, _ " * 文字数 : ", intStr, vbCrLf, _ " * バイト : ", intStrB End Sub '********************************************************* '* Sub myHairetu -- 入力文字を動的配列変数へ '********************************************************* Sub myHairetu(strInput) Dim intLength intLength = Len(strInput) - 1 '配列のサイズ '動的配列 ReDim strChrs(intLength) '動的配列のサイズ変更 '1文字ずつ配列に代入 Dim intCounter For intCounter = 0 To intLength strChrs(intCounter) = Mid(strInput, intCounter + 1, 1) Next End Sub '********************************************************* '* Sub myHenkan(myCode) -- 動的配列を1文字ずつ符号化 '********************************************************* Sub myHenkan(myCode) objTxt.Write myCode & " : " Dim strArray, intCode For Each strArray in (strChrs) On Error Resume Next If myCode = "Shift_JIS" Then intCode = Hex(Asc(strArray)) Else intCode = Hex(AscW(strArray)) End If objTxt.Write intCode & "," On Error Goto 0 Next objTxt.WriteBlankLines (1) End Sub '********************************************************* '* Sub myNagasugi -- 254文字以上なら中断 '********************************************************* Sub myNagasugi WScript.Echo "入力データが長すぎます...",vbCrLf, _ "253文字以下に分割してください。" objTxt.Close Set objWShell = Nothing Set objTxt = Nothing Set objFSO = Nothing WScript.Quit End Sub