Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am working on a this programming project for class using Visual Basic 2010. I tryed coding it with the code bellow and it doesnt work. Could someone please help me with it. Thanks!
This is the question:
Write a program that allows the user to input a word or phrase and then determine if it is a palindrome. The program should use a Boolean-valued Function procedure named IsPalindrome that returns the value True when the word or phrase is a palindrome and the value False otherwise.
Your program should also include the following:
• Sub Procedure for Getting the input
• Sub Procedure for Validating the input
• Sub Procedure for Displaying the output
• Proper internal documentation
• Complete External Documentation (Method of choice for describing the Solution)

This is the code I have got so far:
VB
Private Sub btnCheck_Click(sender As System.Object, e As System.EventArgs) Handles btnCheck.Click
        Dim strword As String
        Dim intindex As Integer
        Dim strarr() As String
        If Not IsGoodInput(strword) Then
            Exit Sub
        End If
        ReDim Preserve strarr(intindex)
        strarr(intindex) = strword.Trim
        intindex += 1
        txtPhrase.Text += " " + strword
        txtPhrase.Text = txtPhrase.Text.Trim
        If IsPalindrome() Then
            MessageBox.Show("You entered a Palindrome")
        End If
    End Sub
    Private Function IsGoodInput(ByRef word As String) As Boolean
        If IsNumeric(txtWord.Text) Or (txtWord.Text) = "" Then
            MsgBox("Please enter a word.", , "Input Error")
            txtWord.Focus()
            Return False
        Else
            word = txtWord.Text
            Return True
        End If
    End Function
    Private Function IsPalindrome() As Boolean
        Dim strarr() As String
        Dim intupper = strarr.GetUpperBound(0)
        Dim bPalindrome As Boolean = True
        For i As Integer = 0 To CInt(intupper / 2)
            bPalindrome = strarr(i) = strarr(intupper - i)
            If Not bPalindrome Then txtYesOrNo.Text = " No it is not a Palindrome" : Return False
        Next
        txtYesOrNo.Text = "  Yes it is Palindrome"
        Return True
    End Function
Posted
Comments
André Kraak 30-Nov-12 14:28pm    
What does not work?
Sergey Alexandrovich Kryukov 30-Nov-12 15:26pm    
This is not a question! It looks like and order: "Write a program...", "Complete external documentation..." Who do you thing is going to write and complete it?
It looks like you did not even bother to write the text but simply copies something which was given to you. Don't you see that it even looks rude?

However, this is good that you provided some code sample. The problem is very simple, but if you face some difficulty, you need to tell us something about it. 1) what each method or other definition was supposed to do? 2) does it do what you expected? 3) if not, what do you observe instead? 4) why do you think the behavior is wrong?

Also, did you run it all under debugger? Usually, if you do, it might help you to find and fix the problem by yourself.
--SA

1 solution

You might change your IsPalindrome function this way:
VB
Private Function IsPalindrome(s As String) As Boolean
  Dim intupper As Integer = s.Length
  For i As Integer = 0 To CInt(intupper / 2)
    If s(i) <> s(intupper - 1 - i) Then Return False
  Next
  Return True
End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900