Solved

user control

Posted on 2004-10-15
5
139 Views
Last Modified: 2010-05-02
Hello, I am putting together a control that gets and sets the labels text. I am putting this functionality within the name property below:

Private dname As String

 Property name1() As String
        Get
            name1 = dname
        End Get
        Set(ByVal Value As String)
            dname = Label1.Text
        End Set

    End Property

I want to set the label name within control in the implementation program, and not sure how to do it and if my property is looking right at all?
0
Comment
Question by:Gipsy
  • 2
  • 2
5 Comments
 

Author Comment

by:Gipsy
Comment Utility
I would want to set the controls label in the form_load  event :
   
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub
0
 
LVL 5

Assisted Solution

by:jmacmicking
jmacmicking earned 20 total points
Comment Utility
If I'm understanding what you want correctly your Set statement should look something like this:

Set(ByVal Value as String)
    dname=Value
    Label1.Text=dname
End SEt

You could do away with dname entirely, just use Label1.Text in your Get statement as well.

A couple of points though:  
    .Text is a property of a textbox, it sets or gets the text typed into the textbox.  If you're using a label control the equivalent property is .Caption--this sets the text the user of your program sees.
    The name of a control (label or otherwise) is set at design time or, in the case of a dynamically generated control, Dim'd at run time.  I'm assuming you're trying to set either the Text property of a textbox or the Caption property of a label.

If you're control is a label this would be the Set property:

Set(ByVal Value as String)
    dname=Value
    Label1.Caption=dname
End SEt

0
 

Author Comment

by:Gipsy
Comment Utility
Thanks,

But i cant get it to work in implementation,

I want to put smth like this

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

usercontol.name1() = "Start of the month"

End Sub
0
 
LVL 10

Expert Comment

by:fds_fatboy
Comment Utility
jmacmicking:

Gipsy is using vb.NET (not mentioned - but you can tell because of the Property statement layout) therefore, Label1.Text is correct, not Label1.Caption.
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 20 total points
Comment Utility
You can get rid of dName and try changing your Property to this:

Public Property name1() As String
        Get
            name1 = Label1.Text
        End Get
        Set(ByVal Value As String)
            Label1.Text = Value
        End Set

    End Property

I haven't got dotNet here, at work so I can't test it.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now