1

I am getting subscript out of range error where is the problem in this code,

the code uses "zlib" compression to compress the byte array and then it will send to server side over network. my code is as,

sendfile = "C:\Users\bhavesh\Desktop\15.jpg"
uncompressed_size = FileLen(sendfile)
    Open sendfile For Binary As 1
    ReDim uncompressed_bytes(1 To LOF(1)) As Byte
    Get #1, 1, uncompressed_bytes()
    Close #1
    MsgBox "first : " & UBound(uncompressed_bytes) - LBound(uncompressed_bytes)


    compressed_size = 1.01 * uncompressed_size + 12
    ReDim compressed_bytes(0 To compressed_size)
    Select Case compress(compressed_bytes(0), compressed_size - 1, uncompressed_bytes(0), uncompressed_size + 1)
        Case Z_MEM_ERROR
            MsgBox "Insufficient memory", vbExclamation, "Compression Error"
            Exit Sub
        Case Z_BUF_ERROR
            MsgBox "Buffer too small", vbExclamation, "Compression Error"
            Exit Sub
    End Select
    ReDim Preserve compressed_bytes(0 To compressed_size)
1
  • Is there a reason why you cannot locate the line with the error using the IDE? Feb 3, 2014 at 23:07

1 Answer 1

3

You define uncompressed_bytes with a lower bound of 1 and then reference it's 0th element, which is why you're getting subscript out of range.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.