Visual Basic Tutorial


Visual Basic is very simple.

First, we’ll start off with making a new project.

1.>Open Microsoft Visual Studio or Visual Basic Express whichever you have.

2.>The start page will come up. Click on file->New->Project

3.>Then click on windows and in the list of templates, click on Windows forms.

You should have a window which looks something like this.

If you can’t see the tool box, then click on view, then on toolbox.

So, finally you have your form ready.

Now, for some theory.

Basically, Visual Basic is an event driven language. You can add buttons, checkboxes, pictureboxes and other types of tools from the toolbox and use them in your form. Every action, like, clicking, double clicking, moving the mouse and many types of others, are called events.

You can code for any type of event and when that respective event occurs, the corresponding code for that  event will be executed. Visual Basic responds only to events and nothing else. This is why its called an event driven language.

Okay, so lets write a simple program. We’ll display a message box.

Click on the button tool in the toolbox and drag it on the form, like this.

Now, go to the properties window on the lower right corner. Check the very first property, it will be Name.

Name of a control(a control is any tool, like button, textbox, label,etc) is what you use to refer to it while programming while Text property is what the user will see.

Change the name and text property to Hello. And double click on the button after you change the name. You will see this screen

You will see this.


Private Sub Hello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hello.Click

End Sub

In between these two lines, type Msgbox(“hello World”)

Now to run the program, go to debug menu and click start without debugging.

The form will appear. Click on the button “hello”. You should get this output.

This is how simple Visual Basic is. One last thing, you can close the output window by clicking the cross button. But if you want to create an exit button?

Its simple. Create another button, change its name to exit and text also to exit. Double click it.

Write only this in between the generated code.

End.

And now, run the program.

Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s