0

I just switched from MATLAB to visual basic, and need to know how to fill an array using a for loop. This is what I have in visual basic but it's giving me an error. Also if someone could suggest a more efficient way of filling an array, that would be greatly appreciated.

Module Module1

    Sub Main()
        Dim x(10) As Integer
        For i = 1 To x.Length
            x(i) = i
        Next
        Console.WriteLine(x)
        Console.ReadLine()
    End Sub
End Module

1 Answer 1

1

Arrays in .NET (including C# and VB.NET) are indexed from 0...Length-1, whereas VB6 and VBA are indexed from 1...Length.

Change your for-loop to this:

For i = 0 To x.Length - 1
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.