Results 1 to 10 of 10

Thread: Stupid problem with text box...

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,035

    Stupid problem with text box...

    I apologise in advance for this elementary problem!
    Why doesn't this work, when I enter some characters into the box? And yes I have the immediate window showing...
    The text box is named txtChar

    Code:
    Option Explicit
    Dim Bloggs As String
    '-------------------------------
    Private Sub Form_Load()
        Bloggs = txtChar.Text
        Debug.Print Bloggs
    End Sub
    Thanks all!

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,156

    Re: Stupid problem with text box...

    You just have that code in Form_Load. The only text it's going to show is text you put into the textbox while in IDE design mode through the properties window.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Re: Stupid problem with text box...

    The program starts with the load event and then never returns there. Typing in text in the box has no effect.

    Use the changed event for the textbox


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    Debug.Print textbox1.text
    End Sub

    When there is a change, ie text added, this event will fire.But it will fire each time a character is added.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,035

    Re: Stupid problem with text box...

    Could that be simpler? I've managed before without e As EventArgs (but I now can' remember how).
    Also the 'handles...' syntax looks more like vb NET to me...
    Thanks all!

  5. #5
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Re: Stupid problem with text box...

    You don't need the eventargs
    If it's easier, and usually is, just double click the textbox in the programming mode. That will add the event handler for you.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,683

    Re: Stupid problem with text box...

    Yes, that looks like VB.Net.

    What are you really trying to do? Because even fixing that doesn't make any sense.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,035

    Re: Stupid problem with text box...

    Quote Originally Posted by dilettante View Post
    Yes, that looks like VB.Net.

    What are you really trying to do? Because even fixing that doesn't make any sense.
    On loading a form I want a text box to appear, and the next keystroke to be in that and immediately transferred to a variable.
    And, of course in vb6 NOT Net!
    Thanks all!

  8. #8
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Stupid problem with text box...

    To put the value of a TextBox's Text property into a variable whenever that value it changes?

    Code:
     
    Private Sub Text1_Change() 
        variable = Text1.Text
    End sub
    To get focus into the TextBox when the Form loads, set its TabIndex property to zero and its TabStop property to True (which should be the default anyway).

    Regards, Phill W.

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,335

    Re: Stupid problem with text box...

    Quote Originally Posted by Phill.W View Post
    To put the value of a TextBox's Text property into a variable whenever that value it changes?

    To get focus into the TextBox when the Form loads, set its TabIndex property to zero and its TabStop property to True (which should be the default anyway).

    Regards, Phill W.
    Or set its Focus in Form_Activate()-Event
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,035

    Re: Stupid problem with text box...

    Quote Originally Posted by Phill.W View Post
    To put the value of a TextBox's Text property into a variable whenever that value it changes?

    Code:
     
    Private Sub Text1_Change() 
        variable = Text1.Text
    End sub
    To get focus into the TextBox when the Form loads, set its TabIndex property to zero and its TabStop property to True (which should be the default anyway).

    Regards, Phill W.
    The sub change looks to be what I needed. Thanks
    Thanks all!

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