Hi all
How to add events to basic variables. For EX ..When the value of Interger changes it should fire an event and if the valus is 0 another event .. like that ...
Printable View
Hi all
How to add events to basic variables. For EX ..When the value of Interger changes it should fire an event and if the valus is 0 another event .. like that ...
use the raise Event method of VB
VB Code:
Select Case INTVARIABLE Case 0 ' Do something Case 1 ' Do something End Select
Make it more clear plz .May be a sample code or snippet
How is this variable being changed? I mean there is only so many ways it can be changed, right? What data is it holding?
I use a global variable
public withevents intEmp as integer
i use to hold count
when its value get changed by anywhere in the project a particular event shoul fire and if it is 0 another event should fire
private sub intEmp_VChange(Val as integer) ' if value cahges
end sub
private sub intEmp_Vzero ' if it is zero
end sub
VB Code:
Option Explicit Public Event TestA(j As Integer) Public Event TestB(i As Integer) Private Sub Form_Load() Dim x As Integer Randomize x = (Rnd * 1) '* 100 MsgBox x If x = 1 Then RaiseEvent TestA(x) Else RaiseEvent TestA(x) End If End Sub
how to cature that event raised by
Try this....
VB Code:
Option Explicit Private MYintEmp As Integer Public Event VChanged() Public Event VZero() Public Property Get intEmp() As Integer intEmp = MYintEmp End Property Public Property Let intEmp(ByVal iNewValue As Integer) MYintEmp = iNewValue If MYintEmp = 0 Then RaiseEvent VZero Else RaiseEvent VChanged End If End Property Private Sub Command1_Click() Randomize Timer 'Int((upperbound - lowerbound + 1) * Rnd + lowerbound) intEmp = (101 * Rnd) End Sub
But... this should be a Class Module, so that you can create an object (withevents) to get its events.
I pasted the code in a module it gives error in
Public Event VChanged()
Public Event VZero()
RaiseEvent VZero
RaiseEvent VChanged
syntax error
Did you put it in a CLASS module.Quote:
Originally posted by vijayanand
I pasted the code in a module it gives error in
Public Event VChanged()
Public Event VZero()
RaiseEvent VZero
RaiseEvent VChanged
syntax error
Add a class module the same way as a module, project->add->Class Module.
Don't use the class module wizard.
I pasted the code in a module it gives error in
Public Event VChanged()
Public Event VZero()
RaiseEvent VZero
RaiseEvent VChanged
syntax error
Thanx for the help buddy
Try this: