0

I'm just got into Visual Basic and I'm trying to "recode" my programs from java into VB. But my main problem is how to do that, i don't the syntax too much. I have read some but I find it hard(I'm a slow learner :P).

Edit: Here is the code I am trying:

Module Module1
Dim arrays(5) As String

Sub Main()
    Console.WriteLine("Enter your Names:")
    For i As Integer = 0 To arrays.Length
        arrays(i) = Console.ReadLine
    Next i

    For Each arr As String In arrays
        Console.WriteLine(arr)
    Next
    Console.ReadLine()
End Sub

End Module

At some point, whenever I run it and try to input, it goes beyond the number of index. And doesn't write the inputs :P

2
  • Please share some code and you need to be more descriptive to get some help. Commented Jun 30, 2015 at 3:03
  • So some effort, also show what Java are you trying to translate to VB.NET. Commented Jun 30, 2015 at 3:04

1 Answer 1

2

Since it is a zero based array, you need to get the length - 1. Your array is set to 5, so it has 6 elements and arrays. Length = 6 where your loop needs to be 0 to 5.

Module Module1
Dim arrays(5) As String

 Sub Main()
  Console.WriteLine("Enter your Names:")
  For i As Integer = 0 To arrays.Length - 1
    arrays(i) = Console.ReadLine
  Next i

  For Each arr As String In arrays
    Console.WriteLine(arr)
  Next
  Console.ReadLine()
 End Sub
End Module
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the late reply. Thank you :)

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.