2

I'm trying to use some code from the Opus project in VB.net, it was originally written for C, but I am integrating it into another application...

    byte[] _notEncodedBuffer = new byte[0];

    byte[] soundBuffer = new byte[e.BytesRecorded + _notEncodedBuffer.Length];

I'm not sure how these should be translated into VB.net, I have translated all the code but this and am getting good results, just not entirely sure on these, had all kinds of errors with my attempts, including Identifier expected, Bracket identifier missing etc! :(

    Dim wavNEB As Byte() = New Byte [0]

    Dim wavSnd As Byte() = New Byte [e.BytesRecorded + wavNEB.Length]

That was my last attempt, but no cigar!

Any help much appreciated, I rarely have to break VB or C out so it's not a strong point...

3
  • 1
    Change brackets [] to parhentesis ()... Commented Feb 12, 2015 at 0:09
  • 1
    And subtract 1 from the number inside the parentheses. VB expects the index of the last item rather than the number of items in the array. E.g. Dim wavNEB(-1) as Byte Commented Feb 12, 2015 at 0:12
  • This is most definitely not C. It looks like C# to me. Commented Feb 12, 2015 at 0:14

1 Answer 1

6

In VB.NET, the syntax

Dim ArrayName(N) As ArrayType

is equivalent to the C# code:

ArrayType[] ArrayName = new ArrayType[N+1];

Additionally, if ArrayName has been declared as ArrayType, the executable statement

ReDim ArrayName(N)

would be equivalent to the C# code

ArrayName = new ArrayType[N+1];

Additionally, VB.NET offers the syntax

ReDim Preserve ArrayName(N)

as a means of replacing ArrayName with a reference to a new array of size N+1 whose contents are pre-loaded with those of the old array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.