Results 1 to 12 of 12

Thread: [RESOLVED] Trigger TextBox When Form Opens???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    Resolved [RESOLVED] Trigger TextBox When Form Opens???

    I am creating a form and I have a label that will display the user's name, but what I need to do it trigger a text box when the application opens that will allow the user to type in their name and then assign that value to the label in my form. How do I trigger the text box and assign the value to my label? My label is named lblStudent. Can anyone help me with this?

  2. #2
    Lively Member C0der's Avatar
    Join Date
    Mar 2010
    Location
    Somewhere in Internet
    Posts
    113

    Re: Trigger TextBox When Form Opens???

    Try this:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Label1.Caption = Text1
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    Re: Trigger TextBox When Form Opens???

    When I tried to add this code, both the Label1 and Text1 say they are not declared and there is an error when I try to run the script. I don't have a text box on my form, I just have the label. I need to have a text box trigger when the form opens, like a pop up I guess, and then the user can put in their name and then the value of the text box gets saves to the label (lblStudent). I'm new to this type of coding. Can you be a little more detailed?

  4. #4
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Trigger TextBox When Form Opens???

    Try adding a TextBox and a Label, both named: Text1 and Label1. To use the code posted in Post #2.
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Trigger TextBox When Form Opens???

    Quote Originally Posted by twilitegxa View Post
    When I tried to add this code, both the Label1 and Text1 say they are not declared and there is an error when I try to run the script. I don't have a text box on my form, I just have the label. I need to have a text box trigger when the form opens, like a pop up I guess, and then the user can put in their name and then the value of the text box gets saves to the label (lblStudent). I'm new to this type of coding. Can you be a little more detailed?
    Welcome to the forums...

    I think, InputBox() is really what you want..!
    Code:
    Private Sub Form_Load()
      lblStudent.Caption = InputBox("Enter your name:")
    End Sub
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    Re: Trigger TextBox When Form Opens???

    Quote Originally Posted by akhileshbc View Post
    Welcome to the forums...

    I think, InputBox() is really what you want..!
    Code:
    Private Sub Form_Load()
      lblStudent.Caption = InputBox("Enter your name:")
    End Sub
    ...
    That sound more like what I am needing, but when I tried your code, I received this error:

    Error 1 'Caption' is not a member of 'System.Windows.Forms.Label'.

    Can you help? I don't know what to do.

  7. #7
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Trigger TextBox When Form Opens???

    What kind of Visual Basic or Visual Studio are you using. Because that sounds like a .NET version of Visual Basic!! If I'm not mistaken??? Or your ActiveX control, hasn't been registered, or that you have to add it into your project!!
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Trigger TextBox When Form Opens???

    Quote Originally Posted by twilitegxa View Post
    That sound more like what I am needing, but when I tried your code, I received this error:

    Error 1 'Caption' is not a member of 'System.Windows.Forms.Label'.

    Can you help? I don't know what to do.
    You are not using VB6. In that language, labels have a caption property. In VB.NET, they have a text property, so it would be
    Code:
    lblStudents.Text = Whatever
    Moved To VB.NET

  9. #9
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Trigger TextBox When Form Opens???

    I think you use vs8
    beside in vs8 we dont have any caption for label1 in vs8 it's text

    it's the same code that akhileshbc said

    1-make a label1

    just copy these in your code page

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Label1.Text = InputBox("Enter your name:")
    
        End Sub
    End Class
    Last edited by Pc Monk; Mar 28th, 2010 at 10:47 AM.

  10. #10
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: Trigger TextBox When Form Opens???

    Quote Originally Posted by akhileshbc View Post
    Welcome to the forums...

    I think, InputBox() is really what you want..!
    Code:
    Private Sub Form_Load()
      lblStudent.Caption = InputBox("Enter your name:")
    End Sub
    ...
    i was having same problem
    ty for you're help

  11. #11
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Trigger TextBox When Form Opens???

    Ok how about this
    in form1 you make one textbox and in form2 you have your label
    in startup first you load form1 and the user type his name and then form2 coming up with the label that have the value of textbox in form1

    i think you should try this

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    Re: Trigger TextBox When Form Opens???

    Quote Originally Posted by Pc Monk View Post
    I think you use vs8
    beside in vs8 we dont have any caption for label1 in vs8 it's text

    it's the same code that akhileshbc said

    1-make a label1

    just copy these in your code page

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Label1.Text = InputBox("Enter your name:")
    
        End Sub
    End Class
    Thank you so much! This example did the trick!

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