Results 1 to 3 of 3

Thread: Understanding Code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Illinois
    Posts
    27

    Unhappy

    I have a code that I need explained to me line by line.

    Private Sub txtInputBox_KeyPress(KeyAscii As Integer)

    If Chr(KeyAscii) = "+" Then

    KeyAscii = 0

    txtDisplayBox.Text = Val(txtDisplayBox.Text) + Val(txtInputBox.Text)

    txtInputBox.Text = ""

    End If

    End Sub
    ________________________________________________
    Now when I ran the code, I could not finish putting the sentence in the text box when I get a message automatically saying It's a palindrom!!
    I'm a MICKEY FAN

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'txtInputBox is a text box and the event is the keypress
    
    Private Sub txtInputBox_KeyPress(KeyAscii As Integer)
    
    'if the + key is pressed then
    If Chr(KeyAscii) = "+" Then
    'the key = nothing (pretend the key doesn't exist)
    KeyAscii = 0
    'then in txtDisplayBox text box add the value or it ot the value or txtinputbox
    txtDisplayBox.Text = Val(txtDisplayBox.Text) + Val(txtinputbox.Text)
    'set the value of txtinputbox to nothing
    txtinputbox.Text = ""
    'end the if statement
    End If
    'exit sub
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    hardly surprising about the message coming up before you have finished typing the sentence! It is because the computer is doing the check every single time you press a letter!

    do not use the KEYPRESS event for this procedure, because you will never get far enough to do the test properly.

    Perhaps you could paste the code into a button's click event or something.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width