Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort text box input

Status
Not open for further replies.

bryman

Programmer
Oct 3, 2001
9
0
0
US
I have a project to sort 5 text boxes. Any suggestions of where to start?
 
Hi Bryman,

Could you please give more details.
How is your project working. Where would you place your sorted data etc.

Grt
 
I'm supposed to sort the random numbers in ascending order. The data then would show in a textbox.
 
How do you retrieve this numbers?
Do they come from a database?
How are the textboxes filled with the numbers?
 
I want the user to enter the numbers into 5 text boxes, then the user hits a command button, then the program is to sort the numbers and display the ascended sort into a seperate label box or simply just print on the form.
 
Hi Bryman,

I found a way to do your thing. Perhaps it's possible to find a shorter way but I din't have much time to search.
Here is what I did.


'Make sure that the input in the textbox can only be numeric
'Therefore create a Function (fDecimalSep)
'Put a textbox on your form. Leave the name as Text1.
'Copy it, then paste another textbox onto the form.
'When VB asks if you want to create a control array, say "Yes".

Code begins:

Public Function fDecimalSep() As String
fDecimalSep = Mid$(Format(1234, "###.##"), 5, 1)
End Function


Private Sub Command1_Click()
Dim Small As Single
Dim Teller As Integer
Dim I As Integer
Dim Y As Integer
For Teller = 0 To Text1.Count - 1
For I = 0 To Text1.Count - 1
If Text1(I).Text <> &quot;&quot; Then
Small = Text1(I).Text
For Y = 0 To Text1.Count - 1
If Text1(Y).Text <> &quot;&quot; Then
If Text1(Y).Text < Small Then
Small = Text1(Y).Text
End If
End If
Next Y
End If
Next I
I = 0
For I = 0 To Text1.Count - 1
If Text1(I) <> &quot;&quot; Then
If Small = Text1(I).Text Then
Text1(I).Text = &quot;&quot;
Exit For
End If
End If
Next I

'put numbers in labels
If Label1.Caption = &quot;&quot; Then
Label1.Caption = Small
Else
Label1.Caption = Label1.Caption & &quot;;&quot; & Small
End If
Next Teller
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Select Case KeyAscii
Case vbKey0 To vbKey9, vbKeyBack
'allowed keys -- do nothing
Case Asc(fDecimalSep)
'allows 1 comma in the textbox
If InStr(Text1(Index).Text, fDecimalSep) Then
KeyAscii = 0
End If
Case vbKeyReturn
'Enter key
KeyAscii = 0 'avoids the beep
If Index < Text1.UBound Then
Text1(Index + 1).SetFocus
Else
Text1(Text1.LBound).SetFocus
End If
Case Else
KeyAscii = 0 'discard the keystroke
End Select
End Sub

\code ends

Hope this helps
Good luck
 
Thanks alot for the answer, it really helped!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top