2 Replies - 2927 Views - Last Post: 30 November 2012 - 12:52 PM Rate Topic: -----

#1 ITPROG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-November 12

Palindrome Programming Project

Posted 30 November 2012 - 12:10 PM

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:
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")
            Return False
            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
        txtYesOrNo.Text = "  Yes it is Palindrome"
        Return True
    End Function

Is This A Good Question/Topic? 0
  • +

Replies To: Palindrome Programming Project

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 233
  • View blog
  • Posts: 770
  • Joined: 19-October 11

Re: Palindrome Programming Project

Posted 30 November 2012 - 12:48 PM

And what is your question? What problem are you facing, where do you have errors, what are they?
Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Palindrome Programming Project

Posted 30 November 2012 - 12:52 PM

There is an excellent tutorial here on DIC. It's called Debugging Skills, and you would be well advised to read it and learn some basic debugging.

For example, placing a breakpoint on line 2 in your code, running the program, and single-stepping through the code would reveal to you that while you do indeed, enter the Function IsGoodInput(strword), the path through it is never going to be what you might be expecting. Can you see why? Hint: check the value of variables as you step through.

Have a look, make some corrections, and come back with more questions, if you need further help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1