VB6.0用掲示板の過去のログ(No.1)−VBレスキュー(花ちゃん)
[記事リスト] [新規投稿] [新着記事] [ワード検索] [過去ログ] [管理用]

投稿日: 2003/02/25(Tue) 19:19
投稿者TOMO
Eメール
URL
タイトルRe^2: 便乗質問、&演算子を使用しない方法

サンプルありがとうございます。
Dictionary オブジェクトとJoin関数の組合せが最も高速でした。

戴いたサンプルを参考に、16進ダンプのサンプルができましたので報告します。

サンプルを2つ作りましたが、私のコードがマズイためか、
Dictionary オブジェクトのコレクションよりも単純にSring型変数
の配列にした方が高速でした。
しかし、Join関数の存在を初めて知りましたが、その効果に驚きました。
誠にありがとうございました。

' サンプル−0
' Dictionary オブジェクト + Join関数
Private Function GetHexDump_0(bytData() As Byte) As String
    Dim lngByteLen  As Long
    Dim strVAddress As String
    Dim objDicHex   As Object
    Dim objDicChr   As Object
    Dim objDicRow   As Object
    Dim bTmp        As Byte
    Dim n           As Long
    Dim i           As Long
    Dim j           As Long
    On Error Resume Next
    lngByteLen = UBound(bytData) + 1
    If (lngByteLen = 0) Then Exit Function
    Set objDicHex = CreateObject("Scripting.Dictionary")
    Set objDicChr = CreateObject("Scripting.Dictionary")
    Set objDicRow = CreateObject("Scripting.Dictionary")
    n = 0
    For i = 0 To lngByteLen - 1 Step 16
        strVAddress = Right$("0000000" & Hex(i), 8) & " "
        For j = 0 To 15
            If (i + j < lngByteLen) Then
                bTmp = bytData(i + j)
                If (bTmp < &H10) Then
                    objDicHex(j) = "0" & Hex(bTmp)
                Else: objDicHex(j) = Hex(bTmp)
                End If
                If (bTmp < 32) Then
                    objDicChr(j) = "."
                Else: objDicChr(j) = Chr$(bTmp)
                End If
            Else: objDicHex(j) = "  "
            End If
        Next j
        objDicRow(n) = strVAddress & Join(objDicHex.Items()) _
                       & " " & Join(objDicChr.Items(), "")
        n = n + 1
    Next i
    GetHexDump_0 = Join(objDicRow.Items(), vbCrLf)
    Set objDicHex = Nothing
    Set objDicChr = Nothing
    Set objDicRow = Nothing
End Function


' サンプル−1
' Sring型の配列 + Join関数
Private Function GetHexDump_1(bytData() As Byte) As String
    Dim lngByteLen  As Long
    Dim strVAddress As String
    Dim strHex(15)  As String
    Dim strChr(15)  As String
    Dim strRow()    As String
    Dim nRows       As Long
    Dim bTmp        As Byte
    Dim n           As Long
    Dim i           As Long
    Dim j           As Long
    On Error Resume Next
    lngByteLen = UBound(bytData) + 1
    If (lngByteLen = 0) Then Exit Function
    nRows = (lngByteLen + 15) \ 16
    ReDim strRow(nRows - 1)
    n = 0
    For i = 0 To lngByteLen - 1 Step 16
        strVAddress = Right$("0000000" & Hex(i), 8) & " "
        For j = 0 To 15
            If (i + j < lngByteLen) Then
                bTmp = bytData(i + j)
                If (bTmp < &H10) Then
                    strHex(j) = "0" & Hex(bTmp)
                Else: strHex(j) = Hex(bTmp)
                End If
                If (bTmp < 32) Then
                    strChr(j) = "."
                Else: strChr(j) = Chr$(bTmp)
                End If
            Else
                strHex(j) = "  "
                strChr(j) = ""
            End If
        Next j
        strRow(n) = strVAddress & Join(strHex()) _
                    & " " & Join(strChr(), "")
        n = n + 1
    Next i
    GetHexDump_1 = Join(strRow(), vbCrLf)
End Function


- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)

- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)

- Web Forum -