0

I worte a code for Palindrom and i am receiving error message could someone tell me where is the mistake is?

thank you.

Dim i As Integer
Dim word As String = wordTextBox.Text
Dim testWord As String
Dim reverseWord As String
Dim testChar As String
Dim maxIndex As Integer

maxIndex = Len(word) - 1
For i = 0 To maxIndex
testChar = Mid(word, i, 1)
If testChar <> " " Then
testWord = testWord & LCase(testChar)

End If

Next i


maxIndex = Len(testWord) - 1
For i = maxIndex To 0 Step -1
reverseWord = reverseWord & Mid(testWord, i, 1)

Next


If testWord = reverseWord Then
MessageBox.Show("The word is palindrome", "Palindrom", MessageBoxButtons.OK, MessageBoxIcon.Information)

Else
MessageBox.Show("The word is not Palindrome.", "Palindrom", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If


wordTextBox.SelectAll()

End Sub

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Teme64
0

I worte a code for Palindrom and i am receiving error message could someone tell me where is the mistake is?

Could you please tell, what error message you get?

When you post your questions here, always include any error messages and/or describe the actual problem as detail as possible. Everyone's willing to help to solve your problem, but nobody has the time to figure out what is the problem. Thank you :)

0

And after fixing your code you could also try this

Try
  If Strings.StrReverse(wordTextBox.Text) = wordTextBox.Text Then
    MessageBox.Show("The word is palindrome", "Palindrom", MessageBoxButtons.OK, MessageBoxIcon.Information)
  Else
    MessageBox.Show("The word is not Palindrome.", "Palindrom", MessageBoxButtons.OK, MessageBoxIcon.Information)
  End If
Catch ex As Exception
  MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.