Vb.Net arrays beed help with issue.

Discussion in 'Web Design & Coding' started by VenomXt, Mar 27, 2007.

  1. VenomXt

    VenomXt Blame me for the RAZR's Folding Team

    Houston, Texas
    Ok here is the problem

    This is the code have generated so far

    Module numbers
       Sub Main()
          Dim numbers(5) As Integer
          Dim secondnumbers(5) As Integer
          Dim x As Integer
          Dim z As Integer = 0
          For i As Integer = 0 To 5
             Console.WriteLine("Please Enter The Value(-1 to stop)")
             x = Console.ReadLine()
             If x < -1 Then
                Do Until x > -2
                   Console.WriteLine("You have entered a negative number, Please Try again")
                   x = Console.ReadLine
             ElseIf x = -1 Then
                Console.WriteLine("You have opted to quit entering numbers")
                'This rebuilds the array due to wanting to end the number entering early and it preserves the old data.
                i = 5
                z = i
                ' this isnt culling the zeros that are left becase you wanted to end input early
                ReDim Preserve numbers(z)
             End If
             'this is whats getin the data from the read line and entering it into the array
             numbers(i) = x
          Next i
          'If z = 0 Then
          Dim txt As String = ""
          For i As Integer = 0 To 5
             txt &= numbers(i).ToString & vbCrLf
          Next i
          ' The SharedCopy method does exactly what you think it will do, copy an array or pieces of an array to another array. Remember though, you may me copying reference types so approach it accordingly
          Array.Copy(numbers, secondnumbers, z)
          'not sure if i will need
          ' Dim txt As String = ""
          'For i As Integer = 0 To 5
          'txt &= numbers(i).ToString & vbCrLf
          'Next i
          ' End If
       End Sub
    End Module
    I cant get the redim preserve statment to make the array just the input without the remainder array size to be filled with zeros and then a -1. Any ideas? Im stuck.