|
-
Aug 6th, 2006, 05:28 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] User Control Question
Hello,
I put together a user control with two date pickers and labels. I am to set the labels text property and get the number of days between the date ranges. I have the code to do this, but when I test the control, the labels do not have the new text property. I haven't tested the date range portion yet. I have followed the steps in the text book on building the solution so that the control is available when using the form. Could someone let me know what I'm doing wrong with setting the label text? Here is my control code:
VB Code:
Public Class DateRange
Public WriteOnly Property PickUp() As String
Set(ByVal value As String)
Label1.Text = "PickUp Day"
End Set
End Property
Public WriteOnly Property DropOff() As String
Set(ByVal value As String)
Label2.Text = "DropOff Day"
End Set
End Property
Public ReadOnly Property GetDays() As String
Get
'Declare variables
Dim DayCount As Integer
'Determine number of days
DayCount = CInt((DateDiff(DateInterval.Day, DateTimePicker1.Value, DateTimePicker2.Value)))
Return CStr(DayCount)
End Get
End Property
End Class
Thanks
-
Aug 6th, 2006, 07:23 PM
#2
Re: [2005] User Control Question
You're setting the Text of the Labels to a predefined string no matter what the caller passes. The 'value' argument contains the string the the caller is trying to set, so you have to assing that to the Label's Text property:
VB Code:
Public WriteOnly Property PickUp() As String
Set(ByVal value As String)
Label1.Text = [U]value[/U]
End Set
End Property
Public WriteOnly Property DropOff() As String
Set(ByVal value As String)
Label2.Text = [U]value[/U]
End Set
End Property
-
Aug 6th, 2006, 08:15 PM
#3
Thread Starter
Lively Member
Re: [2005] User Control Question
Hello,
Sorry, I'm a little confused. Where does "Value" come from? Do I set this through the controls property window (the label text field) for each label then use the Get and Set portion in the public property? I don't see where else "Value" would come from.
Thanks
-
Aug 6th, 2006, 08:25 PM
#4
Re: [2005] User Control Question
You don't do anything. It's is the parameter passed to the Set method:
VB Code:
Public WriteOnly Property PickUp() As String
Set(ByVal [U]value[/U] As String)
Label1.Text = [U]value[/U]
End Set
End Property
When you use a property you are implicitly calling either the Get or Set method from the property definition. Your properties are WriteOnly so they only have a setter. When someone assigns a value to your property like this:
VB Code:
myDateRange.PickUp = SomeValue
They are implicitly calling this method:
VB Code:
Set(ByVal value As String)
Label1.Text = value
End Set
and SomeValue is passed as the 'value' parameter.
-
Aug 6th, 2006, 08:37 PM
#5
Thread Starter
Lively Member
Re: [2005] User Control Question
Ok, I understand now, I think. I use the generic "Value" in the control, then when I use the control on the form I set the value for the label text by using:
VB Code:
myDateRange.PickUp = SomeValue
Thank you very much!
-
Aug 6th, 2006, 08:47 PM
#6
Thread Starter
Lively Member
Re: [2005] User Control Question
Just got it to work. Thanks again. I'm sure I'll have more control questions in the near future.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|