麻烦与背景颜色区分字母和数字

时间:2018-02-14 11:06:55

标签: reporting-services

我正在尝试根据其内容更改单元格的背景颜色。我们正在考虑成绩,无论是“A到U”还是或	 9到1'。如果等级低于目标等级2,则需要突出显示该单元格。如果单元格只是数字或只是字母而不是两者,我们就可以使用它。

以下是报告的自定义代码:

Public Function gradeCheck(SubjectGrade AS String, TargetGrade AS String) AS String

Dim gradeValue = convertGradeToInt(SubjectGrade)
Dim targetValue = convertGradeToInt(TargetGrade)

If (targetValue - gradeValue) < -1
    Return "Orange"
Else
    Return "White"
End If  
End Function

Public Function gradeCheckInt(SubjectGradeInt AS Integer, TargetGradeInt AS Integer) AS String

If (TargetGradeInt - SubjectGradeInt) >= 2
    Return "Orange"
Else
    Return "White"
End If  
End Function    

Public Function convertGradeToInt(grade AS String) AS Integer

Select Case grade
    Case "A*"
        return 1
    Case "A"
        return 2
    Case "B"
        return 3
    Case "C"
        return 4
    Case "D"
        return 5
    Case "E"
        return 6
    Case "F"
        return 7
    Case "G"
        return 8
    Case "U"
        return 9
End Select
End Function

以下代码适用于自己的数字或自己的字母:

信     = IIF(ISNOTHING(Fields!report_Grade.Value)     ,&#34;怀特&#34;     ,IIF(ISNOTHING(Fields!TargetGrade.Value)         ,&#34;怀特&#34;         ,code.gradeCheck(Fields!report_Grade.Value,Fields!TargetGrade.Value)         )     )

编号

= IIF(ISNOTHING(Fields!report_Grade.Value)
, "White"
, IIF(ISNOTHING(Fields!TargetGrade.Value)
    , "White"
    ,code.gradeCheckInt(Fields!report_Grade.Value, Fields!TargetGrade.Value)
    )
)

这是我觉得应该工作的,但只是突出显示正确的数字,而不是字母:

= IIF(ISNOTHING(Fields!report_Grade.Value)
    , "White"
    , IIF(ISNOTHING(Fields!TargetGrade.Value)
        , "White"
        ,IIF(IsNumeric(Fields!report_Grade.Value)
            ,code.gradeCheckInt(Fields!report_Grade.Value, Fields!TargetGrade.Value)
            ,code.gradeCheck(Fields!report_Grade.Value, Fields!TargetGrade.Value)
        )
    )
)

非常感谢任何帮助。

由于

2 个答案:

答案 0 :(得分:0)

看起来你的成绩总是来自同一列,所以这必须是一个字符串(即使它包含一个数字)。如果是这种情况,那么我会通过测试字符串是否为类似

的值来修改convertGradeToInt函数。
Public Function convertGradeToInt(grade AS String) AS Integer

    If Val(grade) > 0 then
        return Val(grade)
    ELSE

        Select Case grade
            Case "A*"
                return 1
            Case "A"
                return 2
            Case "B"
                return 3
            Case "C"
                return 4
            Case "D"
                return 5
            Case "E"
                return 6
            Case "F"
                return 7
            Case "G"
                return 8
            Case "U"
                return 9
        End Select
    End If
End Function

现在,如果传入的值是数字,则只返回相同的值,如果它是一个字符串,则返回匹配的等级(如果找不到匹配则为零)。

现在你的颜色表达可以很简单

=IIF(Code.convertGradeToInt(Fields!TargetGrade.Value) - Code.convertGradeToInt(Fields!report_Grade.Value) >= 2 , "Orange", Nothing)

您不需要任何其他代码,只需要一个函数和一个颜色表达式。

我可能忽略了一些事情,因为它没有经过测试,但希望它会给你足够的解决问题。

答案 1 :(得分:0)

感谢上面的Alan,我能够让它发挥作用。这是我使用的最终自定义代码:

Here is the final custom code I used:

Public Function gradeCheck(SubjectGrade AS Integer, TargetGrade AS Integer) AS String

If TargetGrade - SubjectGrade >= 2 
    Return "Orange"
Else
    Return "White"
End If  
End Function


Public Function convertGradeToInt(grade AS String) AS Integer

If Val(grade) > 0 then
    return Val(grade)
ELSE

    Select Case grade
        Case "A*"
            return 9
        Case "A"
            return 8
        Case "B"
            return 7
        Case "C"
            return 6
        Case "D"
            return 5
        Case "E"
            return 4
        Case "F"
            return 3
        Case "G"
            return 2
        Case "U"
            return 1
    End Select
End If
End Function

这是颜色表达式:

= IIF(ISNOTHING(Fields!report_Grade.Value)
    , "White"
    , IIF(ISNOTHING(Fields!TargetGrade.Value)
        , "White"
        , code.gradeCheck(Code.convertGradeToInt(Fields!report_Grade.Value), Code.convertGradeToInt(Fields!TargetGrade.Value))
    )
)