hey
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.
Thanks

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

Recommended Answers

All 4 Replies

see this palindrome program :

Palindrome.zip

don't forget to give feedback.

commented: great +1
commented: peace of code +1

Thanks a lot ! :)

commented: Random Useless Comment On An Old Thread. Taste It. -2

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
Loop


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

End Sub

commented: No Code Tags... Random useless post to an old thread... Taste It. -2

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!"
    Else
        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 :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.