Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Custom Code Error Expand / Collapse
Author
Message
Posted Thursday, May 9, 2013 4:47 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 19, 2013 11:58 AM
Points: 24, Visits: 54
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.
Post #1451010
Posted Thursday, May 9, 2013 8:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 19, 2013 11:58 AM
Points: 24, Visits: 54
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.
Post #1451167
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse