checking if variable is in date format?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon May 08, 2006 11:59 pm

From your original posting:
And it it great doing what is was designed to do.
What type of contents do you get if not a date? Text, numbers, time, currency, other?

Can you provide examples?

If a date will it always/never have leading zeros on month/day?

Solution could be done by checking for poisitions of "/" and ":" and AM/PM, vs. converting into actual date.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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

Post by JRL » Tue May 09, 2006 5:08 am

dseibold,
I had some time tonight to play around with this. I'm suspecting that if this was working for you, you were using the originally posted vbscript. No matter what I tried I could not make the "trimming vbscript" work. Since the original poster was taking data from excel, that's what I tried also.

What I tried tonight that worked was:
- open Excel
- type a date into the A1 cell
- use ddrequest to place that date into a variable
- use Marcus' suggestion to remove the CR LF from the date
- run the original vbscript.

This is the script that worked for me. Open Excel "book1.xls", type a date into the A1 cell, then step through the following script with the watchlist open to see what happens. Then type text other than a date into cell A1 of book1.xls and step through the script with the watchlist open and see what happens. Remember that to use DDERequest the file being read must be open.



DDERequest>Excel,Book1.xls,R1C1,date,5

StringReplace>date,CR,,date
StringReplace>date,LF,,date
VBSTART
VBEND

VBEval>IsDate("%date%"),isit
If>isit=True
//whatever
EndIf


Hope this makes sense,
Dick

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

Post by dseibold » Tue May 09, 2006 5:38 pm

No, I was not using the originally posted vbscript... I was using the Trim version. I have no idea why it was working at one time...

I used your suggestions and everything works fine ... except ...

Here is the script portion I am working with now...

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>IsDate("%test1%"),isit

If>isit=False
messagemodal>%isit%
Goto>Jump2
Endif

Press Down
Goto>Loop2
Label>Jump2

messagemodal>"Hurrah"
Goto>ScriptEnd

In this script if I begin with a blank MS Access field, isit comes back as False.
If I begin with a MS Access field with a valid date, it comes back True (as expected). It then goes down to the next record and repeats the loop. When it gets to a blank field, it continues to come back True instead of False.

I tried Let>isit=False at the beginning of the loop but it continues to come back True.

I really do appreciate all of the help I'm receiving.

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

Post by JRL » Tue May 09, 2006 6:26 pm

When it gets to a blank field, it continues to come back True instead of False.

I tried Let>isit=False at the beginning of the loop but it continues to come back True.


Your problem is that the date is still in the clipboard. you need to clear the clipboard each time through. Try adding the line PutClipBoard>null. The word "null" will test false and will be what is analysed after your CTRL+C reads a blank field rather than the previously CTRL+C'ed date.

Hope this makes sense,
Dick

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

Post by dseibold » Tue May 09, 2006 6:57 pm

:D

Dick,

THANKS!!!!

I'm back up and running and tickled pink!

You're a lifesaver!

David

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