开发者

Report expression help

开发者 https://www.devze.com 2022-12-14 06:22 出处:网络
I am using the following expression in a local report for a WinForms application, but I receive \"#Error\" when the field value is null:

I am using the following expression in a local report for a WinForms application, but I receive "#Error" when the field value is null:

=IIf(Fields!MyField.Value = "", "NULL", Left(Fields!MyField.Value, Len(Fields!MyField.Value) - 2))

I am doing this to strip off a trailing comma and space of the value. The IIf() works, the Left() works, and the Len() works... but not when I add in the "- 2" part of the expression.

I assumed null values (or ZLSs) would be a non-issue开发者_JAVA技巧 since I am pulling them out before the latter half of the expression is evaluated.

Any ideas what might be causing this? Assistance is greatly appreciated!


It looks to me like your inline if is only screening for empty strings, and then assigning the value to null. Null values (and strings of length 1, actually) will break this code.

Try using this:

=IIf(IsNull(Fields!MyField.Value), "NULL", 
(IIf (Len(Fields!MyField.Value) < 2, "SHORT", 
Left(Fields!MyField.Value, Len(Fields!MyField.Value) - 2)))

I added the line breaks for readability. You can use whatever string in place of "SHORT", obviously. This prevents Len(Fields!MyField.Value) - 2 from evaluating to a negative number, which I bet is causing your issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消