Hiya
I am trying to make a program on visual basic 5.0 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.

Private Sub cmdStart_Click()
   Dim inputWord As String
   Dim testWord As String
   Dim reverseWord As String
   Dim testChar As String
   Dim i as Integer 
   Dim maxIndex as Integer 

 
   'Get input from the user.
   inputWord = InputBox("Please enter your word")

   'Record the input in lower case and remove spaces (you can
   'add checks for tabs, linefeeds, etc).
   maxIndex = Len(inputWord) - 1
   For i = 0 To maxIndex
      testChar = Mid(inputWord, i, 1)
      If testChar <> " " Then
         testWord = testWord & LCase(testChar)
      End If
   Next

   'Reverse testWord.
   maxIndex = Len(testWord) - 1
   For i = maxIndex To 0 Step -1
      reverseWord = reverseWord & Mid(testWord, i, 1)
   Next

   'Compare reverseWord to testWord and output the results.
   If testWord = reverseWord Then
      MsgBox "Yes, it's a palindrome"
   Else
      MsgBox "No, it's not a palindrome"
   End If


   'Get input from the user.
   inputWord = InputBox("Please enter your word")

   'Record the input in lower case and remove spaces (you can
   'add checks for tabs, linefeeds, etc).
   maxIndex = Len(inputWord) - 1
   For i = 0 To maxIndex
      testChar = Mid(inputWord, i, 1)
      If testChar <> " " Then
         testWord = testWord & LCase(testChar)
      End If
   Next

   'Reverse testWord.
   maxIndex = Len(testWord) - 1
   For i = maxIndex To 0 Step -1
      reverseWord = reverseWord & Mid(testWord, i, 1)
   Next

   'Compare reverseWord to testWord and output the results.
   If testWord = reverseWord Then
      MsgBox "Yes, it's a palindrome"
   Else
      MsgBox "No, it's not a palindrome"
   End If
End Sub

Hi,

u can simply use the "Reverse" function. I'am not sure if Reverse function is available in VB5 or not, but we have it in VB6. Check this :

Dim sSQL As String
sSQL=InputBox("Please enter your word")
If Trim(sSQL) <> "" Then
  If sSQL = Reverse(sSQL) Then
      Msgbox "Palindrome True"
  Else
     Msgbox "Not A Palindrome"
  End If
End If

 
REgards
Veena
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.