ActiveX Control Property Pages


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: ActiveX Control Property Pages

Hybrid View

  1. #1
    Jerry Bumgarner Guest

    ActiveX Control Property Pages


    I've created an ActiveX control that uses the MSComm control to retrieve data
    from a controller and now I want to add property pages to let the user change
    the Com Port and Baud Rate.
    The ActiveX control has the following properties:

    Public Property Let CommPort(portnum As Integer)
    MSComm.CommPort = portnum
    End Property
    Public Property Let BaudRate(baud As Long)
    MSComm.Settings = Str(baud) & LTrim(",N,8,1")
    End Property

    When I add a property page, the following event code is added:
    Private Sub PropertyPage_ApplyChanges()
    SelectedControls(0).CommPort = txtCommPort.Text
    SelectedControls(0).BaudRate = txtBaudRate.Text
    End Sub

    This doesn't set the properties of the MSComm control. Any suggestions?

  2. #2
    Neal Andrews Guest

    Re: ActiveX Control Property Pages

    Hi Jerry

    Have you placed the PropertyChanged method in the txtbox for the property?
    Something like...

    Private Sub txtBx_Change(Index As Integer)
    if m_fLoaded then
    PropertyPage.Changed = True
    end if
    End Sub

    Note:
    m_fLoaded is a private variable set at the end of the
    PropertyPage_SelectionChanged() event.

    Private Sub PropertyPage_SelectionChanged()

    m_fLoaded = False

    'Load Properties from control into property page.

    m_fLoaded = True
    End Sub

    Regards
    Neal

    "Jerry Bumgarner" <jerry.bumgarner@indramat.com> wrote in message
    news:396c6df8$1@news.devx.com...
    >
    > I've created an ActiveX control that uses the MSComm control to retrieve

    data
    > from a controller and now I want to add property pages to let the user

    change
    > the Com Port and Baud Rate.
    > The ActiveX control has the following properties:
    >
    > Public Property Let CommPort(portnum As Integer)
    > MSComm.CommPort = portnum
    > End Property
    > Public Property Let BaudRate(baud As Long)
    > MSComm.Settings = Str(baud) & LTrim(",N,8,1")
    > End Property
    >
    > When I add a property page, the following event code is added:
    > Private Sub PropertyPage_ApplyChanges()
    > SelectedControls(0).CommPort = txtCommPort.Text
    > SelectedControls(0).BaudRate = txtBaudRate.Text
    > End Sub
    >
    > This doesn't set the properties of the MSComm control. Any suggestions?




  3. #3
    JerryB Guest

    Re: ActiveX Control Property Pages


    Hello Neal,

    Thanks for the reply. I had included those methods already.
    In the app where I'm testing the control, I can bring up the property page
    and change the commport in the text box. If I hit Ok to close the property
    page and then open the property page again, the new commport is displayed.
    However, if I run the app and put the following code in the form load event,
    the old, original commport is read:

    Label2.caption = activexcontrol.commport

    This is my first attempt at property pages. When does the code in the property
    page actually run?

    If it calls a method in the ActiveX control, when does that method run?

    Thanks,
    Jerry


    "Neal Andrews" <neal@nandrews.freeserve.co.uk> wrote:
    >Hi Jerry
    >
    >Have you placed the PropertyChanged method in the txtbox for the property?
    >Something like...
    >
    >Private Sub txtBx_Change(Index As Integer)
    > if m_fLoaded then
    > PropertyPage.Changed = True
    > end if
    >End Sub
    >
    >Note:
    > m_fLoaded is a private variable set at the end of the
    >PropertyPage_SelectionChanged() event.
    >
    > Private Sub PropertyPage_SelectionChanged()
    >
    > m_fLoaded = False
    >
    > 'Load Properties from control into property page.
    >
    > m_fLoaded = True
    > End Sub
    >
    >Regards
    >Neal
    >
    >"Jerry Bumgarner" <jerry.bumgarner@indramat.com> wrote in message
    >news:396c6df8$1@news.devx.com...
    >>
    >> I've created an ActiveX control that uses the MSComm control to retrieve

    >data
    >> from a controller and now I want to add property pages to let the user

    >change
    >> the Com Port and Baud Rate.
    >> The ActiveX control has the following properties:
    >>
    >> Public Property Let CommPort(portnum As Integer)
    >> MSComm.CommPort = portnum
    >> End Property
    >> Public Property Let BaudRate(baud As Long)
    >> MSComm.Settings = Str(baud) & LTrim(",N,8,1")
    >> End Property
    >>
    >> When I add a property page, the following event code is added:
    >> Private Sub PropertyPage_ApplyChanges()
    >> SelectedControls(0).CommPort = txtCommPort.Text
    >> SelectedControls(0).BaudRate = txtBaudRate.Text
    >> End Sub
    >>
    >> This doesn't set the properties of the MSComm control. Any suggestions?

    >
    >



  4. #4
    Neal Andrews Guest

    Re: ActiveX Control Property Pages

    Hi Jerry

    Ok so we know that the property page is working Ok because you can access
    the information when you reopen the property page, but not when the actual
    control is run, correct!

    Spotted it!

    >> Public Property Let CommPort(portnum As Integer)
    >> MSComm.CommPort = portnum
    >> End Property


    You need to call the PropertyChanged method i.e.

    Public Property Let CommPort(portnum As Integer)
    MSComm.CommPort = portnum
    Call PropertyChanged("CommPort")
    End Property

    This tells the control that it needs to call the UserControl_WriteProperties
    so that the value is saved to the property bag.
    if you haven got any methods in the UserControl_WriteProperties event then
    they look something like this

    Call PropBag.WriteProperty(("CommPort", MSComm.CommPort, <Your Default
    Value for the commport>)

    Since you are using a class method you could properly dump the whole class
    to the property bag

    Also I would recommend passing any property Let members by Val and not by
    ref

    Public Property Let CommPort(ByVal portnum As Integer)

    Regards
    Neal



    "JerryB" <jerry.bumgarner@indramat.com> wrote in message
    news:396dc9fa$1@news.devx.com...
    >
    > Hello Neal,
    >
    > Thanks for the reply. I had included those methods already.
    > In the app where I'm testing the control, I can bring up the property page
    > and change the commport in the text box. If I hit Ok to close the

    property
    > page and then open the property page again, the new commport is displayed.
    > However, if I run the app and put the following code in the form load

    event,
    > the old, original commport is read:
    >
    > Label2.caption = activexcontrol.commport
    >
    > This is my first attempt at property pages. When does the code in the

    property
    > page actually run?
    >
    > If it calls a method in the ActiveX control, when does that method run?
    >
    > Thanks,
    > Jerry
    >
    >
    > "Neal Andrews" <neal@nandrews.freeserve.co.uk> wrote:
    > >Hi Jerry
    > >
    > >Have you placed the PropertyChanged method in the txtbox for the

    property?
    > >Something like...
    > >
    > >Private Sub txtBx_Change(Index As Integer)
    > > if m_fLoaded then
    > > PropertyPage.Changed = True
    > > end if
    > >End Sub
    > >
    > >Note:
    > > m_fLoaded is a private variable set at the end of the
    > >PropertyPage_SelectionChanged() event.
    > >
    > > Private Sub PropertyPage_SelectionChanged()
    > >
    > > m_fLoaded = False
    > >
    > > 'Load Properties from control into property page.
    > >
    > > m_fLoaded = True
    > > End Sub
    > >
    > >Regards
    > >Neal
    > >
    > >"Jerry Bumgarner" <jerry.bumgarner@indramat.com> wrote in message
    > >news:396c6df8$1@news.devx.com...
    > >>
    > >> I've created an ActiveX control that uses the MSComm control to

    retrieve
    > >data
    > >> from a controller and now I want to add property pages to let the user

    > >change
    > >> the Com Port and Baud Rate.
    > >> The ActiveX control has the following properties:
    > >>
    > >> Public Property Let CommPort(portnum As Integer)
    > >> MSComm.CommPort = portnum
    > >> End Property
    > >> Public Property Let BaudRate(baud As Long)
    > >> MSComm.Settings = Str(baud) & LTrim(",N,8,1")
    > >> End Property
    > >>
    > >> When I add a property page, the following event code is added:
    > >> Private Sub PropertyPage_ApplyChanges()
    > >> SelectedControls(0).CommPort = txtCommPort.Text
    > >> SelectedControls(0).BaudRate = txtBaudRate.Text
    > >> End Sub
    > >>
    > >> This doesn't set the properties of the MSComm control. Any suggestions?

    > >
    > >

    >




  5. #5
    Jerry Bumgarner Guest

    Re: ActiveX Control Property Pages


    Hello again,
    Thanks for the suggestions. It's almost working now. To troubleshoot, I
    put Msgbox's in the properties and events of the control and property page
    so that I would now when events and properties were executing.

    After adding the control to the test project and right clicking on the property
    page, a message box displays that the commport is 2 (original value set in
    the mscomm control). When I change the commport to 1 on the property page
    and press okay, I get a message box from the Property Let and shows that
    mscomm.commport =1. Seems to be working.
    However, when I run the test project, the form load event reads the commport
    (label1.caption = activexcontrol.commport). The Property Get event runs
    and returns a setting of 2 - even though the property page changed it to
    1.
    I've checked all my code in the control and nothing else sets the commport.

    If I add the following code to the test project,
    activeXcontrol.commport = 1, then the commport is changed but it defeats
    the purpose of the property page.

    What am I doing wrong??

    Thanks again,
    Jerry


    "Neal Andrews" <neal@nandrews.freeserve.co.uk> wrote:
    >Hi Jerry
    >
    >Ok so we know that the property page is working Ok because you can access
    >the information when you reopen the property page, but not when the actual
    >control is run, correct!
    >
    >Spotted it!
    >
    >>> Public Property Let CommPort(portnum As Integer)
    >>> MSComm.CommPort = portnum
    >>> End Property

    >
    >You need to call the PropertyChanged method i.e.
    >
    >Public Property Let CommPort(portnum As Integer)
    > MSComm.CommPort = portnum
    > Call PropertyChanged("CommPort")
    >End Property
    >
    >This tells the control that it needs to call the UserControl_WriteProperties
    >so that the value is saved to the property bag.
    >if you haven got any methods in the UserControl_WriteProperties event then
    >they look something like this
    >
    > Call PropBag.WriteProperty(("CommPort", MSComm.CommPort, <Your Default
    >Value for the commport>)
    >
    >Since you are using a class method you could properly dump the whole class
    >to the property bag
    >
    >Also I would recommend passing any property Let members by Val and not by
    >ref
    >
    >Public Property Let CommPort(ByVal portnum As Integer)
    >
    >Regards
    >Neal
    >
    >
    >
    >"JerryB" <jerry.bumgarner@indramat.com> wrote in message
    >news:396dc9fa$1@news.devx.com...
    >>
    >> Hello Neal,
    >>
    >> Thanks for the reply. I had included those methods already.
    >> In the app where I'm testing the control, I can bring up the property

    page
    >> and change the commport in the text box. If I hit Ok to close the

    >property
    >> page and then open the property page again, the new commport is displayed.
    >> However, if I run the app and put the following code in the form load

    >event,
    >> the old, original commport is read:
    >>
    >> Label2.caption = activexcontrol.commport
    >>
    >> This is my first attempt at property pages. When does the code in the

    >property
    >> page actually run?
    >>
    >> If it calls a method in the ActiveX control, when does that method run?
    >>
    >> Thanks,
    >> Jerry
    >>
    >>
    >> "Neal Andrews" <neal@nandrews.freeserve.co.uk> wrote:
    >> >Hi Jerry
    >> >
    >> >Have you placed the PropertyChanged method in the txtbox for the

    >property?
    >> >Something like...
    >> >
    >> >Private Sub txtBx_Change(Index As Integer)
    >> > if m_fLoaded then
    >> > PropertyPage.Changed = True
    >> > end if
    >> >End Sub
    >> >
    >> >Note:
    >> > m_fLoaded is a private variable set at the end of the
    >> >PropertyPage_SelectionChanged() event.
    >> >
    >> > Private Sub PropertyPage_SelectionChanged()
    >> >
    >> > m_fLoaded = False
    >> >
    >> > 'Load Properties from control into property page.
    >> >
    >> > m_fLoaded = True
    >> > End Sub
    >> >
    >> >Regards
    >> >Neal
    >> >
    >> >"Jerry Bumgarner" <jerry.bumgarner@indramat.com> wrote in message
    >> >news:396c6df8$1@news.devx.com...
    >> >>
    >> >> I've created an ActiveX control that uses the MSComm control to

    >retrieve
    >> >data
    >> >> from a controller and now I want to add property pages to let the user
    >> >change
    >> >> the Com Port and Baud Rate.
    >> >> The ActiveX control has the following properties:
    >> >>
    >> >> Public Property Let CommPort(portnum As Integer)
    >> >> MSComm.CommPort = portnum
    >> >> End Property
    >> >> Public Property Let BaudRate(baud As Long)
    >> >> MSComm.Settings = Str(baud) & LTrim(",N,8,1")
    >> >> End Property
    >> >>
    >> >> When I add a property page, the following event code is added:
    >> >> Private Sub PropertyPage_ApplyChanges()
    >> >> SelectedControls(0).CommPort = txtCommPort.Text
    >> >> SelectedControls(0).BaudRate = txtBaudRate.Text
    >> >> End Sub
    >> >>
    >> >> This doesn't set the properties of the MSComm control. Any suggestions?
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center