0

I have tried to get an arraylist to work across all subs. I keep having a problem were the system wont recognize the arraylist name and wants me to generate a new stub or property for it. I am trying to write a program that will get user inputted numbers and sort them in descending and ascending order. Thank you for any help you can give, I am rather new to programming and dont really understand everything.

Module Module1
'This is a program written by Ben Sampley in order to print user defined numbers in ascending and descending orders
Public Sub Main()
    Dim n1, n2, n3, n4, n5, n6, n7, n8, n9, n10 As Integer
    Dim title As String = "Input Number"
    n1 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n2 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n3 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n4 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n5 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n6 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n7 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n8 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n9 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input
    n10 = InputBox("Please Enter A Whole Number Between 1 And 100", title, "0") 'Asks for user input and assigns a variable to the input

    Dim numbers As ArrayList = New ArrayList 'new arraylist called numbers
    numbers.add(n1) 'Adds to arraylist
    numbers.add(n2) 'Adds to arraylist
    numbers.add(n3) 'Adds to arraylist
    numbers.add(n4) 'Adds to arraylist
    numbers.add(n5) 'Adds to arraylist
    numbers.add(n6) 'Adds to arraylist
    numbers.add(n7) 'Adds to arraylist
    numbers.add(n8) 'Adds to arraylist
    numbers.add(n9) 'Adds to arraylist
    numbers.add(n10) 'Adds to arraylist

    Dim numasc As Threading.Thread = New Threading.Thread(AddressOf ascending) 'sets the number ascending
    numasc.Start() 'starts thread
    Dim numdesc As Threading.Thread = New Threading.Thread(AddressOf descending) 'sets the numbers descending
    numdesc.Start() 'starts thread
End Sub
Public Sub ascending()
    numbers.sort()
    console.writeline("The numbers in sorted ascending order are")
    Print(numbers)
End Sub
Public Sub descending()
    numbers.sort()
    numbers.reverse()
    console.writeline("The numbers in sorted descending order are")
    Print(numbers)
End Sub

End Module

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • 1
    It is an issue of *Scope*: `numbers` is declared in `Sub Main` so that is the only place it exists – Ňɏssa Pøngjǣrdenlarp Jan 18 '17 at 16:43
  • You need to send the ArrayList as a parameter to your function, [here's an example](https://msdn.microsoft.com/en-us/library/6x4c42hc(v=vs.110).aspx). But that might cause problem since your Main will finish before the threads finish. – the_lotus Jan 18 '17 at 16:45

0 Answers0