checking if variable is in date format?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

ct976
Newbie
Posts: 7
Joined: Wed Dec 08, 2004 8:08 pm

checking if variable is in date format?

Post by ct976 » Fri Dec 10, 2004 5:07 pm

hi,

here is my situation:

i have a script that goes to a menu item in a screen, and copies the contents.

i use getclipboard> to put it into a variable A

getclipboard>A

if>A is a date format (eg. 8/22/2003 12:00:00 AM)
goto>step1
else
goto>step2
endif


how would i be able to do this? the date always changes, so i am thinking of something that uses wildcards, %like% etc.. i cant use getpixel because the box always remain the same color. how do i detect text?


thanks alot
:idea:

ct976
Newbie
Posts: 7
Joined: Wed Dec 08, 2004 8:08 pm

Post by ct976 » Fri Dec 10, 2004 5:09 pm

also note that i can't copy empty contents, so this doesnt work:

if>A="", step2
step1

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Dec 10, 2004 5:20 pm

Use VBScript's IsDate function:


VBSTART
VBEND

Let>date=8/22/2003
VBEval>IsDate("%date%"),isit
If>isit=True
//whatever
EndIf
MJT Net Support
[email protected]

ct976
Newbie
Posts: 7
Joined: Wed Dec 08, 2004 8:08 pm

Post by ct976 » Fri Dec 10, 2004 5:59 pm

thanks for the quick reply. it seems to be working, up until i get to a record when it is not a date. when its not a date, the clipboard actually contains an excel cell, containing a number.

and i get this error:

Microsoft VBScript compilation error :1033
Unterminated string constant
Line 222. Column 18


could this be an error caused by a cell in excel? but this should still work, since even if it has preceding or trailing memory attached to the number, it is still not a date and the script should continue :?:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Dec 10, 2004 6:09 pm

Seen this before. Something to do with data in Excel at the end of the string. Or it could be a nul string.

Try this:


VBSTART
Function IsItADate(datestring)
if datesting null then
IsItADate = IsDate(Trim(datestring))
else
IsItADate = False
end if
End Function
VBEND

Let>date=8/22/2003
VBEval>IsItADate("%date%"),isit
If>isit=True
//whatever
EndIf


This checks that it is not null and also trims it. Hopefully that solves it.
MJT Net Support
[email protected]

ct976
Newbie
Posts: 7
Joined: Wed Dec 08, 2004 8:08 pm

Post by ct976 » Fri Dec 10, 2004 7:30 pm

excellent!! MJTnet rocks :P

dseibold
Newbie
Posts: 15
Joined: Mon Mar 06, 2006 7:13 pm
Location: Stockton, CA
Contact:

Error Message Confusion

Post by dseibold » Fri May 05, 2006 5:58 pm

I'm using the script shown below... It worked fine for awhile but now I get the following error whenever the VB Script is called:

Microsoft VB Script Compilation Error: 1033
Unterminated string constant
Line 4, Col 25

Can anyone explain this error to me so I can try to get my script running again? I have checked the script syntax very carefully and can find nothing that has changed. I have even recopied the script and reinserted it into my script but I can't get it to run without this error occuring.

support wrote:Seen this before. Something to do with data in Excel at the end of the string. Or it could be a nul string.

Try this:


VBSTART
Function IsItADate(datestring)
if datesting null then
IsItADate = IsDate(Trim(datestring))
else
IsItADate = False
end if
End Function
VBEND

Let>date=8/22/2003
VBEval>IsItADate("%date%"),isit
If>isit=True
//whatever
EndIf


This checks that it is not null and also trims it. Hopefully that solves it.

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 05, 2006 9:51 pm

I don't know much about vbscript but the line:

if datesting null then

has a misspelling of the variable datestring

It seems to me that as long as you have no null data the script will run fine. However, with the misspelled variable always passing the test for not null there might be an error if
IsItADate = IsDate(Trim(datestring))
tries to execute with null data.

just a thought,
Dick

dseibold
Newbie
Posts: 15
Joined: Mon Mar 06, 2006 7:13 pm
Location: Stockton, CA
Contact:

Post by dseibold » Fri May 05, 2006 10:45 pm

I just copied the script from the previous posting - I had corrected the spelling and it was working perfectly but now it won't work at all...

I deleted the function call and my script still works fine but now I have no way to trap any errors that may appear so I really would like to figure out what has caused this problem.

But thanks for trying!

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 05, 2006 11:19 pm

Where is the data coming from? I would think that if the script was working perfectly and the script hasn't changed the logical place to check for corruption is the data.

Tried looking up the error on the Inet. The best expanation I found was that the text string is incorrectly terminated perhaps with an EOF character. Not much help there, except that if the string ends in a non text character for some reason, Macro Scheduler will not accurately process it.

Later,
Dick

dseibold
Newbie
Posts: 15
Joined: Mon Mar 06, 2006 7:13 pm
Location: Stockton, CA
Contact:

Post by dseibold » Sat May 06, 2006 12:06 am

Where is the data coming from?
I'm copying data from the internet... I'll check out the linefeed... maybe that is my problem.

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat May 06, 2006 7:16 am

Try this:

StringReplace>date,CR,,date
StringReplace>date,LF,,date
VBEval>IsItADate("%date%"),isit
If>isit=True
//whatever
EndIf
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

dseibold
Newbie
Posts: 15
Joined: Mon Mar 06, 2006 7:13 pm
Location: Stockton, CA
Contact:

Post by dseibold » Mon May 08, 2006 9:05 pm

I've tried all of the suggestions... Thanks to all of you for helping.
However, I'm getting a message that the field which I know is a date in an MS Access table is not a date!

Here's a portion of my script in which I am looping through my MS Access table looking for the next record that does not have a date in the date field:


VBSTART
Function IsItADate(datestring)
if datestring null then
IsItADate = IsDate(Trim(datestring))
else
IsItADate = False
end if
End Function
VBEND

// MUCH script cut here for ease of understanding.

Label>Loop2
Press CTRL
Send>c
Wait>0.30
Release CTRL
wait>0.30

WaitClipBoard>2
GetClipBoard>test1

StringReplace>test1,CR,,test1
StringReplace>test1,LF,,test1
VBEval>IsItADate("%test%"),isit
messagemodal>%isit%
If>isit=True then
Press Tab * 5
Press Tab * 5
Press Tab * 5
Press Tab * 5
Press Tab * 2
Wait>0.90
Goto>Loop2
ELSE
messagemodal>"FAILED"
Endif


The message is always "FAILED" whether the field has a date in it or not.

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon May 08, 2006 9:55 pm

GetClipBoard>test1

StringReplace>test1,CR,,test1
StringReplace>test1,LF,,test1
VBEval>IsItADate("%test%"),isit
Shouldn't the variable "test" actually be "test1"?

GetClipBoard>test1

StringReplace>test1,CR,,test1
StringReplace>test1,LF,,test1
VBEval>IsItADate("%
test1%"),isit

Later,
Dick

dseibold
Newbie
Posts: 15
Joined: Mon Mar 06, 2006 7:13 pm
Location: Stockton, CA
Contact:

Post by dseibold » Mon May 08, 2006 10:45 pm

JRL wrote:
Shouldn't the variable "test" actually be "test1"?
Later,
Dick
:oops: You caught me in a syntax error! Thanks!

I changed it... but the results are the same...

I still get "FAILED" for dates.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts