Results 1 to 19 of 19

Thread: Changing Values without Firing Events

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    26

    Changing Values without Firing Events

    Hello, I have a headache. I have so many controls on this form and they all interact with each other, but there is one problem. I can't change the contents without triggering an event. For instance, I am displaying data from a DB and I put this:
    Code:
    chkTaking(0).Value = True
    But because chkTaking(0) has a click event that is built into it, it runs when I say that which produces errors. Is there a way that I can change the .Value of the control without triggering its event?
    Thanks a lot.
    ~evlich

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I would create a form-level boolean variable that you could use to know when to bypass such events.

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    or maybe something like this:

    chkTaking(0).Tag = "No"
    chkTaking(0).Value = True

    then in the Check or click event whatver:

    If chkTaking(Index).Tag = "No" Then chkTaking(Index).Tag = "": Exit Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    26
    But then how would the user be able to see that it was changed?
    ~evlich

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    IF you changed it by code (Tag = "No"), then it would not register as a click, but it would still appear checked. IF you didn't (Tag = "") then it would do whatever was in the event.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by Lethal
    I would create a form-level boolean variable that you could use to know when to bypass such events.
    This is how I handle things too... it's probably the easiest to implement, and it works great.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Me two.... I cannot think of a better way. It's pretty effective.

    I have to admit, the Tag-way also works... but only if you're not using it for something else.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. ' In Declarartion Area
    2.  
    3. Dim BOOLCANCEL as Boolean
    4.  
    5. ' In Click Event of control you want to handle
    6.  
    7. If BOOLCANCEL = FALSE Then
    8.  
    9. ' Perform the click event...
    10.  
    11. ' When setting something you know will fire click event use :
    12.  
    13. BOOLCANCEL = TRUE
    14.  
    15. ' Run your code
    16.  
    17. BOOLCANCEL = FALSE

    Does this make sense?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    26
    I understand what you are saying. That would probably work. I just thought that there might be a better way. How would the tag way work, just for knowledge.
    Thanks a lot.
    ~evlich

  10. #10
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    i showed you how the tag way works, up several posts.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  11. #11
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by evlich
    I understand what you are saying. That would probably work. I just thought that there might be a better way. How would the tag way work, just for knowledge.
    Thanks a lot.
    You could use the Tag property, but if you want to use TAag for another use, you'd be limited. It is still best to go with the form level variable..
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  12. #12
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857

    Re: Well

    Originally posted by James Stanich
    VB Code:
    1. ' In Declarartion Area
    2.  
    3. Dim BOOLCANCEL as Boolean
    4.  
    5. ' In Click Event of control you want to handle
    6.  
    7. If BOOLCANCEL = FALSE Then
    8.  
    9. ' Perform the click event...
    10.  
    11. ' When setting something you know will fire click event use :
    12.  
    13. BOOLCANCEL = TRUE
    14.  
    15. ' Run your code
    16.  
    17. BOOLCANCEL = FALSE

    Does this make sense?
    I agree with James I think this is the easiest and cleanest. I call my boolean varialble "ClickedByUser"

    VB Code:
    1. Dim ClickedByUser as boolean
    2.  
    3. Sub Something()
    4.  
    5. 'Call the command1 click event
    6. ClickedByUser = False
    7. Command1_Click
    8.  
    9. End Sub
    10.  
    11. Sub Command1_Click()
    12.  
    13. 'see if user cliced me or program clicked me
    14. If ClickedByUser Then
    15.    'user code here
    16. Else
    17.    'program code here
    18.    
    19.    'reset my variable
    20.     ClickedByUser = True
    21. End if
    22.  
    23. End Sub
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  13. #13
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    See yet another user who agrees with the form level variable...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  14. #14
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    blnFreezeEvents for me. Wth Tag you would have to set the tag for every control that would be affected directly or indirectly and then reset the tags (not in the events but) only after it is OK to have the events called again. A public flag works best for me.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    26
    Thanks a lot. I got the form level variable to work. Appreciate all your help.
    ~evlich

  16. #16
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    For waht itws worth, you are welcome...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  17. #17
    Addicted Member
    Join Date
    Aug 2000
    Location
    Adelaide - Australia
    Posts
    150
    My suggestion, and what i have been doing to get around your problem is to include a "Friend" proerty so that you can change the value without firing the event.

    so the user uses this
    chkTaking(0).Value = True

    Public Property Let Value(newValue as Boolean)
    m_Value = newValue
    Raiseevent ValueChanged()
    End Property

    you use
    chkTaking(0).SetValue = True
    where SetValue is something like
    Friend Property Let Value(newValue as Boolean)
    m_Value = newValue
    End Property

  18. #18
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Gary007...

    Isn't that a long work-around to what we have already posted?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  19. #19
    Addicted Member
    Join Date
    Aug 2000
    Location
    Adelaide - Australia
    Posts
    150
    My method quite possibly is a long work around but it saves on a variable, and one less thing that could go wrong, especially when you start doing multi threading and things like that. When you have variables that control the behaviour of an object things can get very tricky when you get into multi-threading. If you have two threads trying to change the property using your method, one raising the event and one not, you will find that things dont act the way they should. The event may fire once, twice or not at all depending on which thread got their first and which one left first.

    But on the other hand if you are not multi-threading the other method is fine, but you must remember to set the variable, then clear it again after you have made the change to the property. Two things to remember to do, one if you just remeber to call the "friend" method instead of the "public".

    They each have their draw-backs, i do admit that.

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