1

我在 Report Builder 3.0 中的报告中有一个多值单字符串作为参数字段(例如 20124、20125)。现在我想拆分这个字符串,并显示“Summer 2012”而不是“20124”和“Fall 2012”而不是“20125”。我使用的是 Visual Basic。这是我在 Report Builder 3.0 自定义代码中创建的两个函数.错误出现在“If Right(yearterm)...”行的第二个函数中。它给了我一个语法错误。如果我写“String.Right”它给我错误:“'Right' is not a 'String' 的成员”。如果我取出整个“If 语句”,报告将运行,但“20124,20125”给我这个:“, 2012, 2012”。

我怎样才能使这项工作?

Public Function SplitParameterValues(ByVal parameter As Parameter) As String
    Dim result As String
    Dim a(0 To 10) As String
    a = Split(parameter.Value, ",")

    For i As Integer = 0 to a.length - 1
        result = result +", "  + YearTermTranslation(a(i))
    Next

    Return result
End Function

Public Function YearTermTranslation(ByVal yearterm As String) As String
    Dim result As String
    Dim term As String
    Dim year = Left(yearterm, 4)

    If Right(yearterm, 1) = 5
    Then term = "Fall"
    Else If Right(yearterm, 1) = 4
    Then term = "Summer"
    Else If Right(yearterm, 1) = 3
    Then term = "Spring"
    Else term = "Winter"
    End If

    result = term + " " + year

    Return result
End Function
4

1 回答 1

2

问题是您将Thens 放在单独的行中,并且 ; 中存在语法错误ElseRight它与- 除非这是复制粘贴错误无关。

Public Function YearTermTranslation(ByVal yearterm As String) As String
    Dim result As String
    Dim term As String
    Dim year = Left(yearterm, 4)

    If Right(yearterm, 1) = 5 Then
        term = "Fall"
    ElseIf Right(yearterm, 1) = 4 Then
        term = "Summer"
    ElseIf Right(yearterm, 1) = 3 Then
        term = "Spring"
    Else
        term = "Winter"
    End If

    result = term + " " + year

    Return result
End Function

哦,如果这实际上是 VB.NET……请学习 VB.NET。

Public Function SplitParameterValues(ByVal parameter As Parameter) As String
    Dim result As String = String.Empty
    Dim a() As String = parameter.Value.Split(","c)

    For i As Integer = 0 To a.length - 1
        result &= ", " & YearTermTranslation(a(i))
    Next

    Return result
End Function

Public Function YearTermTranslation(ByVal yearterm As String) As String
    Dim term As String
    Dim year As String = yearterm.Substring(0, 4)

    Select Case yearterm(yearterm.Length - 1)
        Case "5"c
            term = "Fall"
        Case "4"c
            term = "Summer"
        Case "3"c
            term = "Spring"
        Case Else
            term = "Winter"
    End Select

    Return term & " " & year
End Function
于 2012-03-09T03:44:28.787 回答