locked
Operator '&' is not defined for type 'String()' and string "

    Question

  • 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()'.
    Thursday, August 21, 2008 6:59 PM

Answers

  • Peager said:

    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()'.

    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. 

    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

    Thursday, August 21, 2008 8:33 PM
  • 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
    Thursday, August 21, 2008 7:51 PM
    Moderator

All replies

  • Use the + rather than &
    Thursday, August 21, 2008 7:33 PM
  • No Joy....

     Operator '+' is not defined for string "Division " and type 'String()'.
    Thursday, August 21, 2008 7:46 PM
  • 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
    Thursday, August 21, 2008 7:51 PM
    Moderator
  • also vbcrlf should be swapped with 

    Environment.NewLine

    Thursday, August 21, 2008 8:10 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:21 PM
  • Peager said:

    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()'.

    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. 

    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

    Thursday, August 21, 2008 8:33 PM
  • Chris,

    Good call.....  stupid, stupid, stupid on my part. 

    Thanks a bunch.
    Thursday, August 21, 2008 10:36 PM