Having issues with a function to change a parameter value.

Brenda Stewart 96 Reputation points
2020-09-03T20:49:18.04+00:00

I have 2 parameters coming in - one has a job number that has to be reformatted and updated to the other. I wrote a function to do the format because nothing I tried in the expression for the second parameter worked.
Well, it's still not working. The catch is that I have to figure out the position of the "-" in the data. If it's 947- I need to add 2 spaces to the beginning. If it's 1008- I have to add 1 space before it.

Public Shared Function ReFormatJob(NewJobNo as String)
If NewJobNo.IndexOf("-") <=4 Then
NewJobNo = " " & NewJobNo
else
NewJobNo = " " & NewJobNo
End If

End Function

In the parm expression:

=Code.ReFormatJob(Parameters!Job.Value)

I really appreciate any help I can get with this.

Thank you

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Brenda Stewart 96 Reputation points
    2020-09-04T15:09:10.79+00:00

    My boss ended up fixing it.

    This was his solution

    Public Function FormatJob(pJob As String)
    Dim NewJob As String
    Dim J As String
    Dim Pos as Integer
    Dim Part1 as String
    Dim Part2 as String

    J=Trim(pJob)
    Pos=InStr(J,"-")
    
    If Pos=0 Then
        NewJob=Right("     " + J,5) + "-"
    Else
        Part1=Left(J,Pos-1)
        Part2=Mid(J,Pos+1,99)
        NewJob=Right("     " + Part1,5) + "-" + Right("  " + Part2,2)
    End If
    
    Return NewJob
    

    End Function

    2) I changed the Expression values for the two parameters @BeginContract and @EndContract in the Dataset to be: "=Code.FormatJob(Parameters!Job.Value)"

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ZoeHui-MSFT 36,116 Reputation points
    2020-09-04T06:44:43.56+00:00

    Hi,

    I'm not familiar with VB.

    So I tried another way to meet your need without custom code fuction.

    Try the expression:

    =Right(space(10)&left(Parameters!Job.Value,len(Parameters!Job.Value)-1),5)&"-"

    If you have any question, please feel free to let me know.

    If your problem has been solved, please mark "accepted answer" on my reply, thanks for your understanding.

    Regards,

    Zoe


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.