Sunday, February 12, 2012

Camel Case

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

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

|||

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

|||

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

|||

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

|||

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

|||

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

|||

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

|||

Sorry ,i didn't observe that much keenly.

Thank you Rajiv,Code is Working.

|||

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

No comments:

Post a Comment