checking if variable is in date format?
Moderators: Dorian (MJT support), JRL
checking if variable is in date format?
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
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
Use VBScript's IsDate function:
VBSTART
VBEND
Let>date=8/22/2003
VBEval>IsDate("%date%"),isit
If>isit=True
//whatever
EndIf
VBSTART
VBEND
Let>date=8/22/2003
VBEval>IsDate("%date%"),isit
If>isit=True
//whatever
EndIf
MJT Net Support
[email protected]
[email protected]
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
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
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.
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]
[email protected]
Error Message Confusion
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.
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.
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
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
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!
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!
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Try this:
StringReplace>date,CR,,date
StringReplace>date,LF,,date
VBEval>IsItADate("%date%"),isit
If>isit=True
//whatever
EndIf
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
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.
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.