I have to write a simple program that checks for a palindrome(a word or sentence that reads the same from right to left and left to right...eye, eve). I have to enter a palindrome sentence into a text box it will check and see if it is a palindrome usind the whil loop statement. Punctuation must also be included. A form is also needed.

This is the code I am using for my palindrome problem but i will not correctly identify palindromes. Does anyone see any problems.

Dim numchar As Integer 'number of chars in phrase
Dim I As Integer 'lcv
Dim ch As Char 'one character in phrase
Dim intchar As Integer 'asc conversion
Dim TempWord As String 'word used while checking going forward

TempWord = ""
strstripped = ""

'trim
strphrase = Trim(strphrase)
numchar = Len(strphrase)

'keep only letters
For I = 1 To numchar
ch = Mid(strphrase, I, 1)
If (Asc(ch) >= 65 And (Asc(ch) <= 90)) Then
TempWord += ch
strstripped = strstripped & ch
numchar = numchar - 1
End If
Next I

strphrase = TempWord

Comments
:)

See if this help :

Dim strTEXT As String
Dim intSTR_LEN As Integer
Dim intCOUNT As Integer
Dim boolPALIN As Boolean

Private Sub Command1_Click()
strTEXT = Text1
boolPALIN = True

strTEXT = Replace(strTEXT, ",", "", , , vbTextCompare)
strTEXT = Replace(strTEXT, ".", "", , , vbTextCompare)
strTEXT = Replace(strTEXT, "'", "", , , vbTextCompare)
strTEXT = Replace(strTEXT, " ", "", , , vbTextCompare)

intSTR_LEN = Len(strTEXT)

If Int(intSTR_LEN / 2) = intSTR_LEN Then
    For intCOUNT = 1 To intSTR_LEN / 2
        If Mid(strTEXT, intCOUNT, 1) <> Mid(strTEXT, intSTR_LEN - (intCOUNT - 1), 1) Then boolPALIN = False
    Next intCOUNT
Else
    For intCOUNT = 1 To (intSTR_LEN / 2) - 1 
        If Mid(strTEXT, intCOUNT, 1) <> Mid(strTEXT, intSTR_LEN - (intCOUNT - 1), 1) Then boolPALIN = False
    Next intCOUNT
End If
If boolPALIN = True Then MsgBox ("The phrase '" & strTEXT & "' is a palindrome!") Else MsgBox ("The phrase '" & strTEXT & "' is NOT palindrome!")
End Sub

try this

dim my_string as string

my_string = "your string goes here..."

if my_string = StrReverse(my_string) then
MsgBox ("This is palindrome!")
end if

Edited 5 Years Ago by debasisdas: n/a

yeah,,i hope you all can see if my make a new thread too..
once again thanks a million :D

yeah,,i hope you all can see if my make a new thread too..
once again thanks a million :D

This question has already been answered. Start a new discussion instead.