Private Function ConvertToLetter(ByVal num As Integer) As String
num = num - 1
If num < 0 Or num >= 27 * 26 Then
ConvertToLetter = "-"
Else
If num < 26 Then
ConvertToLetter = Chr(num + 65)
Else
ConvertToLetter = Chr(num \ 26 + 64) + Chr(num Mod 26 + 65)
End If
End If
End Function
Tag : .NET, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)
Private Function ConvertToLetter(ByVal num As Integer) As String
num = num - 1
If num < 0 Or num >= 27 * 26 Then
ConvertToLetter = "-"
Else
If num < 26 Then
ConvertToLetter = Chr(num + 65)
Else
ConvertToLetter = Chr(num \ 26 + 64) + Chr(num Mod 26 + 65)
End If
End If
End Function
แบบสมัยใหม่ (ควรจะเป็นแบบนี้) Code (VB.NET)
Private Function ConvertToLetter(ByVal num As Integer) As String
num = num - 1
If num < 0 Or num >= 27 * 26 Then
Return = "-"
Else
If num < 26 Then
Return = Chr(num + 65)
Else
Return = Chr(num \ 26 + 64) + Chr(num Mod 26 + 65)
End If
End If
End Function