dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Thread: Palindrome App

  1. #1
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25

    Palindrome App

    I want to create a palindrome app that determins the word or phrase entered by a user is a palindrome or not. Eg.
    --------------------------------------------
    USER TEXT: Able was i ere i saw Elba

    labelbox: Able was i ere i saw Elba is a palindrome
    ----------------------------------
    im thinking ill have to have a variable holding the string, then create a new variable holding the 'reverse' of the orignal string, and compare them. But im not sure what string function i should use..Any idea of how to code this?

    Thanks.

    -I tried the Loop While, but then the For Loop would be better, How would compare the first char to the last? What would the program look like?

  2. #2
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    The loop while was working but then if i did a Loop while: 1 to Len(string), it would just exit the loop and not hold anything that i needed.

  3. #3
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Well u need a small for loop read from the left text and put in the right label :

    try this :

    Code:
    Dim i As Integer
    For i = 1 To Len(TEXT)
       labelbox.Caption = Mid(TEXT, i, 1) & labelbox.Caption
    Next
    also be sure that the label contains nothing before start.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    Quote Originally Posted by tygolfer
    The loop while was working but then if i did a Loop while: 1 to Len(string), it would just exit the loop and not hold anything that i needed.
    I think your problem is with using "while" in the place of "until"

    ok my posted code will work well isn't ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #5
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    a tiny think maybe be better is to convert first letter to upper case using Ucase() function , but there is no rule for knowing witch letter must be converted to lower case !
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  6. #6
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    yes thats true...this is what i have

    Private Sub cmdCheck_Click()

    Dim i As Integer
    Dim strWord As String

    lblOutput.Caption = ""
    strWord = txtWord.Text

    For i = 1 To Len(Text)
    lblOutput.Caption = Mid(txtWord.Text, i, 1) & lblOutput.Caption
    Next

    End Sub

    --The label box does not show any thing. so how what what the code look like if the label said:

    strWord & "is a palindrome"

    Or if its not one i would be:
    strWord & "is not a palindrome"

    How would the if condition fit and look like?
    Last edited by tygolfer; 12-01-2006 at 03:43 PM.

  7. #7
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    Quote Originally Posted by tygolfer
    lblOutput.Caption = ""
    strWord = txtWord.Text

    For i = 1 To Len(Text)
    lblOutput.Caption = Mid(txtWord.Text, i, 1) & labelbox.Caption
    Next
    what is "TEXT" vb dont know it then it will consider it empty variable and hence the for loop will not be acceed !

    try the for loop like this :
    Code:
    For i = 1 To Len(strWord)

    Quote Originally Posted by tygolfer
    so how what what the code look like if the label said:

    strWord & "is a palindrome"

    Or if its not one i would be:
    strWord & "is not a palindrome"

    How would the if condition fit and look like?
    no if needed u only need a small end after the for loop :

    Code:
    strWord = strWord & " is a palindrome"
    remark the space at the begeening of " is a plain..." to have better results .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  8. #8
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    Quote Originally Posted by tygolfer
    yes thats true...this is what i have
    For i = 1 To Len(Text)
    lblOutput.Caption = Mid(txtWord.Text, i, 1) & labelbox.Caption
    Next
    You may also got compile error coz "labelbox" is not defined u must change it to your label control name ... "lblOutput"

    do u have problems understanding the code ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  9. #9
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    nope i understand it perfectly...I just forgot to change a couple of words around. My fault. (logic error)

    Ok, so now i have:

    Private Sub cmdCheck_Click()

    Dim i As Integer
    Dim strWord As String
    Dim strWord2 As String

    lblOutput.Caption = ""
    strWord = txtWord.Text

    For i = 1 To Len(strWord)
    lblOutput.Caption = Mid(txtWord.Text, i, 1) & lblOutput.Caption
    Next

    If strWord = strWord2 Then
    lblOutput.Caption = strWord & " is palindrome"
    Else
    lblOutput.Caption = strWord & " is plain"
    End If

    End Sub

    I need to change this, what do you think?

  10. #10
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    i edited a few things above.

    right now im getting "strWord is Plain" for every word i type in

  11. #11
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    Quote Originally Posted by tygolfer
    nope i understand it perfectly...I just forgot to change a couple of words around. My fault. (logic error)

    Ok, so now i have:

    Private Sub cmdCheck_Click()

    Dim i As Integer
    Dim strWord As String
    Dim strWord2 As String

    lblOutput.Caption = ""
    strWord = txtWord.Text

    For i = 1 To Len(strWord)
    lblOutput.Caption = Mid(txtWord.Text, i, 1) & lblOutput.Caption
    Next

    If strWord = strWord2 Then
    lblOutput.Caption = strWord & " is palindrome"
    Else
    lblOutput.Caption = strWord & " is plain"
    End If

    End Sub

    I need to change this, what do you think?
    Not logic errors, typing errors "7" ---> "&"

    okey now what is strword2 ?? you have defined it, so it's empty ;
    and finally you compare it with strword witch usually conatins strings, then the first if will never be acceed and u will have plain forever .

    better cpmare strword with the original text : "txtWord"

    Code:
    If strWord = txtWord Then
    got it ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  12. #12
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    lol...7/& ..haha

    strWord= txtWord wont work because:

    if the user inputs: jimmy

    strWord = jimmy
    txtWord =jimmy

    Therefore every word that is inputted says it is a palindrome.

  13. #13
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    I'm feeling u can't understand the code ; I'm talking generally and I'm not making tests for code I brings, I put them to use them when u understand the method ..

    anyway no need for variables at all or for the if statment compare with the label ...

    Code:
    If lblOutput.Caption = txtWord Then
    this compare between the fianl output and the original in the text box ..

    got it this time ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  14. #14
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    Omg, i am an idiot, i didn't even think of that..Ahh im sry..Ok the code is done. Thanks alot for your help!

  15. #15
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    Quote Originally Posted by tygolfer
    Omg, i am an idiot, i didn't even think of that..Ahh im sry..Ok the code is done. Thanks alot for your help!
    No man not an idiot just beginner; sure by time u will know more in programming .. I'm very glade for helping u ,and at any time

    Best regards.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

Similar Threads

  1. Replies: 2
    Last Post: 04-20-2005, 10:38 PM
  2. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  3. How to make App B modal in App A?
    By Måns in forum VB Classic
    Replies: 2
    Last Post: 11-11-2000, 06:17 PM
  4. How to make App B modal in App A?
    By Måns in forum VB Classic
    Replies: 0
    Last Post: 11-08-2000, 08:28 AM
  5. Re: discover whether VB App is in Run mode.
    By Michael Culley in forum VB Classic
    Replies: 3
    Last Post: 09-17-2000, 11:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center