pretty complex vba

  Josquius 12:45 24 Mar 2005

What have I done wrong here? I am trying to get excel to recognise times and only accept correct 24 hour clock times though I don't know how to split it into the 3 parts needed.
What I have is (its part of bigger code hence no dims et all)

time = InputBox("Enter the time")
If time = "" Then End
valid = True
For count = 1 To count = 2 Step 1
char = Mid(time, count, 1)
If (char "0" Or char > "9") Then valid = False
Next count
For count = 3 To count = 3 Step 2
char = Mid(time, count, 1)
If (char > ".") Then valid = False
For count = 4 To count = 5 Step 3
char = Mid(time, count, 1)
If (char "0" Or char > "9") Then valid = False

I get some kind of erro saying for is already in use or something along those lines.

  Yoda Knight 13:02 24 Mar 2005

Not getting "For without Next" error ?

  VoG II 13:05 24 Mar 2005

For count = 3 To count = 3 Step 2

for example does not make a lot of sense.

Why not:

Sub GetATime()

Dim TheString As String

Dim TheTime As Double

TheString = Application.InputBox("Enter A Time")

If IsDate(TheString) Then

TheTime = TimeValue(TheString)


MsgBox "Invalid date"

End If

End Sub

  Josquius 13:13 24 Mar 2005

I have for 3 to 3 as just having for 3 brought back a error.
What is a double, I'm not familiar with this. 2 numeric characters?

  VoG II 13:20 24 Mar 2005

It doesn't have to be a double actually, single would do. That's not the point. Why write all that code when you can use the inbuilt function IsDate() to validate the entered time?

  Josquius 13:42 24 Mar 2005

Arg just noticed my lines haven't shown up in my pasted in version...
I don't know about the isdate() function. Does it work for times and not just dates?

  Josquius 13:48 24 Mar 2005

I'm not entirely sure how it works but it seems it does.

  Josquius 14:51 24 Mar 2005

Actually no not resolved, a minor problem- it allows you to put 3 figures after the decimal (15.003 is accepted) though past 3 and it comes up with the error, how do you bring the 3 to just accepting 2?

  Yoda Knight 15:20 24 Mar 2005

check the LEN of TheString ?

  VoG II 15:53 24 Mar 2005


TheString = Application.InputBox("Enter A Time")

TheString = Left(TheString, 5)


This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017