Operator '&' is not defined for type 'String()' and string "
-
Thursday, August 21, 2008 6:59 PM
I have been getting the this error in the following script used to set the report title in MS Reporting Services. I have tried everything I can think of to no avail. Can someone point me in the right direction?= IIF(Parameters!DivList.Count > 1, Join(Parameters!DivList.Value,",") , Parameters!DivList.Label) & vbCrLf & "General Ledger Audit" & vbCrLf & "From " & Parameters!BegPer.Label & " " & cStr(Parameters!EndYear.Value) & " Thru " & Parameters!EndPer.Label & " " & cStr(Parameters!EndYear.Value)
By changing the code to what I really want,= IIF(Parameters!DivList.Count > 1, "Divisions " & Join(Parameters!DivList.Value,",") , "Division " & Parameters!DivList.Label) & vbCrLf & "General Ledger Audit" & vbCrLf & "From " & Parameters!BegPer.Label & " " & cStr(Parameters!EndYear.Value) & " Thru " & Parameters!EndPer.Label & " " & cStr(Parameters!EndYear.Value)
the error changes slightly:
Operator '&' is not defined for string "Division " and type 'String()'.
All Replies
-
Thursday, August 21, 2008 7:33 PMUse the + rather than &
-
Thursday, August 21, 2008 7:46 PMNo Joy....
Operator '+' is not defined for string "Division " and type 'String()'.
-
Thursday, August 21, 2008 7:51 PMModerator
Rather than chucking everything on one line, create separate variables so you can see exactly what's causing the problem. It looks like, though, Parameters!DivList.Label is not a string (whatever that is).
Edit: oh, and the '&' symbol is fine.
Stephen J Whiteley- Edited by SJWhiteleyModerator Thursday, August 21, 2008 7:52 PM edit
- Marked As Answer by Riquel_DongModerator Monday, August 25, 2008 7:49 AM
-
Thursday, August 21, 2008 8:10 PMalso vbcrlf should be swapped with
Environment.NewLine
-
Thursday, August 21, 2008 8:21 PM
Hmmmmm.... The following similar code works fine.... I guess I'll just have to take it apart.... looks like some esoteric bug to me...="Trial Balance Worksheet" & vbCrLf & IIF(Parameters!MonthOrYear.Value="M", "For ", "YTD ") & rTrim(Parameters!Per.Label) & " / " & Parameters!Year.Value & vbCrLf & IIF(Parameters!DivList.Count = 1, "For " & Parameters!DivList.Label (0), "Divisions " & Join(Parameters!DivList.Value,",")) -
Thursday, August 21, 2008 8:33 PM
Peager said:The second error would seem to occur because Parameters!DivList.Label is not a string, but a string array as indicated by the error. You can't concatenate a string and a string array using the & operator.I have been getting the this error in the following script used to set the report title in MS Reporting Services. I have tried everything I can think of to no avail. Can someone point me in the right direction?
= IIF(Parameters!DivList.Count > 1, Join(Parameters!DivList.Value,",") , Parameters!DivList.Label) & vbCrLf & "General Ledger Audit" & vbCrLf & "From " & Parameters!BegPer.Label & " " & cStr(Parameters!EndYear.Value) & " Thru " & Parameters!EndPer.Label & " " & cStr(Parameters!EndYear.Value)
By changing the code to what I really want,= IIF(Parameters!DivList.Count > 1, "Divisions " & Join(Parameters!DivList.Value,",") , "Division " & Parameters!DivList.Label) & vbCrLf & "General Ledger Audit" & vbCrLf & "From " & Parameters!BegPer.Label & " " & cStr(Parameters!EndYear.Value) & " Thru " & Parameters!EndPer.Label & " " & cStr(Parameters!EndYear.Value)
the error changes slightly:
Operator '&' is not defined for string "Division " and type 'String()'.
Your final example seems to compile because you are accessing the first element in the array which is a string: Parameters!DivList.Label(0) so the & operator is happy.
I agree with SJWhitley. Your code is very hard to read. When a line of code gets this complicated, it's better to break it up into several separate lines so that it is easier to understand.
Chris- Marked As Answer by Riquel_DongModerator Monday, August 25, 2008 7:49 AM
-
Thursday, August 21, 2008 10:36 PMChris,
Good call..... stupid, stupid, stupid on my part.
Thanks a bunch.

