Thursday, March 13, 2014

SSRS and Numeric Superscripts

They said it couldn't be done. Well I did it.
The below code can be embedded in a SSRS report as custom code. It takes any number and returns the superscript value.

    Function Superscriptify(ByVal number As Integer)
        Dim superscripts As New System.Collections.Generic.Dictionary(Of Integer, Integer)
        superscripts.Add(0, 8304)
        superscripts.Add(1, 185)
        superscripts.Add(2, 178)
        superscripts.Add(3, 179)
        superscripts.Add(4, 8308)
        superscripts.Add(5, 8309)
        superscripts.Add(6, 8310)
        superscripts.Add(7, 8311)
        superscripts.Add(8, 8312)
        superscripts.Add(9, 8313)
        Dim returnString As String = ""
        Do While ((number Mod 10 <> 0) Or (number / 10 > 0))
            Dim remainder As Integer = number Mod 10
            returnString = ChrW(superscripts.Item(remainder)) & returnString
            number = Math.Floor(number / 10)
        Loop
        Return returnString
    End Function


Use as follows (set the expression of a textbox): =Code.Superscriptify(723)
This should result in: 723