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)
        If str1 = str2 Then blnStatus = True
        Return blnStatus
    End Function

More by this Author

Comments 2 comments

UV 6 years ago

Not gud for starter

nicomp profile image

nicomp 6 years ago from Ohio, USA Author

@UV: sorry!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    Click to Rate This Article