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

  • The Importance of Doing Laundry

    We could nag, but this is better. It is less work for us to use the words of others to emphasize the importance of doing laundry. Besides, if you saw the way we dressed, you'd laugh your mouse off.

  • Data Hiding in Java

    Data Hiding is an aspect of Object Oriented Programming (OOP) that allows developers to protect private data and hide implementation details. In this tutorial we examine basic data hiding techniques in Java.

  • Introduction to Windows Notepad

    A useful text editor is an essential component of any personal computer. Every day we need to make notes, compose documents, and record vital pieces of information. We depend on our text editor. Microsoft provided...

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