Results 1 to 13 of 13

Thread: textbox value..

  1. #1

    Thread Starter
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20

    textbox value..

    hi to everyone..im very new in this thing
    i have a form w/ corresponding textbox.
    in the textbox the user input a value and in pressing "enter" the value in textbox will be store in a string..

    what i want is when the user press "esc" while editing in textbox it will fill the previous value..
    how to do it?

    thanks in advance..

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    use a stack

  3. #3

    Thread Starter
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    Originally posted by brown monkey
    use a stack
    ok i try it..

    tanx for the suggs...

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I don't think it is quite that simple. Allowing a user access to the ESC key always give rise to problems. It is safer to use Confirm and Cancel buttons, making all other controls.Enabled=False. In the MouseEnter (or possibly TextChanged) event of the Textbox use something like

    VB Code:
    1. If bFirst=false then
    2.   othercontrols.enabled=False
    3.   bfirst=True
    4.   strText=Textbox.Text
    5. end if

    Then in the click event of the confirm button
    VB Code:
    1. bFirst=False
    2.   strText=""
    3.   othercontrols.enabled=True
    4.   btnConfirm.Enabled=False
    5.   btnCancel.Enabled=False
    In the click event of the cancel button
    VB Code:
    1. bfirst=False
    2.   Textbox.Text=strText
    3.   strText=""
    4.   btnConfirm.Enabled=False
    5.   btnCancel.Enabled=False

    bFirst is a form scope boolean and strText is a form scope string
    Last edited by taxes; Jun 18th, 2004 at 06:19 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    tanx for the great idea guys...

    more power

  6. #6
    Junior Member
    Join Date
    Jun 2004
    Posts
    29

    Smile Try this its the easiest

    Well I will tell you the easiest way.
    On got focus store the value in a variable called strOld value
    Capture the key down event and declare a string strNewvalue store the new value in it.
    ‘To store values in the strnew variable. Use this code in ‘TextBox1_KeyPress Event
    strnew = strnew + e.KeyChar
    Now do what ever you want to do you have both the values with you.
    On ESc use Old value and on Enter Use New Value.
    I bet nothing could be easier than this… J
    Give me a place to stand and I will move the Earth

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Try this its the easiest

    Hi,

    Any idea why I get the message

    "KeyChar is not a member of System.EventArgs" ?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Hi Taxes, I don't know in which part of your code it happens, but it seems to be a request of keychar argument in a keydown or keyup event. In these events you can obtain Keycode, for example but not keychar that is available in keypress event.
    Live long and prosper (Mr. Spock)

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by alextyx
    Hi Taxes, I don't know in which part of your code it happens, but it seems to be a request of keychar argument in a keydown or keyup event. In these events you can obtain Keycode, for example but not keychar that is available in keypress event.
    Sorry. I did not make myself clear. I was referring to the post by veins above when he said

    "To store values in the strnew variable. Use this code in ‘TextBox1_KeyPress Event
    strnew = strnew + e.KeyChar"

    I did not like to say he could not do that as it might have been something I was missing.

    So let's get back to veins' post.

    Firstly, you can't do it like that for two reasons;

    1. As above, KeyChar is not available.

    2. Even if you use KeyPress you cannot use it as if the operator makes an error and uses a backspacedelete, you will have an unintelligible character.

    What you can do is use

    strNew = TextBox1.Text

    but only in the KeyUp event. If you use it in the KeyDown or KeyPress event strNew will be 1 character in arrears.

    Thanks alextyx.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Nothing Taxes
    Dear Loner, if you only want to store the value in Textbox1 when press Enter and to recover it when press Esc, you can try this:

    Code:
      Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            Static Copiatesto As String
            If e.KeyCode = Keys.Enter Then
                Copiatesto = TextBox1.Text
            End If
            If e.KeyCode = Keys.Escape Then
                Me.TextBox1.Text = Copiatesto
            End If
        End Sub
    If you need something different....try to explain it to me once again
    Live long and prosper (Mr. Spock)

  11. #11

    Thread Starter
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    thanks alex...
    but it only store the last value inputed in the textbox..
    what i want is all the value inputed will retrieve every time the user press "esc".

    thanks in advance and more power..

  12. #12
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    stack is what you are finding... everytime you hit enter, push it and everytime you hit escape, pop it.

  13. #13

    Thread Starter
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    Originally posted by brown monkey
    stack is what you are finding... everytime you hit enter, push it and everytime you hit escape, pop it.
    thank you BM and the rest of the guys..
    i already got it by using stack.

    VB Code:
    1. Dim x As New Stack()
    2.     Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    3.         If e.KeyCode = Keys.Escape Then
    4.             TextBox1.Text = x.Pop
    5.         End If
    6.         If e.KeyCode = Keys.Enter Then
    7.             x.Push(TextBox1.Text)
    8.             TextBox1.Text = ""
    9.         End If
    10.     End Sub

    thanks and more power

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