ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software

Using Visual Basic to Identify Palindromic Numbers

Updated on May 2, 2009

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


    0 of 8192 characters used
    Post Comment

    • nicomp profile image

      nicomp really 7 years ago from Ohio, USA

      @UV: sorry!

    • profile image

      UV 7 years ago

      Not gud for starter