I am trying to make a program on visual basic 6 to determine weather a
word or phrase is a palindrome or not. I need my program to be able to
tell if the word or phrase is a palindrome and it not being case
sensitive. The code below words to a certin point then brings up an
error but i have no clue why it wont work any help will be appreciated.

I know some things that need to be inculued : arrays and fixed loops and it also needs to take out white spaces.

9 Years
Discussion Span
Last Post by jonc

Dim le
Dim mide
Dim i
Private Sub Command1_Click()
i = 0
Dim yes As Boolean

le = Len(Text1.Text) + 1

Do While i < Len(Text1.Text) - 1
i = i + 1
mide = mid(Text1.Text, i, 1) 'take the next 1 letter in text1.text from position i

If Not mide = mid(Text1.Text, le - i, 1) Then 'if its not the same as the leter i positon from the back then
yes = True
End If

If yes = False Then
MsgBox "Pal"
MsgBox "Not"
End If

End Sub

Votes + Comments
No Code Tags... Random useless post to an old thread... Taste It.

Or... use the strReverse command

Private Sub PalindromeTest(ByVal sWord As String)
    Dim sReversedWord As String

    sReversedWord = StrReverse(sWord)
    If StrComp(sWord, sReversedWord, vbTextCompare) = 0 Then
        MsgBox "Palindrome!"
        MsgBox "Not a Palindrome!"
    End If
End Sub

You could change that to a function and return a boolean value instead of message boxes if you preferred.

Note: Just read the OP again and saw he needs it to use arrays and fixed loops which my example doesn't use. Oh well, I'll post it anyway for reference :)

Edit: sucked into an old thread again... fail :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.