1. Home
  2. Computing & Technology
  3. Visual Basic

Creating Your Own Event Code
Take a drink!

By Dan Mabbutt, About.com

The fundamental act in a drinking binge is taking a drink. You simply pour down a random amount of whatever is in your glass.

Private Sub takeADrink_Click( _
   ByVal sender As System.Object, _
   ByVal e As System.EventArgs) _
   Handles takeADrink.Click
   Randomize()
   SaturdayNight.Drink(Rnd())
End Sub

But the thing that makes this a binge is that when your glass is empty, you have another. This is the event that was raised in the SaturdayNight instance of the Binge object.

Private Sub EmptyGlass() _
   Handles SaturdayNight.EmptyGlass
   SaturdayNight.HaveAnother()
End Sub

This is just template code because in a real binge, you would have to have a very generous friend to make sure that this subroutine doesn't trigger the outOfCash error condition. The passOut event would also have to be coded for more realistic code to provide for orderly program completion.

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Creating Your Own Event Code

©2009 About.com, a part of The New York Times Company.

All rights reserved.