2012-03-09 72 views
1

在报表生成器3.0(例如20124,20125)的报表中,我有一个多值单字符串作为参数字段。现在我想分割这个字符串,并且显示“Summer 2012”而不是“20124”和“2012年秋季”而不是“20125”。我使用Visual Basic。这是我在Report Builder 3.0自定义代码中所做的两个功能。错误是在“If Right(yearterm)...”行中的第二个函数中,它给了我一个语法错误,如果我写“String.Right”,它会给我错误:“'Right'不是如果我拿出整个“If语句”报告将运行但“20124,20125”给我这个:“,2012,2012”。在If语句中使用右函数导致语法错误

我该如何做这项工作?

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 
+3

Please ... indent ... – Ryan 2012-03-09 03:40:06

+2

@ user1258439:你在VBA中做这个吗?我有强烈的感觉,你在vb.net中这样做?我问的原因是因为您正在使用“Dim year = Left(yearterm,4) ”和“返回结果”,它不是VBA/VB6语法。 – 2012-03-09 07:29:11

回答

2

问题是您要将Then s放在不同的行上,并且在0123中有语法错误;它与Right无关 - 除非这是一个复制粘贴错误。

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 
+0

Minitech,哇。谢谢。奇迹般有效。 – 2012-03-09 18:19:18

+0

请检查这个答案,因为这个问题不会导致未答复的部分了。 – Hari 2012-04-20 01:01:43