06-15-2015 08:40 AM
I am writing a code to allow users to define what to search for in the navigatro and then use the results for further analysis. However when I try to search by creation date I get an error that says "The argument Value of the method add must be either a date or USiTimeDisp." I've tried many different methods of entering dates, (mm/dd/yyyy , mm.dd.yyyy etc.) however none have worked.
What does this error mean and how can I correct it?
Solved! Go to Solution.
06-15-2015 09:58 AM
The add method does not accept a string but only CDate or UsiTimeDisp.
Creating usiTimeDisp
dim cdateVal : cdateVal = now dim timedispVal : set timedispVal = createTime(year(cdateVal), month(cdateVal), day(cdateVal), hour(cdateVal), minute(cdateVal), second(cdateVal))
In this case I started with a CDate that I created using now.
So how to get a CDate from a string. Here we meet the locale problem.
English : 22.08.1970 10:22:30
German : 08/22/1970 10:22:30
which is also relected by converting a CDate to string.
Option Explicit dim cdateVal : cdateVal = now dim strVal : strVal = CStr(cdateVal) MsgBox strVal dim cDateVal2 : cDateVal2 = CDate(strVal) msgBox cDateVal2
This code will work. It is capable to convert a CDate into a CStr and afterwards back into CDate. This works if the time string is formatted like expected by your locale setting.
CDate("22.08.1970 10:22:30")
will work in germany but will fail in the US.
dim diademtimeVal : diademtimeVal = TTR("22.08.1970 22:30", "dd.mm.yyyy hh:nn:ss") dim timedispVal : set timedispVal = createTime(0, 0, 0, 0, 0, 0) timedispVal.SecondsFrom0000 = diademtimeVal
will create you a usitimedisp object using a fixed format string. This should solve your request.
06-15-2015 10:05 AM
Worked perfectly. Thank you!