Android Code Snippet VB6 VBA uses prefix mode and data structure of prefix mode.

Discussion in 'Code Snippets' started by boy8199, Jun 5, 2019.

  1. boy8199

    boy8199 New Member

    因为使用VBA,使用了 b4a 的前缀模式传输数据。但是 我查了论坛没有找到VBA VB6的代码,但是有VB.net的代码。 但是 VB.net有很多VBA VB6 没有的新功能和函数。我用了很多时间去尝试。最终我成功的使用前缀模式发送文件成功。我希望分享我的代码,帮助新的朋友。


    1、文件名的长度,VB6, 4个字符,32位(倒序)
    2、文件名,vb6 string --> utf-8,长度为文件名长度
    3、STREAM_PREFIX标志,vb6 4个字符,long(倒序)
    4、文件数据长度,vb6(不支持)8个字符,64位,我只用了最后4位 Long(倒序)
    7、Adler-32校验码,vb6( 不支持)8个字符,64位,我只用了最后4位 Long(正序)

    上面的正序,是指VB6 中的数字存储模式:Long 类型,从左边位,开始存储数据,而V4A的socket是从右开始读取数据的。
    Because of the use of VBA, the prefix mode of b4a is used to transmit data. But I checked the forum did not find VBA VB6 code, but there is VB. net code. But has many new functions and functions that VBA VB6 does not have. I spent a lot of time trying. Eventually, I succeeded in sending files in prefix mode. I want to share my code and help new friends.
    At the same time, I hope the forum can provide more detailed guidance.
    1. File name length, VB6, 4 characters, 32 bits (reverse order)
    2. File name, VB6 string - > utf-8, length is file name length
    3. STREAM_PREFIX flag, vb64 characters, long (reverse order)
    4. File data length, VB6 (not supported) 8 characters, 64 bits, I only used the last 4 bits Long (reverse order)
    6. Document data
    7. Adler-32 check code, VB6 (unsupported) 8 characters, 64 bits, I only used the last 4 bits Long (positive order)
    The positive order above refers to the digital storage mode in VB6: Long type, which stores data from the left bit, while V4A socket reads data from the right.

    Code, I will improve it and upload it to you.
  2. boy8199

    boy8199 New Member


    Public Function Adler32Byte(bString() As Byte, Optional ReturnByteCount As Long = 4, _
                                 Optional A 
    As Long = 1As Byte()

    Dim B As Long, x As Long
    Dim bA(3As Byte
    Dim bB(3As Byte
    Dim bBA(3As Byte
    Dim bBa8(7As Byte
        A = (A + (bString(x) 
    And 255)) Mod 65521
    For x = 1 To UBound(bString)
            B = (B + A) 
    Mod 65521
            A = (A + (bString(x) 
    And 255)) Mod 65521
    Next x

        CopyMemory bA(
    0), A, 4
        CopyMemory bB(
    0), B, 4
        CopyMemory bBA(
    0), bB(1), 1
        CopyMemory bBA(
    1), bB(0), 1
        CopyMemory bBA(
    2), bA(1), 1
        CopyMemory bBA(
    3), bA(0), 1

    If ReturnByteCount = 8 Then
            Call CopyMemory(ByVal VarPtr(bBa8(
    4)), ByVal VarPtr(bBA(0)), 4)
            Adler32Byte = bBa8
            Adler32Byte = bBA
    End If  
    End Function
    MarcoRome and Erel like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice