Control
-
Your control is going to have to expose this property. What you are probably looking to do in your control is when a button is clicked, the code that handles that button click sets a property in your control with a value that is unique to that button, say 1 for the Y button and 0 for N button. Then your application can check the value of the property for which button was clicked. Another method would be to have your control fire an event that includes which button was clicked (as above) in its arguments. In your control, something like this: (not actual code!)
Public Event ButtonClicked(ByVal ButtonID as Integer)
Button handling code:
Private Sub YButton_Clicked(...)
RaiseEvent ButtonClicked(1)
End SubPrivate Sub NButton_Clicked(...)
RaiseEvent ButtonClicked(0)
End SubRageInTheMachine9532
If I understood you correct. I add the following code into my contorll porject and them created new ocx. Private Sub optYes_Click() optYes.Value = True End Sub Private Sub optNo_Click() optNo.Value = True End Sub Private Sub UserControl_Initialize() optNo.Value = False optYes.Value = False End Sub However, when I am placing that control in my main project I still can't see selected value. Please help me.
-
If I understood you correct. I add the following code into my contorll porject and them created new ocx. Private Sub optYes_Click() optYes.Value = True End Sub Private Sub optNo_Click() optNo.Value = True End Sub Private Sub UserControl_Initialize() optNo.Value = False optYes.Value = False End Sub However, when I am placing that control in my main project I still can't see selected value. Please help me.
Wait a minute... My mistake, I thought you were using two command buttons. :doh: OK. An OCX means your using VB6... What you have to do is expose (make Public) your own custom Property. What you would normally do is define an global variable used internal to your control, like m_OptionPicked. You use the optYes and optNo click events to set the value of that variable, either a number or some predefined Enumeration, whatever you want your Property to expose. I'll use an Enum to demonstrate:
' Setup our Public enumeration values
' These are the possible values of our controls property.
Public Enum ControlOptions
Undefined = -1
Yes = 1
No = 0
End Enum
' Internal variables (visible only inside the control!)
' Declaring as 'ControlOptions' will limit the value to
' the possible values of our Enumeration above.
Private m_OptionPicked as ControlOptionsNow, when an option button is clicked, you handle the Click event just as you have in your previous post, BUT you set the value of m_OptionPicked to one of the predefined values of ControlOptions, like this:
Private Sub UserControl_Initialize()
m_OptionPicked = ControlOptions.Undefined
End Sub
Private Sub optYes_Click()
m_OptionPicked = ControlOptions.Yes
End Sub
Private Sub optNo_Click()
m_OptionPicked = ControlOptions.No
End SubAlmost done! Now you have to expose the internal variable as a Property of your control. You can do this using the Property statements. We're going to make a property called OptionPicked that your control exposes to its host. The code in the Property statement will just return the value of the internal variable m_OptionPicked. Once again, we'll declare that the value returned is one of the possible values of ControlOptions above.
Public Property Get OptionPicked() as ControlOptions
return m_OptionPicked
End PropertySince we have only a Property Get defined for OptionPicked, is automatically becomes a Read-Only property. That is, your application can only read the value of OptionPicked, it can't set a new value for it. If you wanted to do that, you would have to define a block of code for a Property Set statement so your control knows what to do with the new value:
Public Property Set OptionPicked( NewValue as ControlOptions )
m_OptionPicked = NewValue
' Some addition code to alter the status
' of the option buttons on screen should go here.
End PropertyThat's all there is to
-
Wait a minute... My mistake, I thought you were using two command buttons. :doh: OK. An OCX means your using VB6... What you have to do is expose (make Public) your own custom Property. What you would normally do is define an global variable used internal to your control, like m_OptionPicked. You use the optYes and optNo click events to set the value of that variable, either a number or some predefined Enumeration, whatever you want your Property to expose. I'll use an Enum to demonstrate:
' Setup our Public enumeration values
' These are the possible values of our controls property.
Public Enum ControlOptions
Undefined = -1
Yes = 1
No = 0
End Enum
' Internal variables (visible only inside the control!)
' Declaring as 'ControlOptions' will limit the value to
' the possible values of our Enumeration above.
Private m_OptionPicked as ControlOptionsNow, when an option button is clicked, you handle the Click event just as you have in your previous post, BUT you set the value of m_OptionPicked to one of the predefined values of ControlOptions, like this:
Private Sub UserControl_Initialize()
m_OptionPicked = ControlOptions.Undefined
End Sub
Private Sub optYes_Click()
m_OptionPicked = ControlOptions.Yes
End Sub
Private Sub optNo_Click()
m_OptionPicked = ControlOptions.No
End SubAlmost done! Now you have to expose the internal variable as a Property of your control. You can do this using the Property statements. We're going to make a property called OptionPicked that your control exposes to its host. The code in the Property statement will just return the value of the internal variable m_OptionPicked. Once again, we'll declare that the value returned is one of the possible values of ControlOptions above.
Public Property Get OptionPicked() as ControlOptions
return m_OptionPicked
End PropertySince we have only a Property Get defined for OptionPicked, is automatically becomes a Read-Only property. That is, your application can only read the value of OptionPicked, it can't set a new value for it. If you wanted to do that, you would have to define a block of code for a Property Set statement so your control knows what to do with the new value:
Public Property Set OptionPicked( NewValue as ControlOptions )
m_OptionPicked = NewValue
' Some addition code to alter the status
' of the option buttons on screen should go here.
End PropertyThat's all there is to
I have some dificulty to compile tha code with the following lines: Public Property Get OptionPicked() As ControlOptions return m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property Please help me. Thanks:((
-
I have some dificulty to compile tha code with the following lines: Public Property Get OptionPicked() As ControlOptions return m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property Please help me. Thanks:((
You have to include what the error/problem is! RageInTheMachine9532
-
I have some dificulty to compile tha code with the following lines: Public Property Get OptionPicked() As ControlOptions return m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property Please help me. Thanks:((
Return
isn't supported in VB6. TryPublic Property Get OptionPicked() As ControlOptions
OptionPicked = m_OptionPicked
End Property
I think you're OK with the
Set
part. -
I have some dificulty to compile tha code with the following lines: Public Property Get OptionPicked() As ControlOptions return m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property Please help me. Thanks:((
My bad! That's what I get for writting VB6 code from memory! The fixed line should be:
Public Property Get OptionPicked() As ControlOptions
OptionPicked = m_OptionPicked
End PropertyRageInTheMachine9532
-
My bad! That's what I get for writting VB6 code from memory! The fixed line should be:
Public Property Get OptionPicked() As ControlOptions
OptionPicked = m_OptionPicked
End PropertyRageInTheMachine9532
Here is my code with your modification: Option Explicit Public Enum ControlOptions Undefined = -1 Yes = 1 No = 0 End Enum Private m_OptionPicked As ControlOptions Private Sub UserControl_Initialize() m_OptionPicked = ControlOptions.Undefined End Sub Private Sub optYes_Click() m_OptionPicked = ControlOptions.Yes End Sub Private Sub optNo_Click() m_OptionPicked = ControlOptions.No End Sub Public Property Get OptionPicked() As ControlOptions OptionPicked = m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property And here is the error: Compile error: Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, as ParamArray, or an invalid Set final parameter
-
Here is my code with your modification: Option Explicit Public Enum ControlOptions Undefined = -1 Yes = 1 No = 0 End Enum Private m_OptionPicked As ControlOptions Private Sub UserControl_Initialize() m_OptionPicked = ControlOptions.Undefined End Sub Private Sub optYes_Click() m_OptionPicked = ControlOptions.Yes End Sub Private Sub optNo_Click() m_OptionPicked = ControlOptions.No End Sub Public Property Get OptionPicked() As ControlOptions OptionPicked = m_OptionPicked End Property Public Property Set OptionPicked(NewValue As ControlOptions) m_OptionPicked = NewValue End Property And here is the error: Compile error: Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, as ParamArray, or an invalid Set final parameter
Once again, my bad! Change the Set to Let:
Public Property Let OptionPicked(NewValue As ControlOptions)
m_OptionPicked = NewValue
End PropertyThe Set version is used for setting object references... RageInTheMachine9532
-
Once again, my bad! Change the Set to Let:
Public Property Let OptionPicked(NewValue As ControlOptions)
m_OptionPicked = NewValue
End PropertyThe Set version is used for setting object references... RageInTheMachine9532
-
It is not your bad it is my luck of knoledge that I can't figure out by myself.But I am learning :) I was able to compile the ocx project and then use it in my main project, however I still can't see the value. UserControl11.Value ????
Thats because it's called OptionPicked, not Value. RageInTheMachine9532
-
Thats because it's called OptionPicked, not Value. RageInTheMachine9532