Click here to Skip to main content
Click here to Skip to main content

VBScript IsTime Function

, 1 Nov 2007
Rate this:
Please Sign up or sign in to vote.
Sample code for IsTime function similar to VBScript's IsDate

Introduction

It may exist, but my limited internet searching talent could not lead me to a VBScript IsTime function similar to the IsDate function provided by VBScript. So, using old technology, a book, I came up with the following example.

Please see Scott Barbour's comment below. As it turns out, IsDate will do this for you.

Background

The book I mentioned above is VBScript Programmer's Reference, 2nd edition. It's an excellent resource and worth the money for anyone who plans to write even a little VBScript.

Using the code

The code seems to work fairly well. However, I have not performed an exaustive unit test so use at your own peril.

The code accepts a time string str and first checks for an empty string. That check probably isn't necessary, but it was there from some previous attempts so I left it. Second, it uses TimeValue to check for a valid time. TimeValue will create a runtime error if the time string is invalid so I turn off the error control switch with On Error Resume Next. I turn the error control switch back on with On Error GoTo 0 when I'm done.

function IsTime (str)
  if str = "" then
    IsTime = false
  else
    On Error Resume Next
    TimeValue(str)
    if Err.number = 0 then
      IsTime = true
    else
      IsTime = false
    end if
    On Error GoTo 0
  end if
end function

Points of Interest

You would think an experienced C++ programmer wouldn't have any trouble with VBScript, but not this guy. Oh well, diversity makes a nerds life interesting. Happy programming!

History

Submitted, 11/01/2007.
Edited, 11/05/2007

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

No Biography provided

Comments and Discussions

 
GeneralIsDate() will do this PinmemberScott Barbour1-Nov-07 6:14 
GeneralRe: IsDate() will do this Pinmembersdkjfhsadlkufjhlawuhfp1-Nov-07 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 1 Nov 2007
Article Copyright 2007 by sdkjfhsadlkufjhlawuhfp
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid