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

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.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Latest member