Hi i'm new to VB, we have just started to learn it in school, but I have come across a problem.
I want the computer to automate the creation and assignment of arrays, but I just get errors with my code.
Here is what I have so far.
Dim k As Integer
Dim test(k) As Integer
For i = 1 To 5
k = i - 1
test(k) = i
Next
Console.Write(test(k))
Console.ReadLine()
End Sub
Can someone show me how to do this properly?
Could someone also show me how to print the entire contents of an integer array?
Thanks
Callum
Edit:
I have also tried, this but it just returns a 0 rather than the first value of the array which should be a 1.
Dim array(5) As Integer
Dim i As Integer
Dim k As Integer
Dim x As Integer
For i = 1 To 5
k = i
x = i - 1
ReDim array(k)
array(x) = i
Next
Console.WriteLine(array(0))
Console.ReadLine()
I want the computer to automate the creation and assignment of arrays, but I just get errors with my code.
Here is what I have so far.
Dim k As Integer
Dim test(k) As Integer
For i = 1 To 5
k = i - 1
test(k) = i
Next
Console.Write(test(k))
Console.ReadLine()
End Sub
Can someone show me how to do this properly?
Could someone also show me how to print the entire contents of an integer array?
Thanks
Callum
Edit:
I have also tried, this but it just returns a 0 rather than the first value of the array which should be a 1.
Dim array(5) As Integer
Dim i As Integer
Dim k As Integer
Dim x As Integer
For i = 1 To 5
k = i
x = i - 1
ReDim array(k)
array(x) = i
Next
Console.WriteLine(array(0))
Console.ReadLine()
Last edited: