Tuesday, August 6, 2013

Convert Number To Ordinal Number Format In Visual Basic 6

Converting ordinal number in Visual Basic is you only need to create a few If...Else statement that will compare your values and concat the appropriate word to put (th, st, nd, rd and th). Using the function below, you can transform a number to it's corresponding ordinal number format.

Public Function GetOrdinal(Number As String) As String 
    If Number = "11" Or Number = "13" Then 
        GetOrdinal = Number & "th" 
    ElseIf Number = "1" Then 
        GetOrdinal = Number & "st" 
    ElseIf Number = "2" Then 
        GetOrdinal = Number & "nd" 
    ElseIf Number = "3" Then 
        GetOrdinal = Number & "rd" 
    Else: GetOrdinal = Number & "th" 
    End If 
End Function