電子書籍の厳選無料作品が豊富!

(1)文字列 2-ABC1234(9文字)をアスキーコード化し
変数配列txt(1 to 10)に
txt(1)=322D「2-」,txt(2)=4142「AB」,
txt(3)=4331「C1」,txt(4)=3233「23」,
txt(5)=3400「4」,txt(6)=0000「」,
txt(7)=0000「」,txt(8)=0000「」,
txt(9)=0000「」,txt(10)=0000「」
とセットしたいのですが、どのようにすれば良いのでしょうか?

(2)(1)の逆変換で変数txt(1 to 10)を 変数mozi as string に「2-ABC1234」とセットしたいのですが、どのようにすれば良いのでしょうか?

初歩的なご質問で申し訳ございません。
よろしくお願いいたします

A 回答 (1件)

もう少し、きれいな形にしたかったけれども、今のところ、こんな程度です。



Sub Code_Hennkan(ByVal myString As String)
 Dim myCode As String
 Dim delim As String
 Dim txt(1 To 10) As Variant
 Dim i As Integer, j As Integer
 For i = 1 To Len(myStr)
  myCode = myCode & Hex(Asc(Mid(myStr, i, 1)))
 Next i
  myCode = myCode & String(40 - Len(myCode), "0")
 For j = 1 To 40 Step 4
  txt((j - 1) / 4 + 1) = Mid(myCode, j, 4)
 Next j
End Sub

Sub Mozi_Henkan(ByVal BaseArray As Variant)
 Dim i As Integer, j As Integer
 Dim buf1 As String
 Dim buf2 As String
 Dim Mozi As String
 For i = LBound(BaseArray) To UBound(BaseArray)
  If BaseArray(i) <> "0000" Then
   buf1 = buf1 & BaseArray(i) 'コードの取り出し
  End If
 Next i
 For j = 1 To Len(buf1) Step 2
  buf2 = buf2 & Chr("&h" & Mid(buf1, j, 2))
 Next j
 Mozi = Mid(buf2, 1, Len(buf2) - InStr(buf2, vbNullString))
End Sub
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!