Main Page. VBA, ASP, Visual Basic 6.0, and VB.net. Visual C++, C#, C++, C. HTML and maybe javascript. Forum,Games and Jokes, other stuff. Submit a Tutorial Today!

Hi, my name is Andy, but you can call me Anman and I'm supposed to be writing a tutorial to help newbies get into Visual Basic by Microsoft.

Chapter 1: Orientation

Welcome to Visual Basic, it's time to learn the bare basics (if you already know about the windows and toolbar in Visual Basic feel free to skip this chapter). Alright, this is the first time you have opened VB and you have selected Standard Exe, so what do you do? Well, first off, welcome to the exciting world of programming. The world where hackers and geniuses reign supreme. You are now different from the rest of everyone else. When you look at a computer screen, you can create and edit now, not only use. Eventually, you will be able to do almost anything you desire if you keep up with programming (it is just like anything else, you gotta learn it from start to finish). If you really want to get involved with programming, and computers and shit, you have to know ATLEAST to Pre-Algebra or Algebra I in math. It is a must, or atleast know these things:

constant=A value that will never change like "1" it will not change to anything else.

variable=It's a number that can change like the variable x, x could be anything

If you didn't know that already, now you do.

Ok, now look at that big window in the center of your screen, that looks like something empty that the dudes from Microsoft didn't finish. That is a form. To your left that is the toolbar. And to the right, you may have a thing that looks like a computer monitor. That shows where your form displays on the screen when you run. You may also have a thing that has a list of different weird things, that's a property listing. To your very right probobaly is a thing that looks like explorer where your files are. If you can't figure out what everything is, here is a diagram helping you out. I'll show you how to use each thing in time, but for now we want to work with the property listing box and the toolbar. Oh yeah, we will ALWAYS work with a form, just to let you know, maybe :) .

Alright, now you see the stuff on your screen. Now what do I do with it? You see those icons on the toolbar? Those are different kinds of controls (too many bold words). Those controls make the "visual" part of VB happen. They make it so you can type text into the form, tell the user information, and make clickable buttons for a few things.

Now that all that is settled, on the tool bar, click the button that has the ab and a cursor right next to the big "A". You'll see something weird happen because it's waiting for you to place the control on the form. Now, click and drag the area on the form that you want to see a text box. If you did it right, there should be a text box on your form. Now, from now on, to Run your programs, press F5 on your keyboard. Yeah yeah, you can go to Run-->Start on the menu, but that's just cheap ;-), learn to use the shortcuts and use them well it could save your ass on a project some day. You are now a programmer if you see a form on the screen with a text box in it and a cursor blinking. Close the window to return back to the development environment (Visual Basic).

Chapter 2: Basic Coding, Naming Conventions, and Other Stuff

Well, you are now a programmer. Congratulations. Not a hacker, but not entirely the worst either. There have been many who have not made it past chapter one in programming.

Experiment on the tool bar somemore to find out what each thing is. It helps to put your mouse over a button and use the tooltip text to see what each control is cause I won't tell what anymore are from now on. Half of programming is remembering the syntax and the other half is using your head and logic. If you can't get by the stupid toolbar/control problem, try again it takes practice to master anything.

Start up a new standard exe project and put a text box on it. It's time to learn a little about naming conventions.

When you click on the text box, the listing in the white list (property listing) changes. The items to the left in the list that you can't change are called properties, while the ones to the right are the values that the properties have. Go up to the very top of the list, or look on it until you find a property called (Name). That's obviously what the name of the control is. Programmers have a tendancy (especially newbies) of not giving good names to controls. A good name for a control will generally state what the fuck the control does and what type of control it is. When you use prefixes on control names to indicate what kind of control it is, that is called a Naming Convention. Here is a sample of some prefixes that I use:

frm=form txt=text box cmd=command button

img=image box pic=picture box lst=list box

(Different Corporations and groups use different prefixes so don't freak if you see different stuff on some code one of these days.)

You can make up whatever you want to use for a naming convention, but I strongly advice that you use something to tell controls apart from each other. It may not look important right now while you're just making worthless crap, but eventually you'll see what I mean. Ok, just for example, name your text box txttext1. If in Chapter 1, you typed into your text box and you were rather observant, you might have found out that a text box only handles one line of text so you can't make multiple lines. Wrong. Go about mid-way down the list and find a property called multiline. Change that to true and you got yourself a good word processor, well maybe not.

Re-run your program (Press F5) and you can now type multi-lined. Ok, quit that and right click on the form. Click on the menu item that says "View Code". This is where most of VB is done, in the coding window. In the coding window, you can modify, create, or do anything you want. The first main things you learn how to do are:

Use Properties: These are the things that "define" something. Like having a car, it's "color" is white. And "color" is a property of car.

Use Methods: These are the "ways" you do something. When you drive a car, you press the accelerator and do loads of other stuff. "How" you drive is the method of the car.

Use Events: Events happen. When they happen, you can do things in code to respond. Like in a car, when somebody cuts you off, you give him the one-finger salute. The someone cutting you off is an event. You giving him the one-finger salute is an event handler, something you do to respond to an event.

Now that is out of our way, we can begin on some basic coding. Right on that screen there should be nothing, if there is some crap on the screen get rid of it. Type in

'Hi, I am visual basic man and I hate you too.

That up there is an example of a comment. The only thing that does in Visual Basic is help you as a programmer out. Visual Basic does not care if you use one, none, or 5 million comments. Just remember that a comment starts with a single-quote (') and is only one line. VB is unlike C which allows you to have multi-line comments.

It is a good idea to use comments. Comments help after you are working on a project for 2 years and you need to look at a line of code. That's happened to me before :).

Chapter 3: Working with forms

Forms are one of the most basic things in VB that you learn and also one of the first. There are three parts of forms: properties, the code behind the form, and the visual part. You've already seen the visual part of the form when you place controls on it. Now right click on the form and click on View Code. If you have programmed before in a non-visual language, this is the "coding window" of visual basic. It's where all the nice code goes. To access the properties, look to your right and there should be a properties window for the form. If there isn't, go to the View menu and click on "Properties Toolbar". Once you can see your properties window for the form, it's time you learn how to manage it.

 

Binary Central by Anman: "http://www15.brinkster.com/anman/"