Results 1 to 5 of 5

Thread: The Event Statement Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    22

    Angry The Event Statement Problem

    Hi there,

    I have this assingment to do and it requires the use of the Event statement. I have looked on the net for information but can only find complex examples on how to use them. Can anyone explain them to me a little better and possibly show me how i would use them.

    Thanks

  2. #2
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: The Event Statement Problem

    What do you want to know?
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    22

    Re: The Event Statement Problem

    Just basically how i would use them and how they work.

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: The Event Statement Problem

    Hi maybe this page may help you a little.
    http://www.developer.com/net/vb/article.php/1430631
    When your dreams come true.
    On error resume pulling hair out.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: The Event Statement Problem

    From the help files.
    Quote Originally Posted by VB Help Files
    Event Statement 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 Event 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 first text box displays "From Now" and the second starts to count seconds. When the full time (9.84 seconds) has elapsed, the first 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.
    VB Code:
    1. Option Explicit
    2.  
    3. Private WithEvents mText As TimerState
    4.  
    5. Private Sub Command1_Click()
    6. Text1.Text = "From Now"
    7.     Text1.Refresh
    8.     Text2.Text = "0"
    9.     Text2.Refresh
    10. Call mText.TimerTask(9.84)
    11. End Sub
    12.  
    13. Private Sub Form_Load()
    14.     Command1.Caption = "Click to Start Timer"
    15.     Text1.Text = ""
    16.     Text2.Text = ""
    17.     Label1.Caption = "The fastest 100 meter run took this long:"
    18.     Set mText = New TimerState
    19.     End Sub
    20.  
    21. Private Sub mText_ChangeText()
    22.     Text1.Text = "Until Now"
    23.     Text2.Text = "9.84"
    24. End Sub
    25.  
    26. Private Sub mText_UpdateTime(ByVal dblJump As Double)
    27.     Text2.Text = Str(Format(dblJump, "0"))
    28.     DoEvents
    29. End Sub
    30.  
    31. 'The remaining code is in a class module named TimerState. The Event
    32. 'statements declare the procedures initiated when events are raised.
    33.  
    34. Option Explicit
    35. Public Event UpdateTime(ByVal dblJump As Double)
    36. Public Event ChangeText()
    37.  
    38. Public Sub TimerTask(ByVal Duration As Double)
    39.     Dim dblStart As Double
    40.     Dim dblSecond As Double
    41.     Dim dblSoFar As Double
    42.     dblStart = Timer
    43.     dblSoFar = dblStart
    44.    
    45.     Do While Timer < dblStart + Duration
    46.         If Timer - dblSoFar >= 1 Then
    47.             dblSoFar = dblSoFar + 1
    48.             RaiseEvent UpdateTime(Timer - dblStart)
    49.         End If
    50.     Loop
    51.    
    52.     RaiseEvent ChangeText
    53.    
    54. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width