Firing event from program
Is it possible to fire contol events (i.e. the change event) programatically?
If possible, how?
Bezzie
[120 byte] By [
Bezzie] at [2007-11-20 1:38:13]

# 1 Re: Firing event from program
you can just run the sub:Private Sub Command1_Click()
Text1_Change
End Subbad programming practise though. If you need to run the code contained within then move it to a sub and call that sub instead:Private Sub Command1_Click()
TextChanged Text1.Text
End Sub
Private Sub Text1_Change()
TextChanged Text1.Text
End Sub
Private Sub TextChanged(ByVal sText As String)
' Your Code
End Sub
# 3 Re: Firing event from program
bushmobile,
Not being smart or anything, why would you call that bad programing practice? I do it all the time, mostly when a menu item does the same thing the a command buttong would do. if I have already written one, I just call it from the other.
I can see where calling an event subroutine from somewhere else in the program might get confusing to read it but does calling one event subroutine from another if both do the same things also qualify as a bad practice?
Howard
# 4 Re: Firing event from program
well, in terms of the actual code that gets executed then it probably doesn't amount to anything at all - but keeping the code maintainable and developable are equally important and calling event subs directly makes that harder to do.
# 5 Re: Firing event from program
Ah, I guess its a philosophical thing then. I find it easier to maintain if I have two events that cause the same thing to happen, to put real code in one and call it from the other than to pull that code into a third sub or function and call it from both.
As I see it, calling one from the other means I only have to keep up with two subs but I can see the value of calling a function, then at least you know your messing with code that may be used by called by another.
H
# 6 Re: Firing event from program
well what happens if you want to change the control that raises the event or modify the exisitng control's behaviour in some way - you have to remember that you're calling this event directly - untangle the associated spagetti.
If you put it in a separate sub then you can box it up and forget about it - all you have to worry about is each individual call to that sub