Using Visual Basic to Identify Palindromic Numbers
A palindrome is a word that is the same both forward and backward. Some numbers are also palindromes. 101 is such a number.
This function, written in Visual Basic, accepts an integer and returns a boolean indicating whether or not the number is a palindrome. The trick is to convert the number to a string, then reverse the string and compare it to the original. If the two strings match, then the original integer is a palindrome.
The function can be placed into any class. Pass the function an integer; it returns a boolean. The return value is "true" if the integer is a palindrome.
'*********************************************************************
'* Determine is an integer is a palindrome *
'* Author: nicomp *
'* Language: Visual Basic *
'*********************************************************************
Function IsPalindrome(ByVal intNum As Integer) As Boolean
Dim str1, str2 As String
Dim i As Integer = 0
Dim blnStatus As Boolean = False
str1 = intNum.ToString
str2 = ""
For i = str1.Length - 1 To 0 Step -1
str2 += str1.Substring(i, 1)
Next
If str1 = str2 Then blnStatus = True
Return blnStatus
End Function
