Results 1 to 6 of 6

Thread: Palindrome Part 3

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Illinois
    Posts
    27
    Will this code also pick up punuation in a palindrome sentence? Could If go in place of the While?

    Dim intPosition As Integer
    Dim strText As String
    Dim strResult As String

    strText = txtInput.Text

    While intPosition =< Len(strText)
    intPosition = intPosition + 1
    strResult = Mid(strText, intPosition, 1) & strResult
    Wend

    If strResult = strText Then
    MsgBox "The string is a palindrome!"
    End If
    I'm a MICKEY FAN

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    That routine will pick up all characters contained in the string passed to it, punctuation and all.

    You could also replace the While loop with the strReverse function.

    From MSDN:

    Dim MyStr
    MyStr = StrReverse("VBScript") ' MyStr contains "tpircSBV".

  3. #3
    Guest
    tappling:
    Why are you starting a new thread for each post you want to post under the same topic?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Illinois
    Posts
    27
    I thought so but my instructor wanted us to use an IF statement. I just wanted to be sure so if I changed the While to If would it change the program?
    I'm a MICKEY FAN

  5. #5
    Guest
    Yes it would.
    The code I posted:
    Code:
    Dim intPosition As Integer 
    Dim strText As String 
    Dim strResult As String 
    
    strText = txtInput.Text 
    
    While intPosition =< Len(strText) 
        intPosition = intPosition + 1 
        strResult = Mid(strText, intPosition, 1) & strResult 
    Wend 
    
    If strResult = strText Then 
        MsgBox "The string is a palindrome!" 
    End If
    This code does have an If statement. Just look at the last three lines.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Illinois
    Posts
    27
    Thanks for your help!!
    I'm a MICKEY FAN

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