954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Palindromes on visual basic 5.0

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
xlilxmexerex
Newbie Poster
2 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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
QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You