Task Sheet 1.1 – Understanding VB

Visual basic has become the world’s most popular event driven programming language. So what is an event driven programming language? An event driven language is one that responds to events – clicking a button, clicking on the screen or selecting an item from a list. Languages like BASIC and Pascal were the most popular non-event driven languages in the 1980s – 1990s but are now being replaced by more modern languages like VB.net etc.

Visual Basic 2008 is an evolution of the Visual Basic language that is engineered for productively building type-safe and object-oriented applications. Visual Basic enables developers to target Windows, Web, and mobile devices On this course we will be using Visual Basic Express Edition (VB.net) to create Window forms; you might recognise a Window form see below.

Visual Studio 2008 has now been replaced by Visual Studio 2010, as we our learning the concepts of programming Visual Studio 2008 is a suitable environment to begin in. By using Visual Studio 2008 as a starting point you will start to understand what the makeup of all Microsoft Applications is, and be able to apply some of the knowledge you will acquire to MS databases or MS spreadsheets that you might have already created. Once you have understood some of the programming concepts in Visual Studio 2008 you will be able to transfer the skills you have learnt to Visual Studio 2010, by taking this approach you will achieve a more thorough understanding. (It is also free to download http://www.microsoft.com/express/download/)

Page 1 of 12 Brendan Coulson Visual Studio Programming Setting up the Program To start with we need to open Microsoft Visual Basic 2008 Express Edition.

Once you have opened Microsoft Visual Basic 2008 you will be confronted with the following Window. This is the interface for Visual Basic 2008 Express Edition, also known as the integrated development environment or IDE.

Page 2 of 12 Brendan Coulson Visual Studio Programming There are various projects to choose from, the one we are interested in is the Windows Forms Application, change the name to: MyFirstApplication and then click OK.

A new form displays in the IDE, and the necessary files for your project are added to the Solution Explorer window, as shown below.

Page 3 of 12 Brendan Coulson Visual Studio Programming This will take you to the Microsoft Visual Basic environment.

Toolbox

Solution explorer

Form Window

Properties

Error list

As you can see above there are many different windows displayed which are explained below.

 Solution Explorer – this contains the main components of the system i.e. Forms and the assemblies and references needed to create a basic program. As you add more functionality to the project the components will be added to the explorer  Toolbox – Holds all the controls that can be used on the form  Properties Window – All components of a program have properties that can be set either through this window or programmatically. If you click once on the Form icon in the Solution Explorer, a set of properties for the form are displayed in the Properties Window – see above.

Page 4 of 12 Brendan Coulson Visual Studio Programming Task: The File Name property for the form (default Form1) needs to be changed to a more suitable name for your project, name it FrmFirstProgram -do not have any spaces.

Rename to “FrmFirstProgram”

Change the Text from Form1 to “First Program” – this time you are allowed to leave spaces as this will be the title of the Form.

Rename to “First Program”

Your screen should now look like the one below.

Page 5 of 12 Brendan Coulson Visual Studio Programming Task: If you look in the solution window, you may notice that the Form name has not changed (Form1.vb). Right click on the form name and change it to FrmFirstProgram.vb.

Page 6 of 12 Brendan Coulson Visual Studio Programming OK I know what you are thinking, when does the fun begin?? Let’s make the form do something.

For the last part of this task, you are required to select a Panel control from the Toolbox and drag it to the top-left corner of the form.

Single click and hold, then drag it onto the form.

From the same toolbox click and drag a textbox onto the panel that you have just created. – See Below:

Page 7 of 12 Brendan Coulson Visual Studio Programming Now select a button from the toolbox and place it to the right of the textbox. Your form should look like the one below:

Finally, from the All Windows Forms tab, select a WebBrowser control and position it under the Panel.

Single click and hold, then drag it onto the form.

Page 8 of 12 Brendan Coulson Visual Studio Programming Your form should look like the one below:

Make the following changes to the controls using by selecting the control and making changes through the properties window: Control Name: Text: Textbox txtLocation Leave blank Button btnGo GO

Note: make sure you spell the names correctly. Your Final form should look like the one below:

Page 9 of 12 Brendan Coulson Visual Studio Programming We now need to add a line of code under the btnGo, to do this double click on the actual button.

You should see the code window appear – see below:

Add this following line of code in between Private Sub and End Sub:

WebBrowser1.Navigate(txtLocation.Text)

Your code window should look like the one below:

(This will be discussed again in more detail)

Page 10 of 12 Brendan Coulson Visual Studio Programming Once you have completed this step, go back to the design window by clicking on the tab shown below:

OK, we are ready to see if your program works. You need to select the debug button:

This will check to see if your program has any errors and lunches your program (This will be discussed again in more detail).

Page 11 of 12 Brendan Coulson Visual Studio Programming Try typing a URL in the textbox followed by clicking GO.

Congratulations you have created your first web browser.

Please ensure that you save all your work! – It is usually stored in a Visual Studio 2008 folder located on your H drive.

Page 12 of 12 Brendan Coulson Visual Studio Programming