Results 1 to 14 of 14

Thread: [RESOLVED] Not call _Change() functions

  1. #1

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Resolved [RESOLVED] Not call _Change() functions

    Hey there,

    I'm sure this has been asked before, but I was unable to find an answer... I have a combobox on a form that's properties gets initialized in the UserForm_Init method... However, the combobox also has a _Change() method, but I don't want that Change method to be called in the init method of the userForm...

    Is there a way to specify this in either the init or change methods?

    thanks much,

    Paul

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Not call _Change() functions

    I don't want that Change method to be called in the init method of the userForm...
    but then the _Change() is as it is not called in the UserForm_Init method

    What is the code in the UserForm_Init ? I mean what properties are you trying to initialize in the UserForm_Init for the combo?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Lively Member
    Join Date
    Jun 2008
    Location
    Chicago and Grand Rapids
    Posts
    95

    Re: Not call _Change() functions

    hey paul

    whenever i have to deal with this i implement a "flag" of sorts to tell whether or not to do the actions. sometimes i make the flag global, otherwise just modular (depending on the scope needed).

    i implement it as follows
    1) dim it wherever you want (so the scope is correct)
    2) set it to "False" as the first step in the UF_Init routine
    3) do all the uf initialization
    4) set it to true when exiting the UF_init routine

    then, in any "Change" or similar event, just check if your boolean flag is true or false. true - do the change event code. false - just exit

    hth
    vw = Volkswagen
    gti = GTI
    R32 = R32
    vr6 = VR6 engine
    lets go racing

  4. #4

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Not call _Change() functions

    Well, in the UserForm_Init, I change the text of the combo box.. doesn't changing that text call the change() method of that combo box?

    because during init I don't want the change method to be called, as it looks something up in a table that shouldn't be done at that point.

  5. #5

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Not call _Change() functions

    Quote Originally Posted by vwgtir32vr6
    hey paul

    whenever i have to deal with this i implement a "flag" of sorts to tell whether or not to do the actions. sometimes i make the flag global, otherwise just modular (depending on the scope needed).

    i implement it as follows
    1) dim it wherever you want (so the scope is correct)
    2) set it to "False" as the first step in the UF_Init routine
    3) do all the uf initialization
    4) set it to true when exiting the UF_init routine

    then, in any "Change" or similar event, just check if your boolean flag is true or false. true - do the change event code. false - just exit

    hth
    ah great... was hoping there might just be a vba command to ignore change methods, but implementing these booleans shouldn't be too tricky. thanks much

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Not call _Change() functions

    Well, in the UserForm_Init, I change the text of the combo box
    Ah no wonder...

    Just a question, why not prefeed the text of the combobox in design mode and set rest of the properties in the init() code? that will save you lots of coding....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Not call _Change() functions

    Well, it's not always the same... I read the text from a file.

  8. #8
    Lively Member
    Join Date
    Jun 2008
    Location
    Chicago and Grand Rapids
    Posts
    95

    Re: [RESOLVED] Not call _Change() functions

    ya, that command would be nice, but as far as i know it doesn't exist... oh well.

    koolsid, that is a good idea, but as is the case with most of my projects, the text for my comboboxes and listviews is "discovered" as part of the init routine (x and y variables on the active worksheet, for instance). in that case, i can't prefeed the text. i see your point though.
    vw = Volkswagen
    gti = GTI
    R32 = R32
    vr6 = VR6 engine
    lets go racing

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Not call _Change() functions

    Well, it's not always the same... I read the text from a file.
    In that case, yes, using a flag as vwgtir32vr6 suggested is apt.

    Also on second thoughts, here is another way I'd do it...

    Keep the text constant. Now my question would be what text should i set in design mode so that it is constant everytime??? something like "Please select your option" and in the init() event I simply add items to the combobox??? ..... additem doesn't fire the change() event

    It is just a thought...

    your views guys...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10
    Lively Member
    Join Date
    Jun 2008
    Location
    Chicago and Grand Rapids
    Posts
    95

    Re: [RESOLVED] Not call _Change() functions

    yes that would work. i have never considered that because i am a little surprised that the .AddItem does not fire the change event. that would work good also it sounds like. i tend to prefer the flag approach because it is very easy to handle whatever event you have to deal with and it is simple to code. as is usually the case, there are a million ways to accomplish this task though...
    vw = Volkswagen
    gti = GTI
    R32 = R32
    vr6 = VR6 engine
    lets go racing

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Not call _Change() functions

    it doesn't...

    try this

    place a combo on a userform and then use this code. now run the userform. you will see that the change code is not fired....

    Code:
    Private Sub ComboBox1_Change()
        MsgBox "hello"
    End Sub
    
    Private Sub UserForm_Initialize()
        ComboBox1.AddItem "aaaa"
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Not call _Change() functions

    that's a good point sid... but in one of my combo box's there are about 300 items, so the whole point of automatically changing the text of the combo box was so that the user didn't have to tediously select their input.

    still overall, a little odd that MS doesn't at least offer some sort of way to bypass the change events...

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Not call _Change() functions

    .... about 300 items...
    Since we are having an intelligent conversation... I have one more point to add...

    I am sure that you are aware that the combobox autocompletes as you type??? so selecting your choice from a 300 or 500 entries is not a problem... what say?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Not call _Change() functions

    Hah yeah that is true...

    But the program itself has about 100 inputs with about 15 combo boxes and 5 forms... so if a user progresses through all the screens and decides to save the input/output, then they can open that file again and all the inputs are opened in the screens... saving the user from remembering what they even input. Before each form is displayed, if a file was opened, those inputs are brought into the form during the init, however, as I learned that was throwing the change() code, which would actually change their inputs to default numbers (as I have the change() code structured).

    I just implemented the modular boolean flags, and they are working great!

    So I guess in this situation, the flags were the only way to do it... basically for ease of use of the user!

Posting Permissions

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



Click Here to Expand Forum to Full Width