|
-
Sep 28th, 2002, 03:13 PM
#1
Thread Starter
Junior Member
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.
-
Sep 28th, 2002, 04:31 PM
#2
PowerPoster
I would create a form-level boolean variable that you could use to know when to bypass such events.
-
Sep 28th, 2002, 04:34 PM
#3
The picture isn't missing
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  .
-
Sep 28th, 2002, 05:41 PM
#4
Thread Starter
Junior Member
But then how would the user be able to see that it was changed?
-
Sep 28th, 2002, 06:04 PM
#5
The picture isn't missing
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  .
-
Sep 28th, 2002, 07:01 PM
#6
PowerPoster
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....
-
Sep 28th, 2002, 07:10 PM
#7
-
Sep 28th, 2002, 07:36 PM
#8
PowerPoster
Well
VB Code:
' In Declarartion Area
Dim BOOLCANCEL as Boolean
' In Click Event of control you want to handle
If BOOLCANCEL = FALSE Then
' Perform the click event...
' When setting something you know will fire click event use :
BOOLCANCEL = TRUE
' Run your code
BOOLCANCEL = FALSE
Does this make sense?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 28th, 2002, 10:55 PM
#9
Thread Starter
Junior Member
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.
-
Sep 28th, 2002, 11:07 PM
#10
The picture isn't missing
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  .
-
Sep 29th, 2002, 12:07 AM
#11
PowerPoster
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....
-
Sep 29th, 2002, 12:07 AM
#12
Fanatic Member
Re: Well
Originally posted by James Stanich
VB Code:
' In Declarartion Area
Dim BOOLCANCEL as Boolean
' In Click Event of control you want to handle
If BOOLCANCEL = FALSE Then
' Perform the click event...
' When setting something you know will fire click event use :
BOOLCANCEL = TRUE
' Run your code
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:
Dim ClickedByUser as boolean
Sub Something()
'Call the command1 click event
ClickedByUser = False
Command1_Click
End Sub
Sub Command1_Click()
'see if user cliced me or program clicked me
If ClickedByUser Then
'user code here
Else
'program code here
'reset my variable
ClickedByUser = True
End if
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!
-
Sep 29th, 2002, 12:10 AM
#13
PowerPoster
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....
-
Sep 29th, 2002, 02:24 AM
#14
Fanatic Member
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.
-
Sep 29th, 2002, 05:21 PM
#15
Thread Starter
Junior Member
Thanks a lot. I got the form level variable to work. Appreciate all your help.
-
Sep 29th, 2002, 05:44 PM
#16
PowerPoster
Well
For waht itws worth, you are welcome...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 30th, 2002, 02:32 AM
#17
Addicted Member
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
-
Sep 30th, 2002, 08:12 AM
#18
PowerPoster
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....
-
Sep 30th, 2002, 09:27 AM
#19
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|