Thread: Textbox problem
View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Textbox problem

Confusing Robert. You have used code with the datevalue and said it worked
except for the blanks problem.

are you actually putting in 12.00 instead of 12:00

Anyway, even using the "." this worked:

Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim tmp As String
Dim fSorted As Boolean
Dim sStr As String, sStr1 As String
Dim dti As Date, dtj As Date

' // generates random times in the textboxes - just
'// used for testing
For i = 1 To 6
If Rnd < 0.3 Then
Me.Controls("Textbox" & i).Text = ""
Else
Me.Controls("Textbox" & i).Text = _
Format(Rnd(), "h.mm")
End If
Next
'// remove the above

For i = 1 To 5
For j = i + 1 To 6
sStr = Me.Controls("Textbox" & i)
sStr1 = Me.Controls("Textbox" & j)
If IsDate(sStr) Then
dti = CDate(sStr)
Else
dti = Date + 5000
End If
If IsDate(sStr1) Then
dtj = CDate(sStr1)
Else
dtj = Date + 5000
End If
If dti dtj Then
Me.Controls("TextBox" & i).Text = _
Me.Controls("TextBox" & j).Text
Me.Controls("TextBox" & j).Text = sStr
End If
Next j
Next i

End Sub

--
Regards,
Tom Ogilvy

"Robert Couchman" wrote in message
...
Hello Tom,

thank you for the advice, but im afraid i have a problem.

i cannot use the function DateValue, as i am not using a
date to input into the textboxes, it is actually a number
(e.g. 12.00 for 12o'clock) so i end up with an error, and
if i remove the DateValue function then i end up with my
numbers in the last few textboxes.

can you please help sort out this problem?

Thank you,

Robert Couchman
)