dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26

Thread: Palindrome App

  1. #16
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    Amahdy, I dont know any of the case commands you mentioned earlier. The Ucase() im guessing is allowing the first letter to be capatilized.

    radar = palindrome
    Radar <> palindrome

    So in my code where would the Ucase function go? is it like: UCase(strWord,1) ?

    CODE:

    'checking to see if the word is a palindrome
    Private Sub cmdCheck_Click()
    'vars
    Dim intX As Integer
    Dim strWord As String

    lblOutput.Caption = "" 'clearing the label
    strWord = txtWord.Text 'variable equaling the txtbox

    'looping structure:
    For intX = 1 To Len(strWord) 'Will check every letter until the end of string 'checks if the letter correspond with the intial input (strWord)
    lblOutput.Caption = Mid(txtWord.Text, intX, 1) & lblOutput.Caption
    Next

    'the word spelled backwards for the USER's proof
    lblBackwards.Caption = lblOutput.Caption

    'If condition showing the user if palindrome = true/false
    If lblOutput.Caption = txtWord Then
    lblOutput.Caption = strWord & " is a palindrome"
    Else
    lblOutput.Caption = strWord & " is plain word"
    End If
    End Sub

  2. #17
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    well Ucase() take one string parameter and return this string to upper case letters .

    ex :
    Code:
    Dim a As String
    a = Ucase("mytest")
    'here a = "MYTEST"
    MsgBox a
    'the inverse function is Lcase()
    a = Lcase(a)
    'Here a = "mytest" again
    MsgBox a
    'also the function can take one character :
    a = Ucase("t")
    MsgBox a 'should be "T"
    now you need to remove the first left letter and put it's upper case ;

    first make a variable to hold the left letter tmp say ,
    second reomve the left letter from the string ,
    third reput in the left of the string the Ucase of tmp
    ex:
    Code:
    Dim tmp as String
    tmp = Left(lblBackwards.Caption, 1)
    lblBackwards.Caption = Mid(lblBackwards.Caption, 2)
    lblBackwards.Caption = Ucase(tmp) & lblBackwards.Caption
    Now with small change u can make it all with one step using function construnction :

    Code:
    lblBackwards.Caption = Ucase(Left(lblBackwards.Caption, 1)) & Mid(lblBackwards.Caption, 2)
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #18
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    Ok so your making the whole word UpperCase, then making the second letter and on Lower Case. That makes sense. Does this replace:

    'the word spelled backwards for the USER's proof
    lblBackwards.Caption = lblOutput.Caption
    lblBackwards.Caption = Ucase(Left(lblBackwards.Caption, 1)) & Mid(lblBackwards.Caption, 2)

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

    Arrow

    Quote Originally Posted by tygolfer
    Ok so your making the whole word UpperCase, then making the second letter and on Lower Case. That makes sense. Does this replace:

    'the word spelled backwards for the USER's proof
    lblBackwards.Caption = lblOutput.Caption
    lblBackwards.Caption = Ucase(Left(lblBackwards.Caption, 1)) & Mid(lblBackwards.Caption, 2)
    Not exactly :
    1) Ucase(Left(lblBackwards.Caption, 1)) :
    Make the left letter UpperCase

    2) Mid(lblBackwards.Caption, 2) :
    Is the string starting by the second letter

    3) lblBackwards.Caption = Ucase(Left(lblBackwards.Caption, 1)) & Mid(lblBackwards.Caption, 2)
    Add them together

    Clear ?

    Now I think you should get correct results , nop ?

    ***My brother went to Canada and told me that there ppl talk the french lang. using this palindrom method , changing in some couples I mean .. example : famille >>> mifam, frere >>> erfr ... do u need it for making the computer make that
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #20
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    of course it is possible to detect if the string is palindrome comparing only half string, instead of building a new one. this is my solution (that is just another solution, I do not want to say that there is anything wrong with yours!)

    Code:
    Public Function IsPalindrome(ByVal s As String) As Boolean
        IsPalindrome = True
        Dim k As Long
        For k = 1 To Len(s) \ 2
            If StrComp(Mid$(s, k, 1), Mid$(s, Len(s) - k + 1, 1), vbTextCompare) <> 0 Then
                IsPalindrome = False
                Exit For
            End If
        Next
    End Function
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

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

    Arrow

    yea If u r talking about best and fast method ; okey to use it do the following :

    put mstraf code in any place in your code [or module]

    now in the cmdCheck_Click() event put this code :

    Code:
    if (IsPalindrome(txtWord)) then
    lblOutput.Caption = strWord & " is a palindrome"
    Else
    lblOutput.Caption = strWord & " is plain word"
    End If
    that will be better and easiest ..
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  7. #22
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    Ok, umm..i kinda want to stick to what i have got so far. Unless you want to code the whole thing for me doing it the 'easy' way? Then i could compare them?

    i have the same command buttons and txtboxes/variables

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

    Arrow

    Quote Originally Posted by tygolfer
    Ok, umm..i kinda want to stick to what i have got so far. Unless you want to code the whole thing for me doing it the 'easy' way? Then i could compare them?

    i have the same command buttons and txtboxes/variables

    I dont understand what u want exactly here but my last post is talking about that :

    in the cmd_click() event only put my last code and put mstraf function in any place or module ,, you will have good results , but also I think before mstraf post u got a good working code , not ?

    just a bit , if u don't know yet more about functions it's similarly to that :


    Code:
    Private Sub cmdCheck_Click()
        Dim NotPalindrome As Boolean
        Dim k As Integer
        For k = 1 To Len(txtWord) \ 2
            If StrComp(Mid$(txtWord, k, 1), Mid$(txtWord, Len(txtWord) - k + 1, 1), vbTextCompare) <> 0 Then
                NotPalindrome = True
                Exit For
            End If
        Next
    
    if (NotPalindrome) then
    lblOutput.Caption = txtWord & " is plain word"
    Else
    lblOutput.Caption = txtWord & " is a palindrome"
    End If
    End Sub

    use the above code if you need final results only ..
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  9. #24
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    Yes the code i had before works great. This code u shown me above also works good. Thnx.

  10. #25
    Join Date
    Dec 2006
    Location
    Toronto
    Posts
    25
    what does the strComp and vbTextCompare functions do?

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

    Arrow

    Quote Originally Posted by tygolfer
    what does the strComp and vbTextCompare functions do?
    search in the MSDN for "strComp" u will find good explaination .


    **It exist directly in the index search ..
    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