Pop Quiz! The most important feature of the first version of Visual Basic that helped make it a smash software hit was:
- It made it easy to create graphical programs for Windows
- It made it easy to use the 'event driven programming' model
Time's up!
The author's answer is 'event driven programming' even though many experts and Microsoft's advertising tend to suggest the first answer.
The concept behind 'event driven programming' is not as easy to explain as programming for Windows. You can explain the Windows programming by simply saying, "Wow! Now I can create programs in just a few minutes without knowing a thing about C++." One problem is that the core idea is just too simple to seem that important. Here it is: Your VB program doesn't 'do' anything except sit there and wait for 'an event'. Then it does different things depending on what the event is. Which event? That's up to you, the programmer. What does it do? That's up to you too.
Let's put this in pictures. Here's what happens when a typical VB program is started.
So what good is this? This is the magic ingredient that makes the program 'interactive'. The form and buttons displayed on the computer screen is part of what is called a GUI, or Graphic User Interface. That simply means that the pictures on the screen interact with the mouse, keyboard, or maybe even something else. In the case of a touch screen, it might be your finger. Now, the program can do one thing when a user clicks button 'A' and something completely different when button 'B' is clicked. The 'event' is that one or the other button is clicked. Your program code is in little chunks called 'event code'. Let's look at an example of event code.
Each button is an 'object' in programming terms and has a name that you, the programmer, can control. We'll use the name 'CommandA' for button 'A' and 'CommandB' for button 'B'. Suppose we wanted to simply display a message stating which button was clicked. Here's the code that would do the trick.
The idea now is simply to understand the relationship between 'objects', 'event code', and your program. Visual Basic helps you create a visual interface, called a GUI and helps you enter event code that interacts with the objects.
We'll actually program this example in Learning VB 6 or Learning VB.NET.
Page
1,
2,
3