1. ## [RESOLVED] Having Trouble about Array Sorting

My english is not well. So I add an image to explain my problem easy.

I need to add numbers (in upper textbox) by inputbox**. But also when user click on SORT, numbers have to written in lower textbox.

Can I assign global values to an array with inputbox ? How ?
**Every click adds only one number.
When i use

Code:
```array.sort(Numberarray)

for i=0 to elementnumber
textbox2.text= cstr(numberarray(i))
next```
it write 0 0 0 0

edit: Now i understand my mistake. it wrote 0 0 0 0 because I created 999 elements array. But Now How can I create an array that have number of elements as the number of clicks.(i am not sure about that sentence )

for example if user entered 4 numbers Array should have 4 elements. How can I Do that ??

I resolve it myself. I'll explain it. maybe it would be useful for others.

I created 999 elements array and I use Arra.sort(arrayname). Then I wrote a For-Next
Code:
```for i=999-(elementnumber+1) to 999
textbox1.text = textbox1.text + cstr(arrayname(i))
next```
basicly When you sort the 999 elements array It will be something like (0,0,0,0...0,0,1,2,4,7,9) then the For-Next wrote the sorted array's last elements in to the textbox.

2. ## Re: Having Trouble about Array Sorting

try this:

Code:
```Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim numbersArray() As Decimal = Array.ConvertAll(TextBox1.Lines.Where(Function(s) Decimal.TryParse(s, New Decimal)).ToArray, Function(s) CDec(Val(s)))
Array.Sort(numbersArray)
TextBox2.Lines = Array.ConvertAll(numbersArray, Function(d) d.ToString)
End Sub

End Class```

3. ## Re: Having Trouble about Array Sorting

i wrote that under Sortbutton_click. Nothing happened

Here is whole code

Code:
```Public Class Form1

Dim NumberArray(999) As Double
Dim elementNumber As Integer

Private Sub AddElementBTN_Click(sender As Object, e As EventArgs) Handles ElemanGirbuton.Click
Static en As Integer  'element number counter
en += 1 'her tıklamada 1 artıyor
NumberArray(en) = InputBox("Eleman Giriniz", "Eleman Giriniz")
txtElementbox.Text = txtElementbox.Text + " " + CStr(NumberArray(en))
elementnumber = en
End Sub

Private Sub SortBTN_Click(sender As Object, e As EventArgs) Handles SiralaBTN.Click

Dim NumberArray() As Decimal = Array.ConvertAll(txtEleman.Lines.Where(Function(s) Decimal.TryParse(s, New Decimal)).ToArray, Function(s) CDec(Val(s)))
Array.Sort(NumberArray)
txtSortbox.Lines = Array.ConvertAll(NumberArray, Function(d) d.ToString)

End Sub
End Class```
edit: Now i understan my mistake. it wrote 0 0 0 0 because I created 999 elements array.

4. ## Re: Having Trouble about Array Sorting

.paul's ever so slightly showy code relies on the numbers entered in the top textbox being each on a separate line.

5. ## Re: Having Trouble about Array Sorting

Hmmm I need to stand side by side with a space " ".

How can I create an array that have number of elements as the number of clicks.(i am not sure about that sentence )
for example if user entered 4 numbers Array should have 4 elements. How can I Do that ??

6. ## Re: [RESOLVED] Having Trouble about Array Sorting

txtEleman.Lines is just an array of strings
you can replace that in my code with any string array, such as txtEleman.Text.Split(" "c)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured