|
-
Dec 18th, 2013, 04:00 PM
#1
Thread Starter
New Member
[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.
Last edited by deccoyi; Dec 18th, 2013 at 05:34 PM.
-
Dec 18th, 2013, 04:20 PM
#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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 18th, 2013, 04:39 PM
#3
Thread Starter
New Member
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.
Last edited by deccoyi; Dec 18th, 2013 at 04:57 PM.
-
Dec 18th, 2013, 04:50 PM
#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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 18th, 2013, 04:56 PM
#5
Thread Starter
New Member
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 ??
Last edited by deccoyi; Dec 18th, 2013 at 04:59 PM.
-
Dec 18th, 2013, 05:37 PM
#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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|