+ Reply to Thread
Results 1 to 23 of 23

Passing combobox value to custom class

Hybrid View

Jacques Grobler Passing combobox value to... 07-04-2012, 04:38 AM
Steffen Thomsen Re: Passing combobox value to... 07-04-2012, 04:56 AM
Andy Pope Re: Passing combobox value to... 07-04-2012, 05:00 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 05:58 AM
Andy Pope Re: Passing combobox value to... 07-04-2012, 06:25 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 07:08 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 07:12 AM
Andy Pope Re: Passing combobox value to... 07-04-2012, 07:21 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 07:47 AM
Andy Pope Re: Passing combobox value to... 07-04-2012, 07:50 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 08:01 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 08:00 AM
Andy Pope Re: Passing combobox value to... 07-04-2012, 08:30 AM
Jacques Grobler Re: Passing combobox value to... 07-04-2012, 08:41 AM
Jacques Grobler Re: Passing combobox value to... 07-05-2012, 03:15 AM
Andy Pope Re: Passing combobox value to... 07-05-2012, 03:31 AM
Jacques Grobler Re: Passing combobox value to... 07-05-2012, 03:46 AM
Andy Pope Re: Passing combobox value to... 07-05-2012, 04:06 AM
Jacques Grobler Re: Passing combobox value to... 07-05-2012, 05:28 AM
Andy Pope Re: Passing combobox value to... 07-05-2012, 05:34 AM
Jacques Grobler Re: Passing combobox value to... 07-05-2012, 05:40 AM
Andy Pope Re: Passing combobox value to... 07-05-2012, 05:43 AM
Jacques Grobler Re: Passing combobox value to... 07-05-2012, 05:49 AM
  1. #1
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Passing combobox value to custom class

    Hi all,

    I have created a class that populates a combobox list with my values for reuase, this class is then initialised in a user form and linked to a combobox1.

    However, I'm trying to generate a couple of properties from the selection of this list made by the user.

    So, to try and explain again, the list is created by a class, the user clicks on the drop down and selects a value in the list, I then wnat the class to know which value is selected so that I can do calculations in the class.

    How do I do this?

    Here is my code:

    'Class code for: cls_combobox_FlangeSection
    
    Option Explicit
    
    Public m_ctlListControl As MSForms.Control
    Public m_asListItems As Variant
    Public WithEvents m_cmbFlangeSection As MSForms.ComboBox
    
    Private Sub Class_Initialize()
        m_asListItems = _
            Array("FB 012.0 x 03.0", "FB 020.0 x 03.0", "FB 020.0 x 05.0", "FB 020.0 x 06.0", "FB 020.0 x 08.0", "FB 020.0 x 10.0", "FB 025.0 x 03.0", "FB 025.0 x 04.5", "FB 025.0 x 05.0", "FB 025.0 x 06.0", "FB 025.0 x 08.0", "FB 025.0 x 10.0", "FB 025.0 x 12.0", "FB 030.0 x 04.5", "FB 030.0 x 05.0", "FB 030.0 x 06.0", "FB 030.0 x 08.0", "FB 030.0 x 10.0", "FB 030.0 x 12.0", "FB 035.0 x 05.0", _
                "FB 040.0 x 04.5", "FB 040.0 x 05.0", "FB 040.0 x 06.0", "FB 040.0 x 08.0", "FB 040.0 x 10.0", "FB 040.0 x 12.0", "FB 040.0 x 16.0", "FB 040.0 x 20.0", "FB 040.0 x 25.0", "FB 047.6 x 05.0", "FB 050.0 x 05.0", "FB 050.0 x 06.0", "FB 050.0 x 08.0", "FB 050.0 x 10.0", "FB 050.0 x 12.0", "FB 050.0 x 16.0", "FB 050.0 x 20.0", "FB 050.0 x 25.0", "FB 060.0 x 06.0", "FB 060.0 x 08.0", _
                "FB 060.0 x 10.0", "FB 060.0 x 12.0", "FB 060.0 x 16.0", "FB 060.0 x 20.0", "FB 060.0 x 25.0", "FB 060.0 x 30.0", "FB 065.0 x 06.0", "FB 065.0 x 08.0", "FB 065.0 x 10.0", "FB 065.0 x 12.0", "FB 065.0 x 16.0", "FB 065.0 x 20.0", "FB 065.0 x 25.0", "FB 070.0 x 06.0", "FB 070.0 x 08.0", "FB 070.0 x 10.0", "FB 070.0 x 12.0", "FB 070.0 x 16.0", "FB 070.0 x 20.0", "FB 080.0 x 06.0", _
                "FB 080.0 x 08.0", "FB 080.0 x 10.0", "FB 080.0 x 12.0", "FB 080.0 x 16.0", "FB 080.0 x 20.0", "FB 080.0 x 25.0", "FB 080.0 x 30.0", "FB 080.0 x 40.0", "FB 090.0 x 06.0", "FB 090.0 x 08.0", "FB 090.0 x 10.0", "FB 090.0 x 12.0", "FB 090.0 x 16.0", "FB 090.0 x 20.0", "FB 090.0 x 25.0", "FB 100.0 x 06.0", "FB 100.0 x 08.0", "FB 100.0 x 10.0", "FB 100.0 x 12.0", "FB 100.0 x 16.0", _
                "FB 100.0 x 20.0", "FB 100.0 x 25.0", "FB 100.0 x 30.0", "FB 100.0 x 40.0", "FB 100.0 x 50.0", "FB 110.0 x 06.0", "FB 110.0 x 08.0", "FB 110.0 x 10.0", "FB 110.0 x 12.0", "FB 130.0 x 08.0", "FB 130.0 x 10.0", "FB 130.0 x 12.0", "FB 130.0 x 16.0", "FB 130.0 x 20.0", "FB 130.0 x 25.0", "FB 150.0 x 08.0", "FB 150.0 x 10.0", "FB 150.0 x 12.0", "FB 150.0 x 16.0", "FB 150.0 x 20.0", _
                "FB 150.0 x 25.0", "FB 150.0 x 30.0", "FB 180.0 x 10.0", "FB 180.0 x 12.0", "FB 180.0 x 16.0", "FB 180.0 x 20.0", "FB 180.0 x 25.0", "FB 200.0 x 10.0", "FB 200.0 x 12.0", "FB 200.0 x 16.0", "FB 200.0 x 18.0", "FB 200.0 x 20.0", "FB 200.0 x 25.0", "FB 200.0 x 30.0", "FB 250.0 x 10.0", "FB 250.0 x 12.0", "FB 250.0 x 16.0", "FB 250.0 x 18.0", "FB 250.0 x 20.0", "FB 250.0 x 25.0", _
                "FB 250.0 x 30.0", "FB 300.0 x 10.0", "FB 300.0 x 12.0", "FB 300.0 x 16.0", "FB 300.0 x 18.0", "FB 300.0 x 20.0", "FB 300.0 x 25.0", "FB 300.0 x 30.0", "FB 300.0 x 35.0", "FB 300.0 x 40.0", "FB 300.0 x 45.0", "FB 300.0 x 50.0", "FB 300.0 x 55.0", "FB 300.0 x 65.0", _
                "eqL 025.0 x 025.0 x 02.5", "eqL 025.0 x 025.0 x 03.0", "eqL 025.0 x 025.0 x 04.0", "eqL 025.0 x 025.0 x 05.0", "eqL 030.0 x 030.0 x 03.0", "eqL 030.0 x 030.0 x 04.0", "eqL 030.0 x 030.0 x 05.0", "eqL 040.0 x 040.0 x 02.5", "eqL 040.0 x 040.0 x 03.0", "eqL 040.0 x 040.0 x 04.0", "eqL 040.0 x 040.0 x 05.0", "eqL 040.0 x 040.0 x 06.0", "eqL 045.0 x 045.0 x 03.0", "eqL 045.0 x 045.0 x 04.0", _
                "eqL 045.0 x 045.0 x 05.0", "eqL 045.0 x 045.0 x 06.0", "eqL 050.0 x 050.0 x 03.0", "eqL 050.0 x 050.0 x 04.0", "eqL 050.0 x 050.0 x 05.0", "eqL 050.0 x 050.0 x 06.0", "eqL 050.0 x 050.0 x 08.0", "eqL 060.0 x 060.0 x 04.0", "eqL 060.0 x 060.0 x 05.0", "eqL 060.0 x 060.0 x 06.0", "eqL 060.0 x 060.0 x 08.0", "eqL 060.0 x 060.0 x 10.0", "eqL 070.0 x 070.0 x 06.0", "eqL 070.0 x 070.0 x 08.0", _
                "eqL 070.0 x 070.0 x 10.0", "eqL 080.0 x 080.0 x 06.0", "eqL 080.0 x 080.0 x 08.0", "eqL 080.0 x 080.0 x 10.0", "eqL 080.0 x 080.0 x 12.0", "eqL 090.0 x 090.0 x 06.0", "eqL 090.0 x 090.0 x 08.0", "eqL 090.0 x 090.0 x 10.0", "eqL 090.0 x 090.0 x 12.0", "eqL 100.0 x 100.0 x 08.0", "eqL 100.0 x 100.0 x 10.0", "eqL 100.0 x 100.0 x 12.0", "eqL 100.0 x 100.0 x 15.0", "eqL 120.0 x 120.0 x 08.0", _
                "eqL 120.0 x 120.0 x 10.0", "eqL 120.0 x 120.0 x 12.0", "eqL 120.0 x 120.0 x 15.0", "eqL 150.0 x 150.0 x 10.0", "eqL 150.0 x 150.0 x 12.0", "eqL 150.0 x 150.0 x 15.0", "eqL 150.0 x 150.0 x 18.0", "eqL 200.0 x 200.0 x 16.0", "eqL 200.0 x 200.0 x 18.0", "eqL 200.0 x 200.0 x 20.0", "eqL 200.0 x 200.0 x 24.0", _
                "uneqL 065.0 x 050.0 x 06.0", "uneqL 065.0 x 050.0 x 08.0", "uneqL 075.0 x 050.0 x 06.0", "uneqL 075.0 x 050.0 x 08.0", "uneqL 080.0 x 060.0 x 06.0", "uneqL 080.0 x 060.0 x 08.0", "uneqL 090.0 x 065.0 x 06.0", "uneqL 090.0 x 065.0 x 08.0", "uneqL 090.0 x 065.0 x 10.0", "uneqL 095.0 x 065.0 x 06.0", "uneqL 095.0 x 065.0 x 08.0", "uneqL 095.0 x 065.0 x 10.0", _
                "uneqL 100.0 x 065.0 x 08.0", "uneqL 100.0 x 065.0 x 10.0", "uneqL 100.0 x 075.0 x 06.0", "uneqL 100.0 x 075.0 x 08.0", "uneqL 100.0 x 075.0 x 10.0", "uneqL 100.0 x 075.0 x 12.0", "uneqL 125.0 x 075.0 x 08.0", "uneqL 125.0 x 075.0 x 10.0", "uneqL 125.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 10.0", "uneqL 150.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 15.0", _
                "uneqL 150.0 x 090.0 x 10.0", "uneqL 150.0 x 090.0 x 12.0", "uneqL 150.0 x 090.0 x 15.0")
                
    End Sub
    
    Private Sub Class_Terminate()
        Set m_ctlListControl = Nothing
    End Sub
    
    Public Property Get ListControl() As MSForms.Control
        Set ListControl = m_ctlListControl
    End Property
    
    Public Property Set ListControl(ctlListControl As MSForms.Control)
        Select Case TypeName(ctlListControl)
            Case "ListBox", "ComboBox"
                Set m_ctlListControl = ctlListControl
                m_ctlListControl.List = m_asListItems
            Case Else
                ' up to you - maybe raise an error?
        End Select
    End Property
    'Form code:
    
    Dim oList As cls_combobox_FlangeSection
    
    Private Sub UserForm_Initialize()
        Set oList = New cls_combobox_FlangeSection
        Set oList.ListControl = Me.ComboBox1
    End Sub
    Last edited by Jacques Grobler; 07-05-2012 at 03:15 AM.
    Jacques


  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Passing combobox value to custom class

    In the class

    Private cb_value As Long
    
    Public Property Let cb_selected_value(val As Long)
        cb_value = val
    End Property
    In the form

        Private sub Combobox1_click()
              oList.cb_selected_value = Me.Combobox1.value
       end sub
    Now when changing a value in the combobox the class variable cb_value will hold the selected value
    Please take time to read the forum rules

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    The class object already knows.

    Within the class object
    m_cmbFlangeSection.Value 
    or 
    m_cmbFlangeSection.Listindex
    And you can use the events of the m_cmbFlangeSection object to code against.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Hi Andy, what would my new code look like?

    Your code:

    m_cmbFlangeSection.Value 
    or 
    m_cmbFlangeSection.Listindex

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    As you have declared the reference in the class as public you can use the following in your userform

    oList.m_cmbFlangeSection.Value
    If it had been a private member of the class you could add a property to the class
    Public property get Value() as long
        Value = m_cmbFlangeSection.Value
    End property
    Public Property get ListIndex() as long
        ListIndex = m_cmbFlangeSection.ListIndex
    End Property
    Userform code
    Msgbox oList.Value & vblf & oList.ListIndex
    Is the sole purpose of this to populate a list with fixed values? If so a simple function would have done.

  6. #6
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Hi Andy

    Sorry but I'm not getting it to work.

    Here is how I have applied your code to my code:

    'Code: Userform
    
    Dim oList As cls_combobox_FlangeSection
    
    Private Sub ComboBox1_Change()
        Set oList = New cls_combobox_FlangeSection
        MsgBox oList.Value & vbLf & oList.ListIndex
    End Sub
    
    Private Sub UserForm_Initialize()
        Set oList = New cls_combobox_FlangeSection
        Set oList.ListControl = Me.ComboBox1
    End Sub
    'Code: Class: cls_combobox_FlangeSection
    
    Option Explicit
    
    Public m_ctlListControl As MSForms.Control
    Public m_asListItems As Variant
    Public WithEvents m_cmbFlangeSection As MSForms.ComboBox
    
    Public Property Get Value() As Long
        Value = m_cmbFlangeSection.Value
    End Property
    
    Public Property Get ListIndex() As Long
        ListIndex = m_cmbFlangeSection.ListIndex
    End Property
    
    Private Sub Class_Initialize()
        m_asListItems = _
            Array("FB 012.0 x 03.0", "FB 020.0 x 03.0", "FB 020.0 x 05.0", "FB 020.0 x 06.0", "FB 020.0 x 08.0", "FB 020.0 x 10.0", "FB 025.0 x 03.0", "FB 025.0 x 04.5", "FB 025.0 x 05.0", "FB 025.0 x 06.0", "FB 025.0 x 08.0", "FB 025.0 x 10.0", "FB 025.0 x 12.0", "FB 030.0 x 04.5", "FB 030.0 x 05.0", "FB 030.0 x 06.0", "FB 030.0 x 08.0", "FB 030.0 x 10.0", "FB 030.0 x 12.0", "FB 035.0 x 05.0", _
                "FB 040.0 x 04.5", "FB 040.0 x 05.0", "FB 040.0 x 06.0", "FB 040.0 x 08.0", "FB 040.0 x 10.0", "FB 040.0 x 12.0", "FB 040.0 x 16.0", "FB 040.0 x 20.0", "FB 040.0 x 25.0", "FB 047.6 x 05.0", "FB 050.0 x 05.0", "FB 050.0 x 06.0", "FB 050.0 x 08.0", "FB 050.0 x 10.0", "FB 050.0 x 12.0", "FB 050.0 x 16.0", "FB 050.0 x 20.0", "FB 050.0 x 25.0", "FB 060.0 x 06.0", "FB 060.0 x 08.0", _
                "FB 060.0 x 10.0", "FB 060.0 x 12.0", "FB 060.0 x 16.0", "FB 060.0 x 20.0", "FB 060.0 x 25.0", "FB 060.0 x 30.0", "FB 065.0 x 06.0", "FB 065.0 x 08.0", "FB 065.0 x 10.0", "FB 065.0 x 12.0", "FB 065.0 x 16.0", "FB 065.0 x 20.0", "FB 065.0 x 25.0", "FB 070.0 x 06.0", "FB 070.0 x 08.0", "FB 070.0 x 10.0", "FB 070.0 x 12.0", "FB 070.0 x 16.0", "FB 070.0 x 20.0", "FB 080.0 x 06.0", _
                "FB 080.0 x 08.0", "FB 080.0 x 10.0", "FB 080.0 x 12.0", "FB 080.0 x 16.0", "FB 080.0 x 20.0", "FB 080.0 x 25.0", "FB 080.0 x 30.0", "FB 080.0 x 40.0", "FB 090.0 x 06.0", "FB 090.0 x 08.0", "FB 090.0 x 10.0", "FB 090.0 x 12.0", "FB 090.0 x 16.0", "FB 090.0 x 20.0", "FB 090.0 x 25.0", "FB 100.0 x 06.0", "FB 100.0 x 08.0", "FB 100.0 x 10.0", "FB 100.0 x 12.0", "FB 100.0 x 16.0", _
                "FB 100.0 x 20.0", "FB 100.0 x 25.0", "FB 100.0 x 30.0", "FB 100.0 x 40.0", "FB 100.0 x 50.0", "FB 110.0 x 06.0", "FB 110.0 x 08.0", "FB 110.0 x 10.0", "FB 110.0 x 12.0", "FB 130.0 x 08.0", "FB 130.0 x 10.0", "FB 130.0 x 12.0", "FB 130.0 x 16.0", "FB 130.0 x 20.0", "FB 130.0 x 25.0", "FB 150.0 x 08.0", "FB 150.0 x 10.0", "FB 150.0 x 12.0", "FB 150.0 x 16.0", "FB 150.0 x 20.0", _
                "FB 150.0 x 25.0", "FB 150.0 x 30.0", "FB 180.0 x 10.0", "FB 180.0 x 12.0", "FB 180.0 x 16.0", "FB 180.0 x 20.0", "FB 180.0 x 25.0", "FB 200.0 x 10.0", "FB 200.0 x 12.0", "FB 200.0 x 16.0", "FB 200.0 x 18.0", "FB 200.0 x 20.0", "FB 200.0 x 25.0", "FB 200.0 x 30.0", "FB 250.0 x 10.0", "FB 250.0 x 12.0", "FB 250.0 x 16.0", "FB 250.0 x 18.0", "FB 250.0 x 20.0", "FB 250.0 x 25.0", _
                "FB 250.0 x 30.0", "FB 300.0 x 10.0", "FB 300.0 x 12.0", "FB 300.0 x 16.0", "FB 300.0 x 18.0", "FB 300.0 x 20.0", "FB 300.0 x 25.0", "FB 300.0 x 30.0", "FB 300.0 x 35.0", "FB 300.0 x 40.0", "FB 300.0 x 45.0", "FB 300.0 x 50.0", "FB 300.0 x 55.0", "FB 300.0 x 65.0", _
                "eqL 025.0 x 025.0 x 02.5", "eqL 025.0 x 025.0 x 03.0", "eqL 025.0 x 025.0 x 04.0", "eqL 025.0 x 025.0 x 05.0", "eqL 030.0 x 030.0 x 03.0", "eqL 030.0 x 030.0 x 04.0", "eqL 030.0 x 030.0 x 05.0", "eqL 040.0 x 040.0 x 02.5", "eqL 040.0 x 040.0 x 03.0", "eqL 040.0 x 040.0 x 04.0", "eqL 040.0 x 040.0 x 05.0", "eqL 040.0 x 040.0 x 06.0", "eqL 045.0 x 045.0 x 03.0", "eqL 045.0 x 045.0 x 04.0", _
                "eqL 045.0 x 045.0 x 05.0", "eqL 045.0 x 045.0 x 06.0", "eqL 050.0 x 050.0 x 03.0", "eqL 050.0 x 050.0 x 04.0", "eqL 050.0 x 050.0 x 05.0", "eqL 050.0 x 050.0 x 06.0", "eqL 050.0 x 050.0 x 08.0", "eqL 060.0 x 060.0 x 04.0", "eqL 060.0 x 060.0 x 05.0", "eqL 060.0 x 060.0 x 06.0", "eqL 060.0 x 060.0 x 08.0", "eqL 060.0 x 060.0 x 10.0", "eqL 070.0 x 070.0 x 06.0", "eqL 070.0 x 070.0 x 08.0", _
                "eqL 070.0 x 070.0 x 10.0", "eqL 080.0 x 080.0 x 06.0", "eqL 080.0 x 080.0 x 08.0", "eqL 080.0 x 080.0 x 10.0", "eqL 080.0 x 080.0 x 12.0", "eqL 090.0 x 090.0 x 06.0", "eqL 090.0 x 090.0 x 08.0", "eqL 090.0 x 090.0 x 10.0", "eqL 090.0 x 090.0 x 12.0", "eqL 100.0 x 100.0 x 08.0", "eqL 100.0 x 100.0 x 10.0", "eqL 100.0 x 100.0 x 12.0", "eqL 100.0 x 100.0 x 15.0", "eqL 120.0 x 120.0 x 08.0", _
                "eqL 120.0 x 120.0 x 10.0", "eqL 120.0 x 120.0 x 12.0", "eqL 120.0 x 120.0 x 15.0", "eqL 150.0 x 150.0 x 10.0", "eqL 150.0 x 150.0 x 12.0", "eqL 150.0 x 150.0 x 15.0", "eqL 150.0 x 150.0 x 18.0", "eqL 200.0 x 200.0 x 16.0", "eqL 200.0 x 200.0 x 18.0", "eqL 200.0 x 200.0 x 20.0", "eqL 200.0 x 200.0 x 24.0", _
                "uneqL 065.0 x 050.0 x 06.0", "uneqL 065.0 x 050.0 x 08.0", "uneqL 075.0 x 050.0 x 06.0", "uneqL 075.0 x 050.0 x 08.0", "uneqL 080.0 x 060.0 x 06.0", "uneqL 080.0 x 060.0 x 08.0", "uneqL 090.0 x 065.0 x 06.0", "uneqL 090.0 x 065.0 x 08.0", "uneqL 090.0 x 065.0 x 10.0", "uneqL 095.0 x 065.0 x 06.0", "uneqL 095.0 x 065.0 x 08.0", "uneqL 095.0 x 065.0 x 10.0", _
                "uneqL 100.0 x 065.0 x 08.0", "uneqL 100.0 x 065.0 x 10.0", "uneqL 100.0 x 075.0 x 06.0", "uneqL 100.0 x 075.0 x 08.0", "uneqL 100.0 x 075.0 x 10.0", "uneqL 100.0 x 075.0 x 12.0", "uneqL 125.0 x 075.0 x 08.0", "uneqL 125.0 x 075.0 x 10.0", "uneqL 125.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 10.0", "uneqL 150.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 15.0", _
                "uneqL 150.0 x 090.0 x 10.0", "uneqL 150.0 x 090.0 x 12.0", "uneqL 150.0 x 090.0 x 15.0")
        
    End Sub
    
    Private Sub Class_Terminate()
        Set m_ctlListControl = Nothing
    End Sub
    
    Public Property Get ListControl() As MSForms.Control
        Set ListControl = m_ctlListControl
    End Property
    
    Public Property Set ListControl(ctlListControl As MSForms.Control)
        Select Case TypeName(ctlListControl)
            Case "ListBox", "ComboBox"
                Set m_ctlListControl = ctlListControl
                m_ctlListControl.List = m_asListItems
            Case Else
                ' up to you - maybe raise an error?
        End Select
    End Property
    I'm getting a run-time 91 error on:
    MsgBox oList.Value & vbLf & oList.ListIndex

  7. #7
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Hi Steffen,

    I'm also not able to get your code to work, not sure why.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    It's really not clear why you are doing this.
    It's also very confused code.

    You have declared the object m_cmbFlangeSection but then not used it, which is the reason for my code error.

    When I change the reference in the class and modify the userform code it works.

    I've removed the line where you declare a new instance of the object.
    Value is not a property available for generic msforms.Controls.

    Private Sub ComboBox1_Change()
        MsgBox oList.ListIndex
    End Sub
    But the issue now is why the class when you are coding against the combox events on the userform. As I said if all you want to do is load the control with a static list use a function in a standard code module. Or as Romperstomper suggested originally read the information from a file.

  9. #9
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    The combobox is used in a Engineering form. The user selects a value in the combobox and then the class goes through a series of calculations, calculating the running mass (kg/m), the paint area (m²), etc. These properties are then returned to the user form for further calculations.

    The custom combo, just like some of the others I am/ will be working on, is to be used on various types of Engineering forms, each calculating something else. The excel file (before the user uses it) will be a template file, stored under our templates folder, and then when changed into a normal .xlsm file, be moved to the relevant project folder.

    The reason why I dont want to have the combobox reference to a stand-alone file, is that, if the structure of our system changes, or we realise that our designs are not optimum and we then decide to change the design calculations, it will influence existing designs, and I'd like to keep what we have designed at a specific time, to remain as is, no matter what other decision is later made.

    As for the code change you suggest, I'll try now to see if it works.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    So you need to move your calculation code into the class code using the events of the object your declared but as yet are not using.

    There should be no need for code in the combobox on the user forms events.

    Once you have done the class level calculations you can raise your own events in the class and capture those in the userform.

  11. #11
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    I would for instance take the selection and split the string, remove what is standing in the front, and split at the "x", giving me three values, these I would use in calculations.

  12. #12
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Damn it is nice to talk to the experts, and sorry for not quit explaining what I want to achieve in words that all can understand.

    How would I achieve this?

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    class code
    Public m_ctlListControl As MSForms.Control
    Public m_asListItems As Variant
    Public WithEvents m_cmbFlangeSection As MSForms.ComboBox
    
    Public Event FlangeCalc(Prefix As String, Value As Double)
    Public Property Get ListIndex() As Long
        ListIndex = m_cmbFlangeSection.ListIndex
    End Property
    
    Public Property Get Value() As String
        Value = m_cmbFlangeSection.Value
    End Property
    
    
    Private Sub Class_Initialize()
        m_asListItems = _
            Array("FB 012.0 x 03.0", "FB 020.0 x 03.0", "FB 020.0 x 05.0", "FB 020.0 x 06.0", "FB 020.0 x 08.0", "FB 020.0 x 10.0", "FB 025.0 x 03.0", "FB 025.0 x 04.5", "FB 025.0 x 05.0", "FB 025.0 x 06.0", "FB 025.0 x 08.0", "FB 025.0 x 10.0", "FB 025.0 x 12.0", "FB 030.0 x 04.5", "FB 030.0 x 05.0", "FB 030.0 x 06.0", "FB 030.0 x 08.0", "FB 030.0 x 10.0", "FB 030.0 x 12.0", "FB 035.0 x 05.0", _
                "FB 040.0 x 04.5", "FB 040.0 x 05.0", "FB 040.0 x 06.0", "FB 040.0 x 08.0", "FB 040.0 x 10.0", "FB 040.0 x 12.0", "FB 040.0 x 16.0", "FB 040.0 x 20.0", "FB 040.0 x 25.0", "FB 047.6 x 05.0", "FB 050.0 x 05.0", "FB 050.0 x 06.0", "FB 050.0 x 08.0", "FB 050.0 x 10.0", "FB 050.0 x 12.0", "FB 050.0 x 16.0", "FB 050.0 x 20.0", "FB 050.0 x 25.0", "FB 060.0 x 06.0", "FB 060.0 x 08.0", _
                "FB 060.0 x 10.0", "FB 060.0 x 12.0", "FB 060.0 x 16.0", "FB 060.0 x 20.0", "FB 060.0 x 25.0", "FB 060.0 x 30.0", "FB 065.0 x 06.0", "FB 065.0 x 08.0", "FB 065.0 x 10.0", "FB 065.0 x 12.0", "FB 065.0 x 16.0", "FB 065.0 x 20.0", "FB 065.0 x 25.0", "FB 070.0 x 06.0", "FB 070.0 x 08.0", "FB 070.0 x 10.0", "FB 070.0 x 12.0", "FB 070.0 x 16.0", "FB 070.0 x 20.0", "FB 080.0 x 06.0", _
                "FB 080.0 x 08.0", "FB 080.0 x 10.0", "FB 080.0 x 12.0", "FB 080.0 x 16.0", "FB 080.0 x 20.0", "FB 080.0 x 25.0", "FB 080.0 x 30.0", "FB 080.0 x 40.0", "FB 090.0 x 06.0", "FB 090.0 x 08.0", "FB 090.0 x 10.0", "FB 090.0 x 12.0", "FB 090.0 x 16.0", "FB 090.0 x 20.0", "FB 090.0 x 25.0", "FB 100.0 x 06.0", "FB 100.0 x 08.0", "FB 100.0 x 10.0", "FB 100.0 x 12.0", "FB 100.0 x 16.0", _
                "FB 100.0 x 20.0", "FB 100.0 x 25.0", "FB 100.0 x 30.0", "FB 100.0 x 40.0", "FB 100.0 x 50.0", "FB 110.0 x 06.0", "FB 110.0 x 08.0", "FB 110.0 x 10.0", "FB 110.0 x 12.0", "FB 130.0 x 08.0", "FB 130.0 x 10.0", "FB 130.0 x 12.0", "FB 130.0 x 16.0", "FB 130.0 x 20.0", "FB 130.0 x 25.0", "FB 150.0 x 08.0", "FB 150.0 x 10.0", "FB 150.0 x 12.0", "FB 150.0 x 16.0", "FB 150.0 x 20.0", _
                "FB 150.0 x 25.0", "FB 150.0 x 30.0", "FB 180.0 x 10.0", "FB 180.0 x 12.0", "FB 180.0 x 16.0", "FB 180.0 x 20.0", "FB 180.0 x 25.0", "FB 200.0 x 10.0", "FB 200.0 x 12.0", "FB 200.0 x 16.0", "FB 200.0 x 18.0", "FB 200.0 x 20.0", "FB 200.0 x 25.0", "FB 200.0 x 30.0", "FB 250.0 x 10.0", "FB 250.0 x 12.0", "FB 250.0 x 16.0", "FB 250.0 x 18.0", "FB 250.0 x 20.0", "FB 250.0 x 25.0", _
                "FB 250.0 x 30.0", "FB 300.0 x 10.0", "FB 300.0 x 12.0", "FB 300.0 x 16.0", "FB 300.0 x 18.0", "FB 300.0 x 20.0", "FB 300.0 x 25.0", "FB 300.0 x 30.0", "FB 300.0 x 35.0", "FB 300.0 x 40.0", "FB 300.0 x 45.0", "FB 300.0 x 50.0", "FB 300.0 x 55.0", "FB 300.0 x 65.0", _
                "eqL 025.0 x 025.0 x 02.5", "eqL 025.0 x 025.0 x 03.0", "eqL 025.0 x 025.0 x 04.0", "eqL 025.0 x 025.0 x 05.0", "eqL 030.0 x 030.0 x 03.0", "eqL 030.0 x 030.0 x 04.0", "eqL 030.0 x 030.0 x 05.0", "eqL 040.0 x 040.0 x 02.5", "eqL 040.0 x 040.0 x 03.0", "eqL 040.0 x 040.0 x 04.0", "eqL 040.0 x 040.0 x 05.0", "eqL 040.0 x 040.0 x 06.0", "eqL 045.0 x 045.0 x 03.0", "eqL 045.0 x 045.0 x 04.0", _
                "eqL 045.0 x 045.0 x 05.0", "eqL 045.0 x 045.0 x 06.0", "eqL 050.0 x 050.0 x 03.0", "eqL 050.0 x 050.0 x 04.0", "eqL 050.0 x 050.0 x 05.0", "eqL 050.0 x 050.0 x 06.0", "eqL 050.0 x 050.0 x 08.0", "eqL 060.0 x 060.0 x 04.0", "eqL 060.0 x 060.0 x 05.0", "eqL 060.0 x 060.0 x 06.0", "eqL 060.0 x 060.0 x 08.0", "eqL 060.0 x 060.0 x 10.0", "eqL 070.0 x 070.0 x 06.0", "eqL 070.0 x 070.0 x 08.0", _
                "eqL 070.0 x 070.0 x 10.0", "eqL 080.0 x 080.0 x 06.0", "eqL 080.0 x 080.0 x 08.0", "eqL 080.0 x 080.0 x 10.0", "eqL 080.0 x 080.0 x 12.0", "eqL 090.0 x 090.0 x 06.0", "eqL 090.0 x 090.0 x 08.0", "eqL 090.0 x 090.0 x 10.0", "eqL 090.0 x 090.0 x 12.0", "eqL 100.0 x 100.0 x 08.0", "eqL 100.0 x 100.0 x 10.0", "eqL 100.0 x 100.0 x 12.0", "eqL 100.0 x 100.0 x 15.0", "eqL 120.0 x 120.0 x 08.0", _
                "eqL 120.0 x 120.0 x 10.0", "eqL 120.0 x 120.0 x 12.0", "eqL 120.0 x 120.0 x 15.0", "eqL 150.0 x 150.0 x 10.0", "eqL 150.0 x 150.0 x 12.0", "eqL 150.0 x 150.0 x 15.0", "eqL 150.0 x 150.0 x 18.0", "eqL 200.0 x 200.0 x 16.0", "eqL 200.0 x 200.0 x 18.0", "eqL 200.0 x 200.0 x 20.0", "eqL 200.0 x 200.0 x 24.0", _
                "uneqL 065.0 x 050.0 x 06.0", "uneqL 065.0 x 050.0 x 08.0", "uneqL 075.0 x 050.0 x 06.0", "uneqL 075.0 x 050.0 x 08.0", "uneqL 080.0 x 060.0 x 06.0", "uneqL 080.0 x 060.0 x 08.0", "uneqL 090.0 x 065.0 x 06.0", "uneqL 090.0 x 065.0 x 08.0", "uneqL 090.0 x 065.0 x 10.0", "uneqL 095.0 x 065.0 x 06.0", "uneqL 095.0 x 065.0 x 08.0", "uneqL 095.0 x 065.0 x 10.0", _
                "uneqL 100.0 x 065.0 x 08.0", "uneqL 100.0 x 065.0 x 10.0", "uneqL 100.0 x 075.0 x 06.0", "uneqL 100.0 x 075.0 x 08.0", "uneqL 100.0 x 075.0 x 10.0", "uneqL 100.0 x 075.0 x 12.0", "uneqL 125.0 x 075.0 x 08.0", "uneqL 125.0 x 075.0 x 10.0", "uneqL 125.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 10.0", "uneqL 150.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 15.0", _
                "uneqL 150.0 x 090.0 x 10.0", "uneqL 150.0 x 090.0 x 12.0", "uneqL 150.0 x 090.0 x 15.0")
                
    End Sub
    
    Private Sub Class_Terminate()
        Set m_ctlListControl = Nothing
    End Sub
    
    Public Property Get ListControl() As MSForms.Control
        Set ListControl = m_ctlListControl
    End Property
    
    Public Property Set ListControl(ctlListControl As MSForms.Control)
        Select Case TypeName(ctlListControl)
            Case "ListBox", "ComboBox"
                Set m_ctlListControl = ctlListControl
                m_ctlListControl.List = m_asListItems
            Case Else
                ' up to you - maybe raise an error?
        End Select
    End Property
    
    Private Sub m_cmbFlangeSection_Change()
    
        Dim vntItems As Variant
        Dim vntItem As Variant
        Dim strText As String
        Dim lngPos As Long
        Dim dblTotal As Double
        Dim blnNoValue As Boolean
        
        If m_cmbFlangeSection.ListIndex >= 0 Then
            strText = m_cmbFlangeSection.Value
            lngPos = InStr(1, strText, Space(1), vbTextCompare)
            If lngPos > 0 Then
                vntItems = Split(Mid(strText, lngPos + 1), "x")
                dblTotal = 1
                blnNoValue = True
                For Each vntItem In vntItems
                    If IsNumeric(Trim(vntItem)) Then
                        dblTotal = dblTotal * CDbl(Trim(vntItem))
                        blnNoValue = False
                    End If
                Next
                If blnNoValue Then dblTotal = 0
                RaiseEvent FlangeCalc(Trim(Left(strText, lngPos)), dblTotal)
            End If
        End If
    
    End Sub
    Userform code
    Option Explicit
    
    'Form code:
    
    Dim WithEvents oList As cls_combobox_FlangeSection
    
    Private Sub oList_FlangeCalc(Prefix As String, Value As Double)
    
        MsgBox "User selected " & oList.Value & vbLf & "Prefix = " & Prefix & vbLf & "Total=" & Value
        
    End Sub
    
    
    Private Sub UserForm_Initialize()
        Set oList = New cls_combobox_FlangeSection
        Set oList.ListControl = Me.ComboBox1
        Set oList.m_cmbFlangeSection = Me.ComboBox1
    End Sub
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Thanks for the reply Andy, it seems to do something like what I'd like to achieve, I'm going off-line for a bit (work is calling), but I will post again in this thread, even if it is just to say SOLVED...

    Thanks again.

  15. #15
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Morning guys,

    So I have made a couple of adjustments, and it works perfectly, thank you very much.

    Here is the final code as I will be using it in my forms:

    'Code: Class: cls_combobox_FlangeSection
    
    Option Explicit
    
    Public m_ctlListControl As MSForms.Control
    Public m_asListItems As Variant
    Public WithEvents m_cmbFlangeSection As MSForms.ComboBox
    
    Public Event FlangeCalc(m_Height As Double, m_Thickness As Double, m_Width As Double, _
                            m_crossArea As Double, m_massperMeter As Double)
    
    Public Property Get ListIndex() As Long
        ListIndex = m_cmbFlangeSection.ListIndex
    End Property
    
    Public Property Get Value() As String
        Value = m_cmbFlangeSection.Value
    End Property
    
    Private Sub Class_Initialize()
        m_asListItems = _
            Array("FB 012.0 x 03.0", "FB 020.0 x 03.0", "FB 020.0 x 05.0", "FB 020.0 x 06.0", "FB 020.0 x 08.0", "FB 020.0 x 10.0", "FB 025.0 x 03.0", "FB 025.0 x 04.5", "FB 025.0 x 05.0", "FB 025.0 x 06.0", "FB 025.0 x 08.0", "FB 025.0 x 10.0", "FB 025.0 x 12.0", "FB 030.0 x 04.5", "FB 030.0 x 05.0", "FB 030.0 x 06.0", "FB 030.0 x 08.0", "FB 030.0 x 10.0", "FB 030.0 x 12.0", "FB 035.0 x 05.0", _
                "FB 040.0 x 04.5", "FB 040.0 x 05.0", "FB 040.0 x 06.0", "FB 040.0 x 08.0", "FB 040.0 x 10.0", "FB 040.0 x 12.0", "FB 040.0 x 16.0", "FB 040.0 x 20.0", "FB 040.0 x 25.0", "FB 047.6 x 05.0", "FB 050.0 x 05.0", "FB 050.0 x 06.0", "FB 050.0 x 08.0", "FB 050.0 x 10.0", "FB 050.0 x 12.0", "FB 050.0 x 16.0", "FB 050.0 x 20.0", "FB 050.0 x 25.0", "FB 060.0 x 06.0", "FB 060.0 x 08.0", _
                "FB 060.0 x 10.0", "FB 060.0 x 12.0", "FB 060.0 x 16.0", "FB 060.0 x 20.0", "FB 060.0 x 25.0", "FB 060.0 x 30.0", "FB 065.0 x 06.0", "FB 065.0 x 08.0", "FB 065.0 x 10.0", "FB 065.0 x 12.0", "FB 065.0 x 16.0", "FB 065.0 x 20.0", "FB 065.0 x 25.0", "FB 070.0 x 06.0", "FB 070.0 x 08.0", "FB 070.0 x 10.0", "FB 070.0 x 12.0", "FB 070.0 x 16.0", "FB 070.0 x 20.0", "FB 080.0 x 06.0", _
                "FB 080.0 x 08.0", "FB 080.0 x 10.0", "FB 080.0 x 12.0", "FB 080.0 x 16.0", "FB 080.0 x 20.0", "FB 080.0 x 25.0", "FB 080.0 x 30.0", "FB 080.0 x 40.0", "FB 090.0 x 06.0", "FB 090.0 x 08.0", "FB 090.0 x 10.0", "FB 090.0 x 12.0", "FB 090.0 x 16.0", "FB 090.0 x 20.0", "FB 090.0 x 25.0", "FB 100.0 x 06.0", "FB 100.0 x 08.0", "FB 100.0 x 10.0", "FB 100.0 x 12.0", "FB 100.0 x 16.0", _
                "FB 100.0 x 20.0", "FB 100.0 x 25.0", "FB 100.0 x 30.0", "FB 100.0 x 40.0", "FB 100.0 x 50.0", "FB 110.0 x 06.0", "FB 110.0 x 08.0", "FB 110.0 x 10.0", "FB 110.0 x 12.0", "FB 130.0 x 08.0", "FB 130.0 x 10.0", "FB 130.0 x 12.0", "FB 130.0 x 16.0", "FB 130.0 x 20.0", "FB 130.0 x 25.0", "FB 150.0 x 08.0", "FB 150.0 x 10.0", "FB 150.0 x 12.0", "FB 150.0 x 16.0", "FB 150.0 x 20.0", _
                "FB 150.0 x 25.0", "FB 150.0 x 30.0", "FB 180.0 x 10.0", "FB 180.0 x 12.0", "FB 180.0 x 16.0", "FB 180.0 x 20.0", "FB 180.0 x 25.0", "FB 200.0 x 10.0", "FB 200.0 x 12.0", "FB 200.0 x 16.0", "FB 200.0 x 18.0", "FB 200.0 x 20.0", "FB 200.0 x 25.0", "FB 200.0 x 30.0", "FB 250.0 x 10.0", "FB 250.0 x 12.0", "FB 250.0 x 16.0", "FB 250.0 x 18.0", "FB 250.0 x 20.0", "FB 250.0 x 25.0", _
                "FB 250.0 x 30.0", "FB 300.0 x 10.0", "FB 300.0 x 12.0", "FB 300.0 x 16.0", "FB 300.0 x 18.0", "FB 300.0 x 20.0", "FB 300.0 x 25.0", "FB 300.0 x 30.0", "FB 300.0 x 35.0", "FB 300.0 x 40.0", "FB 300.0 x 45.0", "FB 300.0 x 50.0", "FB 300.0 x 55.0", "FB 300.0 x 65.0", _
                "eqL 025.0 x 025.0 x 02.5", "eqL 025.0 x 025.0 x 03.0", "eqL 025.0 x 025.0 x 04.0", "eqL 025.0 x 025.0 x 05.0", "eqL 030.0 x 030.0 x 03.0", "eqL 030.0 x 030.0 x 04.0", "eqL 030.0 x 030.0 x 05.0", "eqL 040.0 x 040.0 x 02.5", "eqL 040.0 x 040.0 x 03.0", "eqL 040.0 x 040.0 x 04.0", "eqL 040.0 x 040.0 x 05.0", "eqL 040.0 x 040.0 x 06.0", "eqL 045.0 x 045.0 x 03.0", "eqL 045.0 x 045.0 x 04.0", _
                "eqL 045.0 x 045.0 x 05.0", "eqL 045.0 x 045.0 x 06.0", "eqL 050.0 x 050.0 x 03.0", "eqL 050.0 x 050.0 x 04.0", "eqL 050.0 x 050.0 x 05.0", "eqL 050.0 x 050.0 x 06.0", "eqL 050.0 x 050.0 x 08.0", "eqL 060.0 x 060.0 x 04.0", "eqL 060.0 x 060.0 x 05.0", "eqL 060.0 x 060.0 x 06.0", "eqL 060.0 x 060.0 x 08.0", "eqL 060.0 x 060.0 x 10.0", "eqL 070.0 x 070.0 x 06.0", "eqL 070.0 x 070.0 x 08.0", _
                "eqL 070.0 x 070.0 x 10.0", "eqL 080.0 x 080.0 x 06.0", "eqL 080.0 x 080.0 x 08.0", "eqL 080.0 x 080.0 x 10.0", "eqL 080.0 x 080.0 x 12.0", "eqL 090.0 x 090.0 x 06.0", "eqL 090.0 x 090.0 x 08.0", "eqL 090.0 x 090.0 x 10.0", "eqL 090.0 x 090.0 x 12.0", "eqL 100.0 x 100.0 x 08.0", "eqL 100.0 x 100.0 x 10.0", "eqL 100.0 x 100.0 x 12.0", "eqL 100.0 x 100.0 x 15.0", "eqL 120.0 x 120.0 x 08.0", _
                "eqL 120.0 x 120.0 x 10.0", "eqL 120.0 x 120.0 x 12.0", "eqL 120.0 x 120.0 x 15.0", "eqL 150.0 x 150.0 x 10.0", "eqL 150.0 x 150.0 x 12.0", "eqL 150.0 x 150.0 x 15.0", "eqL 150.0 x 150.0 x 18.0", "eqL 200.0 x 200.0 x 16.0", "eqL 200.0 x 200.0 x 18.0", "eqL 200.0 x 200.0 x 20.0", "eqL 200.0 x 200.0 x 24.0", _
                "uneqL 065.0 x 050.0 x 06.0", "uneqL 065.0 x 050.0 x 08.0", "uneqL 075.0 x 050.0 x 06.0", "uneqL 075.0 x 050.0 x 08.0", "uneqL 080.0 x 060.0 x 06.0", "uneqL 080.0 x 060.0 x 08.0", "uneqL 090.0 x 065.0 x 06.0", "uneqL 090.0 x 065.0 x 08.0", "uneqL 090.0 x 065.0 x 10.0", "uneqL 095.0 x 065.0 x 06.0", "uneqL 095.0 x 065.0 x 08.0", "uneqL 095.0 x 065.0 x 10.0", _
                "uneqL 100.0 x 065.0 x 08.0", "uneqL 100.0 x 065.0 x 10.0", "uneqL 100.0 x 075.0 x 06.0", "uneqL 100.0 x 075.0 x 08.0", "uneqL 100.0 x 075.0 x 10.0", "uneqL 100.0 x 075.0 x 12.0", "uneqL 125.0 x 075.0 x 08.0", "uneqL 125.0 x 075.0 x 10.0", "uneqL 125.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 10.0", "uneqL 150.0 x 075.0 x 12.0", "uneqL 150.0 x 075.0 x 15.0", _
                "uneqL 150.0 x 090.0 x 10.0", "uneqL 150.0 x 090.0 x 12.0", "uneqL 150.0 x 090.0 x 15.0")
                
    End Sub
    
    Private Sub Class_Terminate()
        Set m_ctlListControl = Nothing
    End Sub
    
    Public Property Get ListControl() As MSForms.Control
        Set ListControl = m_ctlListControl
    End Property
    
    Public Property Set ListControl(ctlListControl As MSForms.Control)
        Select Case TypeName(ctlListControl)
            Case "ListBox", "ComboBox"
                Set m_ctlListControl = ctlListControl
                m_ctlListControl.List = m_asListItems
            Case Else
                ' up to you - maybe raise an error?
        End Select
    End Property
    
    Private Sub m_cmbFlangeSection_Change()
    
        Dim m_Height As Double
        Dim m_Thickness As Double
        Dim m_Width As Double
        Dim m_crossArea As Double
        Dim m_massperMeter As Double
        Dim sizeArray() As String
    
        If m_cmbFlangeSection.ListIndex >= 0 Then
            sizeArray = Split(m_cmbFlangeSection.Value, " x ")
            m_Height = sizeArray(1) / 1000
            m_Width = Right(sizeArray(0), Len(sizeArray(0)) - InStr(sizeArray(0), " ")) / 1000
            
            If UBound(sizeArray) < 2 Then
                m_Thickness = 0
            Else
                m_Thickness = sizeArray(2) / 1000
            End If
            
            If m_Thickness = 0 Then
                m_crossArea = m_Height * m_Width
            Else
                m_crossArea = m_Height * m_Width - ((m_Height - m_Thickness) * _
                                    (m_Width - m_Thickness))
            End If
            
            m_massperMeter = m_crossArea * 7850
            
            RaiseEvent FlangeCalc(m_Height, m_Thickness, m_Width, m_crossArea, m_massperMeter)
    
        End If
    
    End Sub
    'Code: Form
    
    Option Explicit
    
    Dim flangeHeight As Double
    Dim flangeWidth As Double
    Dim flangeThickness As Double
    Dim flangeCrossArea As Double
    Dim flangeMassPerMeter As Double
    
    Dim WithEvents oList As cls_combobox_FlangeSection
    
    Private Sub oList_FlangeCalc(m_Height As Double, m_Thickness As Double, m_Width As Double, _
                    m_crossArea As Double, m_massperMeter As Double)
    
        flangeHeight = m_Height
        flangeWidth = m_Width
        flangeThickness = m_Thickness
        flangeCrossArea = m_crossArea
        flangeMassPerMeter = m_massperMeter
        
    End Sub
    
    Private Sub UserForm_Initialize()
        Set oList = New cls_combobox_FlangeSection
        Set oList.ListControl = Me.ComboBox1
        Set oList.m_cmbFlangeSection = Me.ComboBox1
    End Sub
    For now I'll say this is solved, but if anyone can point out if I can "clean up" my code, please feel free to do so.

  16. #16
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    Instead of private variables in the userform why not keep all those flange values within in the class itself and expose them as properties, maybe even read-only properties.
    You could then remove them from the FlangeCalc event signature.

  17. #17
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    How would I do this? Sorry Andy, I'm very new to the concept of classes

  18. #18
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    See attached.

    I made 1 of the properties read/write by including both Get/Let properties. The others are read-only.
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    That is fantastic!!! It makes the code I require in my form so much less.

    So the flangeHeight is the read-write one, but what does RHS stand for?

  20. #20
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    It's a coding style I picked up from the PED book.

    RHS - RightHandSide

    Class.MyProperty = MyVariable
    Public Property Let MyProperty(RHS as long)
       m_lngProp = RHS
    End property

  21. #21
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    So if I want the height to be read-only, I simply remove the let sub()?

    I was wondering if there are books available for more advanced programming...

  22. #22
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing combobox value to custom class

    Yes. For a property

    Get & Let = Read/Write
    Get only = Read only
    Let only = Write only

    You can not beat the book in the link.

  23. #23
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Passing combobox value to custom class

    Thanks a million

    This thread is then SOLVED.

    Thanks to all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1