- Computers & Software»
- Computer Science & Programming»
- Programming Languages
Visual Basic for beginners: Learn Visual Basic Express
Bit of background and basics
Many of Hub readers here, meets everyday with a single word like "VBasic" or phrase like "VBasic runtime..." or even "VBasic runtime error". So, what is the "VBasic" ?
-Word "VBasic" comes from two words : Visual and Basic giving VBasic.
Visual Basic is an program language. People, usually programers, use it to program an software. Every software is developed (made by) some kind of "program language". The most used ones are : Visual Basic, Java, PHP, HTML, HTML+ , C++, Delphi, and more... The Android programing is the latest way of mobile programing, so it's meant for mobile platforms (mobile phones, smartphones...).
While Visual Basic is considered as one of the "simplest developer tool" to make programs, executable on 32bit and 64bit platforms, usually Windows (because, programing is "form-based" form=Window) it can develop major projects, for enterprise companies. From "Hello Word" kind of programs, trough the programs for tracking the market to the programing of Operating Systems (OS) - Visual Basic is everywhere, and it is easy to use.
To know to program in Visual Basic, You have to know English well. That is a must. Literally, this program language is "talking to You" while You program on it. For example there are program codes like: If something.does then something.what happens ; end if. This is a logical way of programing and it is my way of explanation how the basic programing goes in Visual Basic.
Of course, there are much, much, much more tricky and puzzled things than this, but I gave You an idea how everything works. As in every program language, You have variables and their usage is huge, they can be treated "as integer" or ... You'll see, and learn.
On this page (click on blue marked), You will find plenty of useful informations about Visual Basic itself and programing language. And on this page, You can DOWNLOAD Your first Visual Basic 2010 Express Developer Tool !(when page is opened, click on Install Now.)
Now, let's get started. When installation process is done, and everything is fine configured (there isn't something much to configure to be honest) - You are ready to start Your very first program! Isn't this exciting or what ?
As always, I will go with the pattern of learning "HELLO WORLD" project first. Start up the Visual Basic 2010 Express. After splash screen, You will have several options - even it's own tutorial.(not very useful)
The Main Screen
Starting "HELLO WOLD" Project : Creation
On main window, as displayed, choose the "New Project". One-click on it.
When second window opens, the "template" window that offers You per-configured templates, choose "Windows Form Application"! Then click OK. On bottom part of the window, You will have the option to enter the optional name of the project, but it's o.k to leave it like that.
And wholaaaaaaaa! There You are! You are watching the window that billions of programers watch every day, while they develop the most sophisticated software for our usage, and we don't even know it.
We start with, basic screen. You can see that You already have "Form1" displayed and created, with, on down right side it's properties - if You click once on form. This "Form1" will be Your future window. Now, on the left side - You can see the tools, or "things that You can insert into project". We will need : 1 button and 1 label. So, double click on "Button" (on left side) and double click on "Label" also on left side of the screen.
Now, You've noticed that when You double clicked on the "Button" the button, on "Form1" was created with "Button1" text on it. Same with "Label", just the text on it is "Label1" , which marks the actual name of the object inserted. NOTICE: TEXT ISN'T SAME AS THE NAME, BUT, WHEN YOU INSERT THE OBJECT FOR FIRST TIME, THE "TEXT" VALUE WILL BE THE DEFAULT NAME OF THE INSERTED OBJECT!
Next move is to click on the form, and You will see the "re-size" points being displayed on each corner of form. Click on the down-right, and make the form look like rectangle. It's easy. When You've done it, move the "Button1" object to the right side of the form, and the "Label1" leave on left side of rectangles form.
Click once, to select the object You want to edit/program. Click on the "Button1", and on the right side where the properties window is, change value of "Text" from "Button1" to "Click To See". Remember: when You change something in the "properties" filed, you change the "value" of it!
The button should now contain no more the "Button1" caption, but, "Click To..." ! Probably there isn't enough space for whole phrase ( Click To See ) , so, same as with form, re-size the button, on the way You want - but enough to see the TEXT - "Click To See". Remember: THE NAME OF THE BUTTON WILL STILL BE "BUTTON1" WHEN YOU PROGRAM.
What we forgot, and what is very important, in order to have a program that will display "HELLO WORLD - I MADE IT!" label on click, is to click on the label "Hello World I Made It" and on the properties menu, scroll down, find the Visible and set value to "False". On this way, when You run the application, the label won't be visible until "You say so" - until You click the Button!
Now, click on the "Label1". On the right side, in the properties window, select "Text" , and change the value to " HELLO WORLD - I MADE IT! ". Of course, in both cases, You don't need the quote marks! Which is good, and make things a bit easier and faster.
Starting "HELLO WOLD" Project : Programing
Double click on the "Click To See" button. It will open the window where You enter Your program codes, it is actually the field where the programing starts.
Between "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click" and "End Sub" insert next:
Label1.Visible = True
You have noticed that we didn't insert the "If Button1.Click code..." Why? - Because we already gave an sign to Visual Basic by double clicking on it, that we want action related to click.I've underlined, the code that shows where Visual Basic says to computer, do "this" on CLICK.
And now You need to hit the green "play button" on upper menu. That "play button", will try to run Your project. If project is written well, without any syntax error - it will run it, and You will see it as You've ran the .exe application. And that's it!
The only thing, that I would add is an exit button, that would shut down the application, but since You automatically have the minimize, maximize and close buttons on the right top angle of window - than You probably don't need it. But if You want so, create a new button, change the TEXT to "EXIT" , and double click to it. After double clicking enter:
"Form1.Close" , and that's all.
YOU HAVE MADE YOUR FIRST .EXE APPLICATION IN VISUAL BASIC.