locked
Camel Case RRS feed

  • Question

  • I need to display text in camel case e.g. How Are You....Because of some deign limitation i can't make chnages in my SP. So i need to do it ar SSRS end....Pl let me know if y know the ans...Thanks

    Thursday, May 31, 2007 12:50 AM

Answers

  • Looks like the data in your field is already uppercase.  This will uppercase the first letter, and lowercase the rest.  I think Rajiv missed the part in red in his first post.

     

    Try this:

     

    Code Snippet

    Public Function ConvertToCamelCase(inputStr) as String

    dim inputStrArr

    dim tempWord

    dim outputStr

    dim i

    inputStrArr = Split(inputStr, " ")

     

    for i = 0 to UBound(inputStrArr)

      tempWord = inputStrArr(i)

      tempWord = UCase(Left(tempWord, 1)) & LCase(Right(tempWord, len(tempWord) - 1))

      if outputStr = "" then

        outputStr = tempWord

      else

        outputStr = outputStr & " " & tempWord

      end if

    Next

     

    return outputStr

    End Function

     

     Then, you can use this in your field's expression.

     

    Code Snippet
    =code.ConvertToCamelCase(Fields!salesman_name.Value)

     

    Hope this helps.

     

    Jarret

    Thursday, May 31, 2007 1:47 PM

All replies

  • Hi Amit,

    You can write custom code(embedded code) to distplay the text in Came Case. To do so, go to Report --> Report properties -->  Code tab and then write a function that will convert the input text to camel case as required.

     

    The Function for this purpose is shown below

     

    Code Snippet

    Public Function ConvertToCamelCase(inputStr) as String
      dim inputStrArr
      dim tempWord
      dim outputStr
      dim i
     inputStrArr = split(inputStr," ")

    for i=0 to UBound(inputStrArr)
      tempWord =inputStrArr(i)
      tempWord = Ucase(Left( tempWord ,1)) & Right(tempWord,len(tempWord) -1)
      if outputStr="" then
       outputStr =tempWord
      else
       outputStr = outputStr & " " & tempWord

     end if

     Next 
     return outputStr
     End Function

     

     

    Then right click on the cell where u want to print this string and enter the following expression

    Code Snippet

    =Code.ConvertToCamelCase("how are you")

     

    Hope it helps.

     

    Rajiv

     

     

     

     

    Thursday, May 31, 2007 3:53 AM
  • public function tocamelcase(inputstring) as string
    dim inputstrarr
    dim outputstr
    dim tempstr
    dim i
    inputstrarr=split(inputstring," ")
    for i=0 to UBound(InputStrArr)
     tempstr=InputstrArr(i)
     tempstr=UCase(left(tempstr,1)) & lcase(right(tempstr,len(tempstr)-1))
     if outputstr=" "  then
      outputstr=tempstr
     Else
       outputstr=outputstr & " " & tempstr
     End if
    Next
    return outputstr
    End fuction

     

    It is throwing Error

    An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC30289] Statement cannot appear within a method body. End of method assumed.’.

     

    Can you please corrrect this

     

    Thank you

    Raj Deep.A

     

    Thursday, May 31, 2007 6:22 AM
  • Hi Raj Deep,

    The above error is occuring because of the Typo error in the code. It should be End Function and not End fuction. I have rectified the error below.

     

    Code Snippet

    public function tocamelcase(inputstring) as string
    dim inputstrarr
    dim outputstr
    dim tempstr
    dim i
    inputstrarr=split(inputstring," ")
    for i=0 to UBound(InputStrArr)
     tempstr=InputstrArr(i)
     tempstr=UCase(left(tempstr,1)) & lcase(right(tempstr,len(tempstr)-1))
     if outputstr=" "  then
      outputstr=tempstr
     Else
       outputstr=outputstr & " " & tempstr
     End if
    Next
    return outputstr
    End function

     

    Best Regards,

    Rajiv

    Thursday, May 31, 2007 7:54 AM
  • I am not able to perform below step

    =Code.ConvertToCamelCase("how are you")

    As soon as i type =Code. (i can't see custom function in the list)....Any comments...

     

    Amit

    Thursday, May 31, 2007 10:32 AM
  • Hi Amit,

     

    It is O.K. even if the custom function doesn't appear in the list, type it manually and the report should work fine.

     

    Though I am not sure why it doesn't come in the list, even I didn't get my function to come in the list.

     

    Rajiv

    Thursday, May 31, 2007 10:38 AM
  • ya i tried and it is not working....

     

    =code.ConvertToCamelCase(Fields!salesman_name.Value)...

     

    It's showing in upper case only...

     

    Thanks for your help

    Thursday, May 31, 2007 11:02 AM
  •  

    ya i tried and it is not working....

     

    =code.ConvertToCamelCase(Fields!salesman_name.Value)...

     

    It's showing in upper case only...

     

    Thanks for your help

    Thursday, May 31, 2007 11:10 AM
  • Sorry ,i didn't observe that much keenly.

    Thank you Rajiv,Code is  Working.

    Thursday, May 31, 2007 11:48 AM
  • Looks like the data in your field is already uppercase.  This will uppercase the first letter, and lowercase the rest.  I think Rajiv missed the part in red in his first post.

     

    Try this:

     

    Code Snippet

    Public Function ConvertToCamelCase(inputStr) as String

    dim inputStrArr

    dim tempWord

    dim outputStr

    dim i

    inputStrArr = Split(inputStr, " ")

     

    for i = 0 to UBound(inputStrArr)

      tempWord = inputStrArr(i)

      tempWord = UCase(Left(tempWord, 1)) & LCase(Right(tempWord, len(tempWord) - 1))

      if outputStr = "" then

        outputStr = tempWord

      else

        outputStr = outputStr & " " & tempWord

      end if

    Next

     

    return outputStr

    End Function

     

     Then, you can use this in your field's expression.

     

    Code Snippet
    =code.ConvertToCamelCase(Fields!salesman_name.Value)

     

    Hope this helps.

     

    Jarret

    Thursday, May 31, 2007 1:47 PM
  • Jarret/Rajiv,

     

    Thanks for sharing the function. It works out great. However, it seems that if I tried to convert data that has numbers in it, it will gives me error. I'm trying to change like an address field (i.e. 1245 W. ADAMS to 1245 W. Adams). Have you came across this or any solution for this? Thanks.

     

    Monday, May 5, 2008 3:25 PM
    Answerer
  • Hello Isham,

     

    Can you post the code function you used, the expression you are using to display it on the report, and any errors/warnings you are getting?

     

    I ran your address string with the function exactly as it is in my last post, and it displayed correctly.

     

    Jarret

     

    Monday, May 5, 2008 3:45 PM
  • Jarret,

    Thanks for the quick reply. You know what, I did try what you said and it did not gives any error. So, the function will handle numbers. So it was something else that giving me this error. The function is exactly the same as what you posted, only I change the function name to TitleCase instead of CamelCase. Here is the expression:

     

    =Fields!Vendor.Value + chr(10) + code.ConvertToTitleCase(Fields!Addr1.Value) + iif(Len(Fields!Addr2.Value)=0,chr(10),chr(10) + Fields!Addr2.Value + chr(10)) + code.ConvertToTitleCase(Fields!City.Value) + ", " + Fields!State.Value + " " + Fields!ZipCode.Value

     

    The error message that I got is:

     

    [rsRuntimeErrorInExpression] The Value expression for the textbox ‘textbox6’ contains an error: Argument 'Length' must be greater or equal to zero.

     

    The output should look something like this:

    ABC Company

    12345 W. Adams, Suite 2001

    Chicago, IL 60606

     

    Any ideas? Thanks.

    Monday, May 5, 2008 4:00 PM
    Answerer
  • Isham,

     

    I think your problem is due to one of the fields that you are passing to the function is NULL.

     

    You'll need to make a small change to the function (marked in red).

     

    Code Snippet

    Public Function ConvertToTitleCase(inputStr) as String
    dim inputStrArr
    dim tempWord
    dim outputStr
    dim i
    inputStrArr = Split(inputStr, " ")

     

    if len(inputStr) = 0
      return ""
    end if

     

    for i = 0 to UBound(inputStrArr)
      tempWord = inputStrArr(i)
      tempWord = UCase(Left(tempWord, 1)) & LCase(Right(tempWord, len(tempWord) - 1))
      if outputStr = "" then
        outputStr = tempWord
      else
        outputStr = outputStr & " " & tempWord
      end if
    Next

     

    return outputStr
    End Function

     

     

    Hope this helps.

     

    Jarret

    Monday, May 5, 2008 5:25 PM
  • Jarret,

     

    Thanks for the revision. However, it's not the functions problem, but merely the data problem. What happen was the data that I'm feeding has a padding spaces at the end but just can't see it when running it in Query Analyzer (or Management Studio). That is why I got error on the length. So, what I did was removed the spaces (using rtrim) before passing it to the function and it work like a charm. Thanks again for your help.

     

    Monday, May 5, 2008 8:42 PM
    Answerer
  • Hello Isham,

     

    Sorry, I didn't even think about multiple consecutive spaces or trailing spaces causing issues.  I think this code will work as you need it to.  You shouldn't have to modify your data in order to get this to work.


    Code Snippet

    Public Function ConvertToCamelCase(inputStr) as String
    dim inputStrArr
    dim tempWord
    dim outputStr
    dim i
    inputStrArr = Split(inputStr, " ")

     

    for i = 0 to UBound(inputStrArr)
      tempWord = inputStrArr(i)

     

      if len(tempWord) > 0
        tempWord = UCase(Left(tempWord, 1)) & LCase(Right(tempWord, len(tempWord) - 1))
        if outputStr = "" then
          outputStr = tempWord
        else
          outputStr = outputStr & " " & tempWord
        end if
      end if
    Next

     

    return outputStr
    End Function

     

     

    Hope this helps.

     

    Jarret

    Thursday, May 8, 2008 6:14 PM
  • Yes, you can Camel case by using 

    =StrConv(Fields!Name.Value,3)

    which is very straight forward, no need of writing VB Code Snippet

    Above will convert all the words to camel case, But in some case if you want like this

    New York (NY)

    means use this:

    =StrConv(Left(Fields!Name.Value, InStr(Fields!Title.Name, "(") - 1), 3)
      & Right(Fields!Name.Value, InStr(StrReverse(Fields!Name.Value), "("))

    • Proposed as answer by Jai Anand Wednesday, April 8, 2015 12:59 PM
    • Unproposed as answer by Jai Anand Wednesday, April 8, 2015 12:59 PM
    • Proposed as answer by Jai Anand Wednesday, April 8, 2015 12:59 PM
    Wednesday, April 8, 2015 12:58 PM