944,222 Members | Top Members by Rank

Ad:
Jul 31st, 2007
0

Palindromes on visual basic 5.0

Expand Post »
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.


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdStart_Click()
  2. Dim inputWord As String
  3. Dim testWord As String
  4. Dim reverseWord As String
  5. Dim testChar As String
  6. Dim i as Integer
  7. Dim maxIndex as Integer
  8.  
  9.  
  10. 'Get input from the user.
  11. inputWord = InputBox("Please enter your word")
  12.  
  13. 'Record the input in lower case and remove spaces (you can
  14. 'add checks for tabs, linefeeds, etc).
  15. maxIndex = Len(inputWord) - 1
  16. For i = 0 To maxIndex
  17. testChar = Mid(inputWord, i, 1)
  18. If testChar <> " " Then
  19. testWord = testWord & LCase(testChar)
  20. End If
  21. Next
  22.  
  23. 'Reverse testWord.
  24. maxIndex = Len(testWord) - 1
  25. For i = maxIndex To 0 Step -1
  26. reverseWord = reverseWord & Mid(testWord, i, 1)
  27. Next
  28.  
  29. 'Compare reverseWord to testWord and output the results.
  30. If testWord = reverseWord Then
  31. MsgBox "Yes, it's a palindrome"
  32. Else
  33. MsgBox "No, it's not a palindrome"
  34. End If
  35.  
  36.  
  37. 'Get input from the user.
  38. inputWord = InputBox("Please enter your word")
  39.  
  40. 'Record the input in lower case and remove spaces (you can
  41. 'add checks for tabs, linefeeds, etc).
  42. maxIndex = Len(inputWord) - 1
  43. For i = 0 To maxIndex
  44. testChar = Mid(inputWord, i, 1)
  45. If testChar <> " " Then
  46. testWord = testWord & LCase(testChar)
  47. End If
  48. Next
  49.  
  50. 'Reverse testWord.
  51. maxIndex = Len(testWord) - 1
  52. For i = maxIndex To 0 Step -1
  53. reverseWord = reverseWord & Mid(testWord, i, 1)
  54. Next
  55.  
  56. 'Compare reverseWord to testWord and output the results.
  57. If testWord = reverseWord Then
  58. MsgBox "Yes, it's a palindrome"
  59. Else
  60. MsgBox "No, it's not a palindrome"
  61. End If
  62. End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Unverified User
xlilxmexerex is offline Offline
1 posts
since Jul 2007
Aug 1st, 2007
0

Re: Palindromes on visual basic 5.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 :

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim sSQL As String
  2. sSQL=InputBox("Please enter your word")
  3. If Trim(sSQL) <> "" Then
  4. If sSQL = Reverse(sSQL) Then
  5. Msgbox "Palindrome True"
  6. Else
  7. Msgbox "Not A Palindrome"
  8. End If
  9. End If
  10.  
  11.  
  12. REgards
  13. Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to import a background music?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: precison in double variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC