Solved

user control

Posted on 2004-10-15
5
140 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
ID: 12318158
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
ID: 12318167
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
ID: 12318234
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
ID: 12318598
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
ID: 12318656
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

943 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

10 Experts available now in Live!

Get 1:1 Help Now