DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Argument Value of the method add must be either a date or UsiTimeDisp.

Solved!
Go to solution

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? 

0 Kudos
Message 1 of 3
(4,578 Views)
Solution
Accepted by topic author Artemis125

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.

 

Message 2 of 3
(4,571 Views)

Worked perfectly. Thank you!

0 Kudos
Message 3 of 3
(4,568 Views)