arranging from lowest to highest
hello..can someone help me on how to do my homework..
my teacher ask me to make a program which looks like a calculator..it has buttons 0-9 and a display button..what he want me to do is when i press one of 0-9 button it will be shown in a label box..when i press display button, the numbers in the label will then be sorted and will be shown in the same label box..
ex. label1.caption = 1,5,3,2,4
after pressing the button display this will change the label in a sorted one..
label1.caption = 1,2,3,4,5
thanks..any help will be appreciated..:wave:
Re: arranging from lowest to highest
if i understand you are looking for a sort
Code:
dim t(100)
for i=1 to 100
for x=1 to 99
if t(x)>t(x+1) then
temp=t(x)
t(x)=t(x+1)
t(x+1)=temp
end if
next x
next i
this is called a bubble sort
Re: arranging from lowest to highest
Re: arranging from lowest to highest
hi Don't know if this will help but you can give it a try.
Code:
Private Sub Command1_Click()
Dim nums() As String
Dim x As Integer, y As Integer, tmp As Integer
On Error Resume Next
Label1.Caption = "1,5,3,2,4"
'Split caption into nums array
nums = Split(Label1.Caption, ",")
'Sort nums array
For x = 0 To UBound(nums)
For y = 0 To UBound(nums) - x
If nums(y) > nums(y + 1) Then
tmp = nums(y)
nums(y) = nums(y + 1)
nums(y + 1) = tmp
End If
Next y
Next x
'Rejoin the sorted numbers
Label1.Caption = Join(nums, ",")
End Sub
Re: arranging from lowest to highest
thanks for all the replies..thanks doomfan..your code worked for me..i will just edit the code for my needs..