★ VB.NET For Morons | Your First Application ★

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
23 posts Page 1 of 3
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Before you start reading the tutorial bellow I want you to know something: This tutorial is specified for beginners that still don't know how to make a new project (Windows Application). This tutorial contains images (Screenshots) which will give the user a well understanding about the tutorial's subject.


Video for the tutorial: http://www.youtube.com/watch?v=kS_rM9R0Dlk


Your First Application in Visual Basic Express Edition 2008
by Nery
  • Visual Basic.NET Explanation
What is Visual Basic Express Edition 2008 (as known as VB.NET)

It's a computer programming system developed and owned by Microsoft. Visual Basic was originally created to make it easier to write programs for the Windows computer operating system. The basis of Visual Basic is an earlier programming language called BASIC that was invented by Dartmouth College professors John Kemeny and Thomas Kurtz. Visual Basic is often referred to using just the initials, VB. Visual Basic is easily the most widely used computer programming system in the history of software.
Source: About.com

Is Visual Basic just a programming language or is it more than that?

It's more. Visual Basic was one of the first systems that made it practical to write programs for the Windows operating system. This was possible because VB included software tools to automatically create the detailed programming required by Windows. These software tools not only create Windows programs, they also take full advantage of the graphical way that Windows works by letting programmers "draw" their systems with a mouse on the computer. This is why it's called "Visual" Basic.

Visual Basic also provides a unique and complete software architecture. "Architecture" is the way computer programs, such as Windows and VB programs, work together. One of the major reasons why Visual Basic has been so successful is that it includes everything that is necessary to write programs for Windows.
Source: About.com

Is there more than one version of Visual Basic?

Yes. Since 1991 when it was first introduced by Microsoft, there have been nine versions of Visual Basic up to VB.NET 2005, the current version. The first six versions were all called Visual Basic. In 2002, Microsoft introduced Visual Basic .NET 1.0, a completely redesigned and rewritten version that was a key part of a much larger computer architecture. The first six versions were all "backward compatible". That means that later versions of VB could handle programs written with an earlier version. Because the .NET architecture was such a radical change, earlier versions of Visual Basic have to be rewritten before they can be used with .NET. Many programmers still prefer Visual Basic 6.0 and a few use even earlier versions.
Source: About.com

Isn't Visual Basic only for lower skilled programmers and simple systems?

This was something that programmers using programming languages like C, C++, and Java used to say before Visual Basic .NET. Back then, there was some truth to the charge, although on the other side of the argument was the fact that excellent programs could be written faster and cheaper with Visual Basic than with any of those languages.

VB.NET is the equal of any programming technology anywhere. In fact, the resulting program using the .NET version of the C programming language, called C#.NET, is virtually identical with the same program written in VB.NET. The only real difference today is programmer preference.
Source: About.com

Is Visual Basic "object oriented"?

VB.NET certainly is. One of the big changes introduced by .NET was complete object oriented architecture. Visual Basic 6 was "mostly" object oriented but lacked a few features such as "inheritance". The subject of object oriented software is a big topic by itself and is beyond the scope of this article.
Source: About.com

How much does Visual Basic cost?

Although Visual Basic 6 could be purchased by itself, Visual Basic .NET is only sold as part of what Microsoft calls Visual Studio .NET. Visual Studio .NET also includes the other Microsoft supported .NET languages, C#.NET, J#.NET and C++.NET. Visual Studio comes in a variety of versions with different capabilities that go well beyond just the ability to write programs. In October 2006, Microsoft's posted list prices for Visual Studio .NET ranged from $800 to $2,800 although various discounts are often available.

Fortunately, Microsoft also provides a completely free version of Visual Basic called Visual Basic .NET 2005 Express Edition (VBE). This version of VB.NET is separate from the other languages and is also completely compatible with the more expensive versions. This version of VB.NET is very capable and doesn't "feel" at all like free software. Although some features of the more expensive versions aren't included, most programmers won't notice anything missing. The system can be used for production quality programming and isn't "crippled" in any way like some free software. You can read more about VBE and download a copy at Microsoft's web site.
Source: About.com

Where do I get Visual Basic Express Edition 2008 (VB.NET 2008)

Navigate to microsoft's download page: http://www.microsoft.com/express/download/
or...
Navigate to microsof's VB.NET 2008 page: http://www.microsoft.com/express/vb/Default.aspx

A Visual Basic screenshot:

http://img4.imageshack.us/img4/600/visualbasic1.th.jpg
  • Your first application
Alright, after understanding what visual basic consist in we can, finally, continue to the stage where you're going to create your first Windows application.

Ok, lets begin...

In order to create a project you've to open your VB.NET 2008 (Visual Basic Express Edition 2008) in it's "Homepage":

http://img4.imageshack.us/img4/600/visualbasic1.th.jpg

After doing that, go "File" and then "New Project", or simply press the "New Project" button:

Image

A New window should popup with many kind of projects, what you've to do is choose the first project type called "Windows Application" and name your project to whatever you want:

Image

There you go, you've created your first application on VB.NET 2008! On the Application Preview you should be able to view the form design! There you can design your form, just pick whatever you want from the toolbox and apply it to your form:

Image

In the screenshot above you can see that I've changed the text of that controls, in order to do that you've to meet the Properties!:

Image

For example, if you want to change the text of your control you've to find the "Text" field and fill it to whatever you want. By the way: Do not confuse Name with Text, Name is the name of the control, setting the name will change the way how it'll be recognized by the code, Text changes the text inside the control.

Image
  • Coding your first application
Ok, its time to explain how code works.

The Code part is the brain of your application, without it you cannot do anything with it, just messing around with controls that have no action.

On this step we're going to make a "Hello World" simple application, it'll popup the "Hello World" message by simply pressing a button.

We're going to use the "MsgBox" function to popup the Message Box, a simple message box...

K... Pick a button from the toolbox and drag it on your form, place it wherever you want, change his text to whatever you want, but don't touch the name, let it be as default "Button1"
This is what I got:

Image

In order to set up the button's action you've to double tap your button in the form design! A New tab should appear showing up a bunch of code:

Image

Between
Code: Select all
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
And
Code: Select all
End Sub
Type:
Code: Select all
MsgBox("Hello World")
"MsgBox" calls the Message Box function that will popup with the text wrote between (" "), any text must be wrote with commas " " else it'll give up an error. You can replace Hello World with whatever you want, but remember, add commas " " to the text!

Image

Now, to test your application simply press the "Start Debugging" button:

Image

If it gives up any error then you've to scroll up a little bit and start over again, you may be done a mistake!

If you had no errors then you're ready to make the well known executable (.exe file) that will run your application on windows OS, Mac OS, for example, uses a different file extension: .app
In order to build your executable, go to the
"Build" tab and press "Build yourprojectname"

Image

Ok you've done the executable, Save your project: File -> Save As, and close Visual Basic, go to your project folder, then press on the YourProjectName folder, "bin" folder, "release" folder and there you should have your "YourProjectName.exe" file! Copy it and paste it to your desktop, Double press it and congratulations, you've done your first application!

Image

Image

You can rename the executable to whatever you want BUT keep the .exe file extension!
If you haven't been able to reach here then coding isn't for you!

Have Fun!

Credits:
- Nery (for the tutorial itself)
- About.com (for all the info about Visual Basic)
Last edited by Nery on Sun Sep 13, 2009 8:59 pm, edited 3 times in total.
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Hi Nery
Well done for posting that info for people who are new to VB and might not know where to start. cooll;
Its good to have a Section desgnated to complete begineers.

regards

Chris
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Thank you for the feedback,

Cheers!
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello Nery,

I completely agree with hungryhounduk, the "Hello World!" tutorial is a great example and starting point for anyone just starting out in VB.

Perhaps I should add a section for complete beginners onto the boards and everyone can create "How-To" tutorials for things like how to add controls, building/publishing your application, what each control is used for and stuff like that.

What do you think?.

Great job Nery cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

What if you do a section called "Tutorial Submission" and the other tutorial sections would be closed, so people post in the tutorial submission and if the tutorial posted is good, moderators or admin aprove it and move it to the right tutorial section

I can give you an example:

http://www.hiveworkshop.com/forums/warc ... rials-206/

With that metod we can easily delete every nasty tutorials that are doing nothing in our community.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello Nery,

I do have the options to have posts submitted before they are made public but I removed it because I dont want any restrictions on posting. I think every tutorial submitted is a useful one because even if I or indeed every member on codenstuff.com think the tutorial is useless, someone may come onto the site in say a months time and find that same tutorial very useful.

The only thing I ask when people submit tutorials is that they explain how to use the code to make that tutorial. If someone submits a tutorial like for example:
How to make an application sing and dance

Use this code: #'#'#'#'#'#'#'#'#'#'#

Your finished.
Thats not very useful, people need to know what controls are used, where does the code go, what does the code do. Aslong as people do that then I think the tutorials a good one and will help someone one day cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

But some people doesn't understand that, so making it by the way I shown would be more secure, so before the tutorial being approved people could tell their opinion and rate the tutorial. So even before it is gonna be approved it can get some improvements.
User avatar
Doctorfrost
Dedicated Member
Dedicated Member
Posts: 53
Joined: Sun Oct 04, 2009 4:44 am

Thank you. Just a quick question. What is the tutorial suppose to create?
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

A Simple Application (Hello World)
User avatar
Doctorfrost
Dedicated Member
Dedicated Member
Posts: 53
Joined: Sun Oct 04, 2009 4:44 am

oh alright
Just to ask, are you good with mysql database connections to vb 2008.

I have been trying to get my program to retrieve a picture in a table and import it into a picture box. If anyone is able to help, please respond.

Sincerely, doctorfrost :)
23 posts Page 1 of 3
Return to “Tutorials”