We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 296,803 times

Contents

Related Categories

Visual Basic Tutorial - The Code Window

The Code Window

Once you have been returned to your form, double click on the OK button on your form. A new window will appear, and some VB code will be automatically inserted. This is known as the Code Window. Let's take a look at the code VB has inserted for you:

Private Sub cmdOK_Click()

End Sub

Although it might seem strange at first, it is actually quite logical. First off, the words Sub and End Sub mean that this is a Procedure. Procedures are blocks of code, that can be executed (or run) by Visual Basic. The word Private defines the group of procedures that can call it, but you don't need to worry about that yet.

The most important part is cmdOK_Click(). If you remember, cmdOK is the name of the button that you added to your form. The text after the _ is known as the event. An event, just like in the outside world is something that happens. In Visual Basic, 'event' occur all the time. When the mouse is moved over the form, or when the user enters some text into a textbox, all of these trigger events.

In this case, the event is Click, and occurs, not surprisingly when cmdOK, the button, is clicked. Therefore, any code you enter into this procedure will be run when the OK button is clicked.

Now take a look at the two drop-down boxes at the top of the window:

As you can see, the text in these boxes match what is written. The box on the left lists all the controls that are on your form. If you click it, you will see the names of the three controls that you added to the Form. The right hand box lists all the events that can occur for this control. If you click it, you will see a long list of possible events for the button; the one that you are currently editing is displayed in bold (Click). If you select another item in the list, Visual Basic will automatically add a new procedure. Try this if you want, and then delete the text that VB added afterwards.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [30] Complete VB Beginners Tutorial

    Posted by pcmenegusso on 06 Jun 2008

    what's "grammer" anyway? and who's needing it here?

  • Re: beginner...

    Posted by HartTechService on 27 May 2008

    No offense, but you might want to brush up on your English grammer skills first.  "We'll gonna"= We will gonna or going too??????  This just makes no sense.  "We are ...

  • beginner...

    Posted by Tessa07 on 13 Jun 2007

    Hi evry1..
    I take IT course, n we'll gonna use VB for nxt semester.1st n 2nd semester we already have C n C++,so  i hope any1 here can help me out..TQVM..

  • New to VB.net

    Posted by asingh9 on 08 Sep 2005

    Hi,
    I have been using Visual Basic for one year. Now, I want to switch to VB.net as it is the latest technology. I am totally confused how should I go about doing this. Could you tell me the name of ...

  • Student edition

    Posted by eric2358 on 10 Aug 2005

    You may not be able to comile your code into an executable that would be portable, but your code can be copied into notepad files and kept for later use/reuse.