Vb.Net arrays beed help with issue.

11 Mar 2004
Ok here is the problem

Write an application which will:
[FONT=&quot] [/FONT]Allow the user to create an array of up to 100 positive numbers with the use of -1 to stop entering if user needs an array containing less than 100 elements.
[FONT=&quot] [/FONT]Check user’s input to prevent the input of any wrong numbers. (i.e.. negative numbers, except -1)
[FONT=&quot] [/FONT]Make two copies of the array. (Make sure you create two new arrays only of necessary size: exactly as many as it was entered by user. You may need a counter)
[FONT=&quot] [/FONT]Find (or create) and implement any sorting algorithm and use it to sort the first copy of the array.
[FONT=&quot] [/FONT]Use the standard Array.Sort method to sort the second copy of the array.
[FONT=&quot] [/FONT]Output all three arrays in one table (see example).

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.

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Latest member