love8906
Messages postés2Date d'inscriptionjeudi 29 novembre 2007StatutMembreDernière intervention23 janvier 2008
-
13 janv. 2008 à 20:10
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 2018
-
13 janv. 2008 à 20:21
Bonjour,
Je débute dans les modules de classe et je voudrais réaliser un évenement qui se produit toutes les minutes. J'ai utilisé la fonction SETTIMER qui me déclenche l'appel d'une procédure <TimerProc> jusque-la pas de problème. Mais je n'arrive pas a générer un evenement <newmin> depuis cette procédure pour mettre a jour un LABEL.
Quelqu'un pourrait-il m'orienter ?
Merci a toutes les personnes ayant la réponse a mon problème.
>>love8906<<
Le code d'essai:
********** FORM1 ***********
VERSION 5.00
Begin VB.Form Form1
Caption = "Test de classe"
ClientHeight = 2520
ClientLeft = 60
ClientTop = 375
ClientWidth = 5550
LinkTopic = "Form1"
ScaleHeight = 2520
ScaleWidth = 5550
StartUpPosition = 2 'CenterScreen
Begin VB.Frame Frame2
Caption = "Timer "
Height = 1815
Left = 2520
TabIndex = 5
Top = 600
Width = 1935
Begin VB.CommandButton Command6
Caption = "Desactiver"
Height = 375
Left = 240
TabIndex = 7
Top = 720
Width = 1215
End
Begin VB.CommandButton Command5
Caption = "Activer"
Height = 375
Left = 240
TabIndex = 6
Top = 240
Width = 1215
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 9
Top = 1440
Width = 495
End
Begin VB.Label Label1
Caption = "Minutes écoulées:"
Height = 255
Left = 240
TabIndex = 8
Top = 1200
Width = 1455
End
End
Begin VB.Frame Frame1
Caption = "Initialiser classe TEST"
Height = 1815
Left = 360
TabIndex = 1
Top = 600
Width = 2055
Begin VB.CommandButton Command4
Caption = "Positive"
Height = 375
Left = 240
TabIndex = 4
Top = 1200
Width = 1575
End
Begin VB.CommandButton Command3
Caption = "Nulle"
Height = 375
Left = 240
TabIndex = 3
Top = 720
Width = 1575
End
Begin VB.CommandButton Command2
Caption = "Negative"
Height = 375
Left = 240
TabIndex = 2
Top = 240
Width = 1575
End
End
Begin VB.CommandButton Command1
Caption = "Quitter"
Height = 375
Left = 360
TabIndex = 0
Top = 120
Width = 2055
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public WithEvents classTEST As TEST
Attribute classTEST.VB_VarHelpID = -1
Private Sub classTEST_negatif()
Call MsgBox("TEST est négatif !", vbInformation + vbOKOnly, "MESSAGE")
End Sub
Private Sub classTEST_newmin(ByVal mn As Long)
Label2.Caption = Str(mn)
End Sub
Private Sub classTEST_nulle()
Call MsgBox("TEST est nul !", vbInformation + vbOKOnly, "MESSAGE")
End Sub
Private Sub classTEST_positif()
Call MsgBox("TEST est positif !", vbInformation + vbOKOnly, "MESSAGE")
End Sub
Private Sub Command1_Click()
Unload Me
End
End Sub
Private Sub Command2_Click()
classTEST.valeur = -1
End Sub
Private Sub Command3_Click()
classTEST.valeur = 0
End Sub
Private Sub Command4_Click()
classTEST.valeur = 1
End Sub
Private Sub Command5_Click()
classTEST.TIMERenable = True
Frame2.Caption = "Timer actif"
End Sub
Private Sub Command6_Click()
classTEST.TIMERenable = False
Frame2.Caption = "Timer inactif"
End Sub
Private Sub Form_Initialize()
Set classTEST = New TEST
Frame2.Caption = "Timer inactif"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set classTEST = Nothing
End Sub
********** module de classe ***********
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "TEST"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim loc_valeur As Long
Dim hwndTIMER As Long
Dim loc_TIMER As Boolean
Public Event nulle()
Public Event negatif()
Public Event positif()
Public Event newmin(ByVal mn As Long)
Private Const CLASSNAME As String = "FENETRE"
Private Sub Class_Initialize()
loc_minute = 0
loc_TIMER = False
Call MsgBox("Début de classe TEST !", vbInformation + vbOKOnly, "MESSAGE")
End Sub
Private Sub Class_Terminate()
Call MsgBox("Fin de classe TEST !", vbInformation + vbOKOnly, "MESSAGE")
End Sub
Public Property Let valeur(nx As Long)
loc_valeur = nx
If loc_valeur = 0 Then RaiseEvent nulle
If loc_valeur < 0 Then RaiseEvent negatif
If loc_valeur > 0 Then RaiseEvent positif
End Property
Public Property Get valeur() As Long
valeur = loc_valeur
End Property
Public Property Let minSTART(min As Long)
loc_minute = min
End Property
Property Get minSTART() As Long
minSTART = loc_minute
End Property
Public Property Let TIMERenable(etat As Boolean)
loc_TIMER = etat
If etat Then
hwndTIMER = SetTimer(0, 0, 60000, AddressOf TimerProc)
Else
hwndTIMER = KillTimer(0, hwndTIMER)
End If
End Property
Public Property Get TIMERenable() As Boolean
TIMERenable = loc_TIMER
End Property
*********** module simple ***********
Attribute VB_Name = "TIMER"
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public loc_minute As Long
Public Sub TimerProc()
loc_minute = loc_minute + 1
' Call MsgBox("Temps écoulé !", vbInformation + vbOKOnly, "TIMER")
'Je veux déclencher ici un evenement <newmin> dans le module TEST, comment faire ?
End Sub
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 13 janv. 2008 à 20:21
salut,
en fait ton module doit traiter lui-même la création et la destruction du timer (API), ce qui t'évite de le mettre dans la classe.
ensuite tu gères une collection de ta classe dans le module, comme çà c'est le module qui appelle la fonction de la classe, qui elle peut relever l'évènement
(en effet un évènement ne peut pas être relevé par un module standard)
tu trouveras un exemple dans ma dernière source (AfCls_Timer.cls et Mod_Timer.bas)
++
Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp