Palindromes on visual basic 5.0

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 1
Reputation: xlilxmexerex is an unknown quantity at this point 
Solved Threads: 0
xlilxmexerex xlilxmexerex is offline Offline
Unverified User

Palindromes on visual basic 5.0

 
0
  #1
Jul 31st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Palindromes on visual basic 5.0

 
0
  #2
Aug 1st, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC