USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  RaiseEvent Statment Example??
vilmarbr
Pontos: 2843
SAO PAULO
SP - BRASIL
Postada em 06/12/2005 11:50 hs         
Oi,

Eu peguei um exemplo na MSDN Library do VS 6, usando RaiseEvent Statment, mas dá erro(User-defined type not defined) devido a este tipo(objeto) TimerState!

Tentei declarar como Timer, mas tb. deu erro(Invalid use of New keyword)!

Segue exemplo:
 
RaiseEvent Statment Example
The following example uses events to count off seconds during a demonstration of the fastest 100 meter race. The code illustrates all of the event-related methods, properties, and statements, including the RaiseEvent statement.
The class that raises an event is the event source, and the classes that implement the event are the sinks. An event source can have multiple sinks for the events it generates. When the class raises the event, that event is fired on every class that has elected to sink events for that instance of the object.
The example also uses a form (Form1) with a button (Command1), a label (Label1), and two text boxes (Text1 and Text2). When you click the button, the Min text box displays "From Now" and the second starts to count seconds. When the full time (9.84 seconds) has elapsed, the Min text box displays "Until Now" and the second displays "9.84"
The code for Form1 specifies the initial and terminal states of the form. It also contains the code executed when events are raised.

Option Explicit
Private WithEvents mText As TimerState
Private Sub Command1_Click()
    Text1.Text = "From Now"
    Text1.Refresh
    Text2.Text = "0"
    Text2.Refresh
    Call mText.TimerTask(9.84)
End Sub
Private Sub Form_Load()
    Command1.Caption = "Click to Start Timer"
    Text1.Text = ""
    Text2.Text = ""
    Label1.Caption = "The fastest 100 meters ever run took this long:"
    Set mText = New TimerState
    End Sub
Private Sub mText_ChangeText()
    Text1.Text = "Until Now"
    Text2.Text = "9.84"
End Sub
Private Sub mText_UpdateTime(ByVal dblJump As Double)
    Text2.Text = Str(Format(dblJump, "0"))
    DoEvents
End Sub

The remaining code is in a class module named TimerState. Included among the commands in this module are the Raise Event statements.

Option Explicit
Public Event UpdateTime(ByVal dblJump As Double)
Public Event ChangeText()
Public Sub TimerTask(ByVal Duration As Double)
    Dim dblStart As Double
    Dim dblSecond As Double
    Dim dblSoFar As Double
    dblStart = Timer
    dblSoFar = dblStart
   
    Do While Timer < dblStart + Duration
        If Timer - dblSoFar >= 1 Then
            dblSoFar = dblSoFar + 1
            RaiseEvent UpdateTime(Timer - dblStart)
        End If
    Loop
   
    RaiseEvent ChangeText
   
End Sub


[]'s

http://www.vilmarbro.com.br
     
Elieser Topassi
Pontos: 2843 Pontos: 2843
SÃO JOSÉ DO RIO PRETO
SP - BRASIL
Postada em 06/12/2005 14:34 hs            
Vilmar,
 
A segunda parte do codigo, vc precisa por ela em um MODULO DE CLASSE chamado TimerState... é ele que vai ser a classe do objeto q ta dando erro na primeira parte do codigo....
 
Flw!


Elieser Carlos Topassi
Analista de Sistemas - Desenvolvedor VB/ASP/.Net

e-mail/msn:
elieser_topassi@yahoo.com.br
São José do Rio Preto,SP - Brasil
_____________________________________________________
Emoções "O caminho do tolo aos seus prórios olhos lhe parece reto, mas o sábio ouve conselhos" (Pv 12:15)

     
vilmarbr
Pontos: 2843
SAO PAULO
SP - BRASIL
Postada em 07/12/2005 08:03 hs         
ok, valeu!Emoções

http://www.vilmarbro.com.br
     
Página(s): 1/1    

CyberWEB Network Ltda.    © Copyright 2000-2026   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página