object to long datatype converion

Stimulsoft Ultimate discussion
Post Reply
Vikas
Posts: 20
Joined: Sat Jul 31, 2010 4:12 am
Location: Delhi

object to long datatype converion

Post by Vikas »

Hi

I need to cconvert object datatype to long.

I am using the switch statement like this.

Switch(
DownloadTourMaster.CalculateExpectedDuration=0,
0,
DownloadTourMaster.CalculateExpectedDuration > 0,
DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount
)

In above code DownloadTourMaster.CalculateExpectedDuration is the object datatype. Its showing error as runtime that can't assign object or int to > operator.

Please suggest me. Its very urgent.

Thanks
Vikas
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

object to long datatype converion

Post by Alex K. »

Hello,

You make incorrect comparison of DateTime и Long.
If you wish to compare the field of the DateTime type, then you need to either compare with some default value
(for example 01.01.1900:

Code: Select all

Switch( DownloadTourMaster.CalculateExpectedDuration==DateTime.Parse("01.01.1900"), 0,
 DownloadTourMaster.CalculateExpectedDuration >DateTime.Parse("01.01.1900"), DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount))
or to calculate the amount in days (hours, minutes) and compare with it (Long and Long).

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

object to long datatype converion

Post by Alex K. »

Hello,

You cannot compare different types (in your case the object and long types) This is one of the requirements of the .NET (severe data typification).
You must use the reduction of types.

You may use the following expression:
Switch((long)DownloadTourMaster.CalculateExpectedDuration==0,0,
(long)DownloadTourMaster.CalculateExpectedDuration > 0, DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount)

Thank you.
Vikas
Posts: 20
Joined: Sat Jul 31, 2010 4:12 am
Location: Delhi

object to long datatype converion

Post by Vikas »

Hello Aleksey,

I found the solution. Thanks a lot.


Thanks
Vikas
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

object to long datatype converion

Post by Alex K. »

Ok! Thank you.
Post Reply