IIF compiling at runtime for both True and False case

testString is of variable type string.
testString=“ABC”
Msgbox(IIf(DateTime.TryParse(testString,dtTest),cdate(testString),testString)) --> Got runtime exception. Cannot convert “ABC” to date type.

testString=“12/11/2019” (MM/dd/yyyy)
Msgbox(IIf(DateTime.TryParse(testString,dtTest),cdate(testString),testString)) --> Got 12/11/2019 00:00:00

For False scenario code at runtime is compiling true case as well and throwing runtime exception.

Hi
welcome to uipath community
as we have used Datetime.TryParse() we need to send valid string with some numeric value atleast
@Lakshay_Verma

Hi @Palaniyappan,

That’s why i am using IIF, so that i can skip true case and go to false.

1 Like

DateTime.TryParse will check only whether the date format is of this or that format or not
But ABC is no way a date first right

Even though we are passing string as argument to TryParse that string must have a date as a value in some date format

Cheers @Lakshay_Verma

DateTime.TryParse(testString) will give Boolean Value True or False

IIF (Condition,“True”,“False”)

yah thats correct but along with that condition we have made this casting like converting a string to datetime, which is why throwing error
DateTime.TryParse(testString,dtTest),cdate(testString),testString)

Cheers @Lakshay_Verma

Understood, but my question here is why it’s going to True Case when output of this tryparse condition is false.

Fine
as these two are same they get matched with dateformat and it goes to TRUE part of if condition
IF(DateTime.TryParse(testString,dtTest,cdate(testString)),testString.ToString,“anyvalue”)

Cheers @Lakshay_Verma

No, If you run this into two modules for example… DateTime.TryParse(testString,dtTest), it will give value as False for using “ABC” but in case of “12/11/2019” it gives true value.

Fine
lets go one by one
what is the value of Teststring and the variable dtTest @Lakshay_Verma

testString=“ABC” and dtTest is DateTime variable type with no value.

hmm… then obvious it would fail right being unmatched and if the testString has any date value as string then it would get matched and goes to the TRUE part of IF condition
@Lakshay_Verma

It will give false, so IIF should go to false statement

It is not how IIF works, it will always evaluate both statements, this is not a uipath error, just the way vb.net compiler works…

1 Like

Thanks @bcorrea
That’s all i need to understand.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.