Resolved Pass A Byte Array To A Sub

zunebuggy65

Active member
Joined
Oct 12, 2023
Messages
42
Programming Experience
3-5
I am trying to pass a Byte array to a sub, but no matter how I do it, the sub is writing all zeros.

VB.NET:
    Dim myBinArry(2000) As Byte

    'Code to fill myBinArry here.
    'Verified myBinArry(0) - myBinArry(1999) contain values.

    WriteBinaryFile(myFileName, myBinArry)

    Private Sub WriteBinaryFile(ByVal myFileName As String, ByVal myBinArry As Byte)
        Dim binWrite As BinaryWriter
        binWrite = New BinaryWriter(File.Open(myFileName, FileMode.Create))
        Using binWrite
            For t = 0 To Len(myBinArry) ' I know I should use Ubound and I will as soon as I get passing the Array to work
                binWrite.Write(myBinArry(t))
            Next
        End Using
        binWrite.Close()
    End Sub
  
    'Result: file is created but it writes only zeros.

Secondary, less important question. I use Relyze to view my binary files (decompiler). Can anyone recommend something better? It crashes with large files.

Thank you
 
Last edited:
I'm hoping my last solution in this thread is the correct one. If so, I will mark it resolved. It's strange. I did a search for Passing Byte Arrays to a Sub and the only good example I could find was to Dim the Array as Byte and to pass it without () or ByRef in the parameters calling the Sub. I had so many combinations to try. I knew I would stumble on it eventually.
 
ByRef:
Specifies that an argument is passed in such a way that the called procedure can change the value of a variable underlying the argument in the calling code.
It has no use in this case.
 
Hmmm. It seems to work but I will look at it under the compiler.

I even considered converting my Array to a very long String representation of the Byte Array and passing that String because that always works, except I am dealing with very large binary files.
 
Back
Top