473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Palindrome code for Visual Basic 5.0

Hiya
I was woundering if anyone could help me. A few weeks ago i started using vb 5.0 and now im trying to make a code to determine if a word is a palindrome or not. The code that i have tried dose not work and i was woundering if any one could help.
Thanks

Private Sub cmdStart_Click()

Dim inputWord As String
Dim reverseWord As String

inputWord = InputBox("Please enter your word")

If inputWord = reverseWord Then

MsgBox "Yes, it's a palindrome"

Else

MsgBox "No, it's not a palindrome"

End If

End Sub
Jul 26 '07 #1
2 13624
Your first problem is that you do not set reverseWord to anything in your code. You can also make your program a bit more robust by eliminating whitespace and case from the comparison. That will allow multiword palindromes like "Oozy rat in a sanitary zoo" to be tested. I'm not familiar with VB 5.0 and VB.Net has a lot of built-in functionality to do this but the following code should work (I haven't tested it and, if VB 5 uses 1 based indexing, you'll need to change the indexing in the loops):

Expand|Select|Wrap|Line Numbers
  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 = 0
  7.    Dim maxIndex as Integer = 0
  8.  
  9.    '--Get input from the user.
  10.    inputWord = InputBox("Please enter your word")
  11.  
  12.    '--Record the input in lower case and remove spaces (you can
  13.    '--add checks for tabs, linefeeds, etc).
  14.    maxIndex = Len(inputWord) - 1
  15.    for i = 0 to maxIndex
  16.       testChar = Mid(inputWord, i, 1)
  17.       if testChar <> " " then
  18.          testWord = testWord & LCase(testChar)
  19.       end if
  20.    next
  21.  
  22.    '--Reverse testWord.
  23.    maxIndex = Len(testWord) - 1
  24.    for i = maxIndex to 0 Step -1
  25.       reverseWord = reverseWord & Mid(testWord, i, 1)
  26.    next
  27.  
  28.    '--Compare reverseWord to testWord and output the results.
  29.    If testWord = reverseWord Then
  30.       MsgBox "Yes, it's a palindrome"
  31.    Else
  32.       MsgBox "No, it's not a palindrome"
  33.    End If
  34. End Sub
Good luck,
Michael Bailey
Jul 26 '07 #2
Killer42
8,435 Expert 8TB
I was woundering if anyone could help me. A few weeks ago i started using vb 5.0 and now im trying to make a code to determine if a word is a palindrome or not. The code that i have tried dose not work and i was woundering if any one could help.
Not sure whether it existed in VB version 5, but here's a quote from the VBA documentation...

the StrReverse Function

Description

Returns a string in which the character order of a specified string is reversed.
Jul 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: John | last post by:
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it...
4
by: LCAdeveloper | last post by:
I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0 and am now starting to re-write our code. I was a bit surprised to find that Visual Basic.NET no longer supports fixed length...
0
by: Dr. Zharkov | last post by:
Hello. To see the graphics of technology DirectX 9.0 SDK Update - June 2005 in project Visual Basic, WindowsApplication1 from Visual Studio 2005 Beta 1, in file My Project, MyApplication.vb in a...
2
by: elnahrawi | last post by:
Download ebook http://books-download.com/?Book=1487-Visual+Basic+2005+Jumpstart Okay, all you VB6 developers--time's up. As of March 2005, Microsoft no longer supports this version of Visual...
4
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
1
by: praful pathak | last post by:
i i am praful pathak,porbandar i want to develop my own cross tab report in visual basic 6 i know what developed query from ms access but how to coded in visual basic in designing time and how to...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
2
by: sbweld | last post by:
Hello, I am using Powerpoint 2007 and have found an option to integrate visual basic code into the slides. I am building a standalone Kiosk and I want my powerpoint presentation to reset and go...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
11
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have seen the terms Visual Basic 2005 and VB.NET. It seems that sometimes they seem to be referring to the same thing but sometimes they are not. I also run into terms like VB9 and VB10.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.