SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Custom Code Error


Custom Code Error

Author
Message
Tim Foster
Tim Foster
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 114
I have a function that loops through a recordset doing bespoke customisations. For some reason it appears to have stopped working and I cannot see where the problem is.

Can anyone help?

The code is:
Public Function Localisation(UKString As String) As String

Dim LocalString As New System.Text.StringBuilder(UKString)
Dim i as Integer

If UKString = "" Or IsNothing(UKString) Then
Return UKString
Else
i = 0

For i = 1 to Report.Parameters!Localisations.Count()
If UKString.Contains(Report.Parameters!Localisations.Value(i)) Then
LocalString.Replace(Report.Parameters!Localisations.Value(i).ToString(), Report.Parameters!Localisations.Label(i).ToString())
Exit For
End If
Next i

Return LocalString.ToString()
End If

End Function

It uses a hidden multiselect dataset as the list of customisations, and the sp that produces the set unions a dummy value to ensure that the code always has a set to loop, even if that's just one record. I know this returns data correctly, so the problem isnt the dataset.

The problem is on the LocalString.Replace line, but no matter what I try, I can't get it working again. I had it running previously, but not now.

Any help would be appreciated.
Tim Foster
Tim Foster
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 114
I don't know if I'm allowed to answer my own questions, but I've solved the problem.

The issue is that the Parameters collection is zero based and not 1 based. The error would occur when the customisation was not found, so I changed the for loop to be 0 to Parameters!Localisations.Count() - 1 and everything works nicely.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search