Visual Basic - Learning to Code

Learning to Code in Visual Basic

I will be using various terms during this tutorial here is a small reference centre for you:​

VB/VB200 8 = Visual Basic 2008
GUI = Graphical User Interface
Form = Application with a GUI​




Part One

Downloading



1) Firstly we need to download the required software:
Microsoft Visual Basic 2008 Express Edition - Software Informer. Visual Basic 2008 Express Edition SDK for developping .NET applications.

The software is free of charge as it is by Microsoft, you will realize when you download you will receive a notification “This is a Trial Version, You have 30 days left” Don’t panic all you need to do is register with your email address and you will no longer receive this notification.

2) When you have downloaded Visual Basic 2008 you will be greeted with this screen:
image.png

What we are greeted with is our “Start Page” – This is where we can view the news about VB2008 and view our recent projects.





Part Two

What are we going to be coding?



3) We are going to be coding a computer information center, this will tell us various information about our PC.

Our plan is when a user clicks a button it will full up empty text boxes that we have placed with the required information.

Many people make the mistake of thinking Visual Basic is an easy coding language because it is drag and drop, I can tell you they wrong it may be drag and drop however do they see the coding that goes in behind the GUI?





Part Three

Right, let’s get started!



4) Firstly we need to start a new project:

image.png

We are greeted with this:
image.png

5) When we are coding with VB and we want to make an application with a GUI we want to create a “Windows Forms Application” I will go into more detail later about what the others do.

6) If we click “Windows Forms Application” once, at the bottom of the page we can give our project a name as we are going to be coding an Information Center I’m going to call mine “Info Center” nice and original ;)

Now we have made our project.




Part Four

What’s on my screen?


image.png

Don’t panic im going to break this down :)
image.png

   Note


  • 1 – Open Project
  • 2 – Save Project
  • 3 – Undo
  • 4 – Re-Do
  • 5 – Run Program
  • 6 – Stop Program


7) On the right hand side of the program we have our “solution Center” and our “properties” I always close the solution center as I have never used it unless I am working on a huge project. Once we have close that “Data resources will pop up as well, close that now our “properties” has more room.




Part Five

Let’s get Geeky!



Click once in your form (“FORM1”) this has now made if active meaning anything we change in the properties tab will affect our Form (our program).

8) Let’s change the Forms name to our program name.

Scroll to the bottom of the “properties Tab” until you see “Text” change this to “Info Center”
image.png

Now we have changed that the title of our program has changed.
image.png

9) If we now click button 5 the Run program button it will start our program for us, however this is very boring as our program doesn’t do anything yet!
image.png


   Note
when we run our program in order to edit and make changes we need to stop running the program we can do this 2 ways!
  • Click the red Cross button in our program
  • Click button 6 (Stop program)




Part Six

Making The GUI!



10) On the left hand side we have our tool box, this is where we can add things to our program.
image.png

11) Lets add 6 text boxes to our program!

Click on the Toolbox then click on “Text box” then click on your form 6 times!

If we now run our program again we have 6 working text boxes !
image.png

12) Lets make them look professional, drag and drop them until they look something like this.

   Tip
Remember we need to stop running our form before we can edit it.

image.png

13) Now let’s add 6 Text Labels, and make them look professional. We will change what they say later after we have coded our program:
image.png

14) Now we need to add 2 buttons to our Form (Application), Using the Toolbox add 2 buttons:
image.png




Part Seven

Start Coding!




15) Double click button 2 and it will open the coding screen for button 2.
image.png

We can see this code:

PHP:
 Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
End Sub
End Class

Im going to break this down, as the code is the same in anything to do with VB.

PHP:
 Public Class Form1

This section of code is our program meaning Public class Form1 is the start and End class is the End. Form1 is our programs name (name within the code not the name the users see).

PHP:
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
The section of code is telling our program that is a Private sub for button 2. The button2_click means that when button 2 is pushed it will perform an action, an action that we code below.

PHP:
 Private Sub Button2_Click
Private subs work the same a Class’s when we have a class we must end it without “End Class” the same applies for a sub we must end it with “End sub” Simple aye?

Don’t worry its confusing but by the end of this tutorial it will make perfect sense.

16) Now button 2 we would like to close our program, it’s going to be an Exit button.

So if we look at this code:

PHP:
 Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
End Sub
End Class

What is saying is the program starts here, button 2 gets pushed it ends here. We have coded nothing.

If we add “Close()” in buttons 2 section when the button is pushed the form will close, it should look something link this.

PHP:
 Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub
End Class

If we now run our program when we push button 2 the form will close.

17) Now we need to tell the text boxes to do something when button 1 is pushed:

There are many ways to do this however the simplest way is the way I’m going to show.

If we double click Button 1 we can see button 1’s coding:

This is what you should see:

PHP:
 Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
End Sub
End Class


For this we are going to use this command:
PHP:
my.computer.****
But we need to tell the button were it is going to output the information that is why we added 6 text boxes.

Under button 1’s section add this:

PHP:
textbox1.text =

What this means is when button 1 is clicked textbox1’s text is going to equal something.

When the user pushes the button I would like textbox 1 to show them there computer name, we are going to do this using the “my.computer.name” command.

PHP:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
End Sub

If we now run our program and click button1 it will show us our computer name!
image.png

18) We now to repeat this process for all of our 6 text boxed but giving those different commands as we go along.

Here is what I have:

PHP:
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = My.Computer.Name
TextBox2.Text = My.Computer.Info.OSFullName
TextBox3.Text = My.Computer.Network.IsAvailable
TextBox4.Text = My.Computer.Info.OSPlatform
TextBox5.Text = My.Computer.Clock.GmtTime
TextBox6.Text = My.Computer.Info.TotalPhysicalMemory & " Mb"
 
End Sub
I am using the same command just with different endings, the great thing about using the software is that it will give you hints.

If we look at the last line of code I have done:

PHP:
 TextBox6.Text = My.Computer.Info.TotalPhysicalMemory & " Mb"

At the end of the code I have
PHP:
& “MB”
By doing this I am asking the output to put “MB” on the end of the result, by placing “” in between the MB I am telling the program that that is a comment I would like to put in the text box.

Notice how I have put all the command in the Button 1 section meaning when the button is pushed I would like all the commands to run.

Now let’s run our program and push button 1.
image.png




Part Eight

Cleaning up



19) Now let’s clean up our program.

Firstly we need to give our labels some text that reflects what information will be in the text boxes. To do this we need to click on Label 1 then look in the properties for label 1.

Once you have done that scroll down in the properties field until you see “text” change this to “Computer name”

Do this for each label all 6 of them.

image.png

And you will have something that looks like this:
image.png

20) Now we need to the same for the buttons,
image.png

21) If we select everything on the form we can move it, I’m going to move it more in the center. Then I’m going to drag the Form up a little as it’s too long.

You should have something that looks like this now:
image.png


You have just made your first program!
 
Last edited by a moderator:
Is the latest visual basic free? Or only this version?

I find the info is conflicting on some sites.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Built
OS
Windows 10 Pro
CPU
AMD Ryzen 5 2400G Processor with Radeon RX Vega 11 Graphics
Motherboard
ASRock X470 Master SLI/AC AM4 AMD Promontory X470 SATA 6Gb/s
Memory
G.SKILL Ripjaws V Series 16GB (2 x 8GB) 288-Pin DDR4 SDRAM D
Graphics Card(s)
2047MB NVIDIA GeForce GTX 1060 6GB (EVGA)
Sound Card
Motherboard Built in
Monitor(s) Displays
Acer R240HY bidx 23.8-Inch IPS HDMI DVI VGA (1920 x 1080) Wi
Screen Resolution
1920 x 1080
Hard Drives
1TB Sandisk SSD PLUS (Main drive)
500 GB Seagate 7200 RPM (Games)
500 GB Western Digital 7200 RPM (Virtual Machines)
PSU
CORSAIR TX Series TX650M 650W 80+ Gold Modular Power Supply
Case
CORSAIR CARBIDE SPEC-02 Mid-Tower Gaming Case, Red LED Fan
Cooling
220mm, two 120mm, and four 60mm fans
Keyboard
Wired Dell keyboard
Mouse
Wireless Logitech mouse
Internet Speed
250mb down, 30mb up
Antivirus
Panda Cloud Antivirus
Browser
Chrome-ish x64
Other Info
Your awesome for reading this.
Is the latest visual basic free? Or only this version?

I find the info is conflicting on some sites.

There is Visual basic 2013 express, however VB 08 is similar to 2013, its just the name spaces and formatting that has changed, i would always recommend starting to code in 2008 before 2013 as the adjustment is much smaller and its easier to pick up.

Its just like driving you start in a small car before a ferrari ;)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate 64-bit
CPU
Intel G3420 3.2GHZ Dual Core
Motherboard
Gigabyte H87-HD3
Memory
Kingson 8GB 1600mhz
Graphics Card(s)
MSI R7970 TF 3GD5/OC BE
Monitor(s) Displays
21" LG & "19 Vertical Samsung
Hard Drives
120GB SSD - Boot
1TB WD
350GB External
2TB External (Wireless)
PSU
Corsair CX 500 modular
Case
Zalman Z11 Plus (modified)
Cooling
Corsair H55, 2x 120mm SP Corsair, 1x 140 Coolermaster
Keyboard
Corsair K50
Mouse
CSL Gaming
Internet Speed
164Mbps
Antivirus
Avast, Malwarebytes
Browser
Google Chrome, IE, Firefox
Last time I installed VB I searched but couldn't find a 2013 with only VB, so I went for "Visual Basic 2010 Express" which was the latest version I could find. Don't know how it differs from 08: Download Overview

It's much lighter than installing the entire .NET that supports all other dev languages too.
After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
Last time I installed VB I searched but couldn't find a 2013 with only VB, so I went for "Visual Basic 2010 Express" which was the latest version I could find. Don't know how it differs from 08: Download Overview

It's much lighter than installing the entire .NET that supports all other dev languages too.
After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.

In order to obtain your product key, you just have to give you Email adress.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate 64-bit
CPU
Intel G3420 3.2GHZ Dual Core
Motherboard
Gigabyte H87-HD3
Memory
Kingson 8GB 1600mhz
Graphics Card(s)
MSI R7970 TF 3GD5/OC BE
Monitor(s) Displays
21" LG & "19 Vertical Samsung
Hard Drives
120GB SSD - Boot
1TB WD
350GB External
2TB External (Wireless)
PSU
Corsair CX 500 modular
Case
Zalman Z11 Plus (modified)
Cooling
Corsair H55, 2x 120mm SP Corsair, 1x 140 Coolermaster
Keyboard
Corsair K50
Mouse
CSL Gaming
Internet Speed
164Mbps
Antivirus
Avast, Malwarebytes
Browser
Google Chrome, IE, Firefox
Back
Top