CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2014
    Posts
    7

    isPalendrome function

    Hi folks, just need some help with code :
    need to create a code with isPalendrome function to check if given string is palendrome or not.
    this is my code , something wrong in there. Could you please help?
    thanks.

    Code:
    Function isPalendrome(ByVal Input As String, ByVal Reverse As String) As Boolean
            isPalendrome = (Input = Reverse)
        End Function
    
        Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
            Dim strInput As String
            Dim StrReverse As String
            Dim Outcome As String
    
            strInput = txtString.Text
    
            If Outcome = isPalendrome(strInput, StrReverse) Then
                MsgBox(Outcome, "Is Palindrome!")
            Else
                MsgBox(Outcome, "Is Not Palindrome!")
            End If
    
        End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: isPalendrome function

    No such thing as
    Code:
    Input = Reverse
    The function should just return a FLAG. You are going about it the wrong way. Don't try to reverse the original string. Create a copy, and reverse that.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2014
    Posts
    6

    Re: isPalendrome function

    Here's a function to reverse text if you need one:

    # Private Function Reverse(ByVal Input As String)
    Dim CharNbr As Int16, ReverseString As String
    Dim StringArray() As Char = Input.ToCharArray

    For CharNbr = UBound(StringArray) To 0 Step -1
    ReverseString &= StringArray(CharNbr)
    Next

    Return ReverseString
    End Function
    #

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: isPalendrome function

    That is for numbers, not text
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2014
    Posts
    6

    Re: isPalendrome function

    Not sure I understand you. The original post wanted to reverse a string and that's what the function does.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: isPalendrome function

    My mistake. Sorry.

    You probably get an A+ on the quiz
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured