Results 1 to 6 of 6

Thread: Create a Label with code

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    5

    Create a Label with code

    Hello people!

    I am trying to create a label using code. But I don't konw how.

    I tried to use some code like:
    Code:
    Dim lbl_new as New Label
    lbl_new.Location = New Point(10, 10)
    but that didn't work.

    Can anyone point me to a tutorial or explain how I can do this?

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Create a Label with code

    Anyone?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Create a Label with code

    as you did not explain what you are trying to achieve, or in what application, difficult for anyone to give answer
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Create a Label with code

    Oh, well i was just trying to just create a normal label with code instead of having to make it in the design mode. Like when I press a button a label with like the text from a textbox I have.

    And the application is Word 2007, but I just use the Visual Basic function not Word itself. Kinda hard to explain since I'm not too good with this stuff.

    So just create a label with code is the only thing I want. Thankful for any help

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Create a Label with code

    is this on a userform?

    if so it should be something like
    vb Code:
    1. Set newlbl = Me.Controls.Add("Forms.Label.1", "mylabel", True)
    2. newlbl.Caption = "this is a test"
    3. newlbl.Left = 20
    4. newlbl.Top = 40
    this works, much easier to make the labels in design mode
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Create a Label with code

    Yes thank you! That was exactly what I wanted

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