Library tutorials & articles

Visual Basic Tutorial

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.

Comments

  1. 06 Jun 2008 at 00:12

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

  2. 13 Jun 2007 at 06:02
    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..


  3. 08 Sep 2005 at 11:28

    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 a few books that are for new users. I dont even have any knowledge of ASP(I know a bit of HTML). Do I need to install IIS on my laptop to start web development ? If yes , where can I get it for free?
    Thnaks a ton!

  4. 10 Aug 2005 at 07:35

    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.  

  5. 09 Mar 2005 at 18:16

    I am a student at a vocational school in Ohio. I made a program in VB.NET for students and I would like to know if there is any way I can make an .exe file of my program to take home with me. It isn't for reselling or anything. Just wondering, thanks.



    Jimmy Jimmy 05

  6. 01 Sep 2004 at 05:20
    Quote:
    [1]Posted by Deepthi on 5 Jun 2004 01:10 AM[/1]

  7. 05 Jun 2004 at 01:10

    Hi...


    Can anybody suggest me one reference book for VB.NET??


    Thanx
    Deepthi

  8. 04 Jun 2004 at 12:23

    how can i delete posted msgss here ???

  9. 09 Feb 2004 at 11:55

    Hello,


    Can someone please help meee!  I am trying to connect lotus notes database to asp.net.  Is this even possible? If it is, can someone tell me how this is done.  


    Thanks so much,
    Lsan

  10. 13 Jan 2004 at 14:24
    its certainly not a prerequisite - although the transition from no programming knowledge to learning VB.NET is certainly harder than the transition for an experienced VB programmer to VB.NET!

    Whether to learn VB or VB.NET depends on your reason for learning the language - at the moment, VB probably has more use in a commercial sense; VB.NET is still too new. But if you're looking to the future, then VB.NET/C# is where its at!
  11. 10 Dec 2003 at 05:03

    Hi i'm a beginner with programming & i'd like a piece of advice on whether to learn vb or visual basic .net and i would also like to know if knowledge of vb is a prerequisite to knowing visual studio.net

  12. 08 Nov 2003 at 07:14

    in adodc.recordsource


    In where clause use [primary key

  13. 16 Sep 2003 at 06:45

    my name is syed mudasser from pakistan how are you all
    i like to learn vb

  14. 07 Sep 2003 at 11:33
    Excellent Article
    Many thanks to James Crowley, he has removed my fears of moving on from QB to VB.
    Does anyone else know of a good source of VB tutorials.
    Regards,
     martian.
  15. 30 Aug 2003 at 01:27

    welcome to DF thats what we are all here for... learning and working together

  16. 29 Aug 2003 at 17:25

    I just read your post about the VB for beginners and I want to thankl you about your help and love for learning VB,
    thank you alot,really you gave me the motivation that was needed to start with it.
    sorry for my english it's not perfect but you can understand me (i understand everything that you whrote)
    ok and continue like that people need your help
    thank u

  17. 18 Jun 2003 at 02:58
    great stuff !. i don't know how to start and your tutorial just show me that. thanks a lot.
    by the way, do u know of any vb samples for developing a meeting room booking system?
  18. 13 Apr 2003 at 04:18

    i use the following code to delete records:
    while not adodc1.recordset.eof
       adodc1.recordset.delete adaffectcurrent
        adodc1.recordset.movenext
    loop
    only after 4 deletion i have always this error:
    "runtime error -2147467259(80004005);key coluymn information is insufficient or incorrect. too many rows were affected by update"
    how can i solve this error and continue my deletion process?

  19. 05 Apr 2003 at 12:21
    Thanks Red Spikey Thing i have done a little C in the past but it didint go very far so thats why im trying VB out, was worried i got the wrong program thanks for the info ive been at this all morning
  20. 05 Apr 2003 at 11:39
    This is a common mistake if you have programmed in C, or one of its many variants.  What goes in thevrackets there is any parameters necessary for the sub to work.  To put the message box there, you hvae to do this:
    Code:
    private sub cmdOK_Click()
    MsgBox "Hello " & txtName.Text & "!"
    end sub


    That should work
  21. 05 Apr 2003 at 10:45
    I messed up on this, well this is my first atempt at VB and i have to say right up till i did somthing wrong it was easy to understand and provided much information for begginers. I dont know what i did wrong but i got a compile error saying it expected a list seperator or ).

    I put MsgBox "Hello " & txtName.Text & "!" in between the () tags on the cmdOK_Click() command, it didint work but i couldnt see anywere els to put it im proberly making a compleat begginer mistake so i'll keep at it till i figure out what im doing wrong.

    Im useing Visual Basic 5.0 CCE if anyone can figure out what im doing wrong =)
  22. 15 Jan 2003 at 08:14

    Thanks James, for a really helpful and very well written crash course. I've been wondering about having a go with VB, and you've convinced me!!

  23. 11 Nov 2002 at 21:30
    For the vast majority of your tutorial I had learnt in school (for a school assignment I have to create a program). I did that quickly, but once I got to the challenge exercises I was challenged. I have only created uni-form projects and the idea of moving information from one form to the other was challenging.

    I have much more knowledge to add to my head, and it is because of this tutorial. Thank you once again. You have helped my greatly in my assignment.
  24. 24 Oct 2002 at 22:05

    Thanks for your great article.  Before reading this I had no idea about VB, this has given me a head start, I will surely pass this info on to my friends who are interested in programming.


    Thanks again

  25. 03 Feb 2002 at 02:28

    Great article for someone who knows no programming, with exception of HTML. Obviously, I'm new to the world of VB. I'll be sure to spread the word, should I come across anyone else new. Great site, also.

  26. 01 Jan 1999 at 00:00

    This thread is for discussions of Complete VB Beginners Tutorial.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...
AddThis

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!