22
San Carlos de Guatemala University Engineering Science and Systems Engineering Technical English I How to use a programming language with visual basic

How to Start Using Visual Basic

Embed Size (px)

DESCRIPTION

This is a little manual for the people starting on the programming world. We used Visual Basic that is one of the most common languages for the begginer. Hope you enjoy it.

Citation preview

Page 1: How to Start Using Visual Basic

San Carlos de Guatemala UniversityEngineeringScience and Systems EngineeringTechnical English I

How to use a programming language with visual basic

Name: Myriam Priscila Velasquez CumesID No. 201216037

Page 2: How to Start Using Visual Basic

INDEXpage

Introduction…………………………………………. 3

Objectives……………………………………………. 4

Chapter 1 What is visual Basic?.................................. 5

Chapter 2 Common elements of Visual Basic environment and how to start………………… 6

Chapter 3 Properties window………………………………… 8

Chapter 4 Helpful tips…………………………………………… 9

Chapter 5 Let´s use the programming language……… 10

Chapter 6 How to change variables into text………….. 10

Chapter 7 Let’s add a button to a form…………………… 12

Chapter 8 Basic elements on a code……………………… 13

Chapter 9 Example………………………………………………. 13

Chapter 10 Some Issues could appear while working with visual basic…………………………………. 14

Conclusions………………………………………… 15

Glossary….………………………………………….. 16

Annexes………………………………………………. 17

Bibligraphy…………………………………………… 20

Introduction

Over the past years technology has been increasing its presence in many aspects of life: Jobs, Hobbies, Trips, etc. And technology has

Page 3: How to Start Using Visual Basic

needed and used some other resources to be created. Some of those resources have been programming languages. They are some kind of vocabulary and grammatical rules for instructing a computer to perform tasks needed by the programmer.

This mini-handbook shows us how to easy can be to create a project. It is also for the users to be familiarized with programming languages, because even when every programming language has its own syntaxes, rules, keywords all they use need to be developed in a similar way. In this case, the IDE (Integrated Development Environment) will be of Visual Basic. You will be able to learn specific things you need to know those kinds of languages, about how fascinating they are and the most important thing: How start programming.

You will find a short description of the tools and options Visual Basic offers and some tips to take into consideration in order to start. This is for beginners but you can be an expert once you start programming you will be willing to continue and learn more and more.

Objectives

To make programming language understandable.

To make Visual Basic usage accessible for everyone.

To let people know that it order to program, it´s not mandatory to

have experience. Just the necessary tools.

To empower people with some knowledge in order to start with a

project.

Page 4: How to Start Using Visual Basic

To give just essential topics of how to work with Visual Basic in

order to not fluster people with too much information.

To encourage beginners with some useful tips about how to deal

with a programming language.

To warn people about important rules to follow in order to not make

a mess with too many instructions which are part of a program.

What is Visual Basic?

It´s name refers to the method used to create what users can see; visual. And it refers to the friendly interface; basic. Visual Basic was initially a procedural programming language. Then, Microsoft decided to make Visual Basic into more powerful object oriented programming language.

It is one of the most interactive programming languages and that is why it one of the most used in the world for every kind of programmers. Essentially, a Visual Basic user interface consists of objects that can be placed on the screen and can be arranged so that the screen looks pretty for the customer or user.

Every program created in Visual Basic has some kind of structure: The modules are like chapter, the procedures are like paragraphs and the lines are la phrases. But there is nothing to worry about. In a few steps you will be able to “speak” the Visual Basic´s language.

Page 5: How to Start Using Visual Basic

Common elements of Visual Basic environment

Forms (also known as windows) Buttons (such as command buttons and radio buttons) Boxes (such as text boxes and check boxes) Labels Pictures (such as icons and graphics)

How to start

To design your user interface, follow these steps:

1. Create a form

Page 6: How to Start Using Visual Basic

2. Choose the object you want to draw from the Toolbox.

Page 7: How to Start Using Visual Basic

3. Draw the object on the form.

Example

Properties window for a form

To change the form's title to any name, simple click in the box on the right of the Text property and type in the new name.

Properties can be set by highlighting the items in the right column then change them by typing what we need. There are several option of the form such as font, location, size, foreground color, background color, MaximizeBox, MinimizeBox and more.

And this is not the only way it can be changed. A form can also be modified by codes. And that is one of the hundred of options that a programming language can give us. That makes BV a multi-programming modes making it easy.

It is also important to mention that visual basic works so similar to any software of Windows. The

Page 8: How to Start Using Visual Basic

buttons, the variety of options for every task and the different commands which can be used to perform and action. For example: The tool bars at the top of the window give us options as save a document, open a new file, run a program, to edit something, to view a code, etc.

Helpful tipsOn the form the controls can be added and aligned

The FormLayout icon lets choose the way the application is going to be opened when pressing play.

And there are some other Windows to edit the programming code like Code Editor and there are some others to see the variables while the programm is being executed like Debbuger, Immediate, Locals and Watch. And these tools and windows are the IDE (Integrated Development Environment).Something useful is to choose on Environment the “Promp to Save Changes” option and the click on “When a Program Starts” in order for the changes to be saved before clicking to reproduce.

Page 9: How to Start Using Visual Basic

Help button: It has the ability of giving you information about any property or form by just selecting it and clicking F1.

Let´s use the programming language

Now that we already know something about the Visual Basic environment let´s focus on how to create a program.

It is important to remember the use of variables. They can take any value, as letters (string), whole numbers (integer), fractions (double) or true and false values (boolean).

*To assign a value to a variable the equal sign is used (=). 

Whenever the commands start to being entered an editor will open a part of the program called Form1_Load which is also known as a procedure. And the code which will be written on that procedure is going to be the group of instructions that are going to be performed when the form will charge for the first time.

*Every time a code needs to show a real text it needs to be entered between quotation marks “”.MsgBox is used to show something.

How to change variables into text:

Each variable from Visual Basic can be changed into text using the CStr abbreviation. It comes from Convert to String. In the same way as CStr can be used there are some abbreviations to do that as:

Page 10: How to Start Using Visual Basic

Example: 1.

In this example the value showed will be: 0.5

*Dim: Dimension It´s the variable used to declare (or "tell" Visual Basic) that you are setting up a variable under that name.

2. txtResult.Text = Val(txtOper1.Text) * Val(txtOper2.Text)This example is showing how the command Val will show the result of two text variables in a whole number.

To play a form you just need to click Debug > Start from the menu bar. Or press F5.

To stop it:

1. Click the Red X at the top right of your Form2. Click Debug > Stop Debugging from the menu bar3. Press Shift + F5 on your keyboard

Dim A As Integer = 1Dim B As Integer = 2MsgBox(CDbl(A / B)

Page 11: How to Start Using Visual Basic

When clicking the right button of the mouse with the form previously selected. The option to save the project will appear.

Let’s add a button to a form.

Click on the Button tool in the toolbox with the left hand mouse button once.

Place the mouse to a blank area of the form - It will turn into a cross

Press and hold the left mouse button. With the button drag across the form and you can stop holding it

once you are happy with the size.

This method can be used to draw most of the controls. And once a control is created it can be modify with the options of the properties window.

In order to start working with a code it is just necessary to double click on the control.

Basic elements on a code:

Private: It means that no part of the program can see the code within that part of the code except for the control that you would be working with. Sub: It refers to Subroutine. The "Sub" word tells that some code follows, and that it needs to be executedName of the control we are working with.Event: Instructions, what the code is going to do when executed.End Sub: The subroutine ends right here. This signifies the end of our code.

Example:

This is a program to find the highest digit of three numbers entered in different boxes.

Page 12: How to Start Using Visual Basic

Private Sub Cmdborrar_Click() Txtnum1.Text = "" Txtnum2.Text = "" Txtnum3.Text = "" End Sub Private Sub cmdhallar_Click() Dim A, B, C A = Txtnum1.Text B = Txtnum2.Text C = Txtnum3.Text If (A > B) Then If (A > C) Then MsgBox ("The highest number is: " & A) Else MsgBox ("The highest number is: " & C)

End If Else If (B > C) Then MsgBox ("The highest number is: " & B) Else MsgBox ("The highest number is: " & C) End If End If End Sub Private Sub Command1_Click() Guia_1_1.Hide Guia_1.Show End Sub

And this is the way it may looks like:

Some Issues could appear while working with visual basic:

Versioning problems associated with runtime. Poor support

Page 13: How to Start Using Visual Basic

Inability to create multi-threaded applications. Variant types have a greater performance and storage overhead

than strongly typed programming languages. The development environment is no longer supported by Microsoft.

But they are something you can deal with and take advantage of this Software.

Just remember that the most important thing while creating a code is working clean, with certain names related with the part of the program that is being defined. In order to don’t have misunderstandings while making bigger projects.Now you can feel free to work with Visual Basic with this information. Go ahead and give yourself the freedom to do what you want by using the lots of options and tools available that Visual Basic offers.

Conclusions

Visual Basic is for everyone willing to start using programming language.

There are different ways to perform actions and get the same result.

It does not matter the way a program is developed it just has to follow the rules for the programming language used.

Visual Basic helps users to make everything understandable. Visual Basic makes the visual part or a program easier. Anyone can start with simple projects in order to learn about

how to program. It is necessary sometimes to learn by hearth some topics like

in every new language.

Page 14: How to Start Using Visual Basic

It is important to be organized in order to get a successful program without errors.

Glossary

1. Boolean: Computers of or relating to a data type having two possible values representing “true” or “false”.

2. Caption: A title or explanation for a picture or illustration, especially in a magazine.

3. Command: To direct with specific authority or prerogative; order.

4. Currency: Something that is used as a medium of exchange; money.

5. Debug: To detect and remove errors from (a computer program).

6. Drag: To draw with force, effort, or difficulty; pull heavily or slowly along.

7. Fore color: Fore: Situated at or toward the front, as compared with something else. Fore color: Color situated in the front.

8. Layout: An arrangement or plan.

9. Multi-threaded: Interwoven or ornamented with threads.

Page 15: How to Start Using Visual Basic

10. String: Any series of things arranged or connected in a line or following closely one after another.

Annexes

Annex 1: Tools in the Visual Basic Toolbox

Icon

Tool Name What This Tool Does

Pointer Selects objects

Picture box Draws a box to display graphics

Label Draws a box to display text

Text box Draws a box that can display text and let the user type in text

Frame Groups two or more objects together

Command button Draws a command button

Check box Draws a check box

Page 16: How to Start Using Visual Basic

Option (or radio) button

Draws a radio button

Combo box Draws a combo box

List box Draws a list box

Horizontal scroll bar

Draws a horizontal scroll bar

Vertical scroll bar Draws a vertical scroll bar

Timer Places a timer on a form

Drive list box Draws a drive list box that displays all the disk drives available

Directory list box Draws a directory list box that displays a directory on a particular disk drive

File list box Draws a file list box that displays files in a specific directory

Shape Draws a geometric shape such as a circle or a square

Line Draws a line

Image box Draws a box to display graphics

Data control Draws a control to link a program to a database file

Page 17: How to Start Using Visual Basic

OLE Draws a box to insert an OLE object

Annex 2: Abbreviations

Annex 3: Types of variables

Page 18: How to Start Using Visual Basic

Bibliography

Javier García de Jalón, Aprenda Visual Basic 6.0 como si estuviera en primero, Agosto 1999 , http://mat21.etsii.upm.es/ayudainf/aprendainf/Visualbasic6/vbasic60.pdf

https://www.youtube.com/watch?v=7lpuICNVP4

Microsoft developer network, Introducción al lenguaje de programación Visual Basic, november 2007.https://msdn.microsoft.com/library/xk24xdbe%28v=vs.90%29.aspx

Page 19: How to Start Using Visual Basic

Liew Voon Kiong, Visual Basic 2008 made easy, 2009 http://www.vbtutor.net/vb2008book/vb2008me_preview.pdf

Wallace Wang, Visual Basic 6 for Dummies, http://www.dummies.com/how-to/content/meeting-the-tools-in-the-visual-basic-toolbox.html

Pemrograman, Visual Basic 6.0 – Session 2, February 7, 2011 http://pemrograman-ilmiyah.blogspot.com/2011/02/visual-basic-60-session-2.html

Home and learn copyright, Free Visual Basic .NET Course http://www.homeandlearn.co.uk/NET/nets1p11.html

Manuel Vergara, Aprende a utilizar Visual Basic, 2011

http://visualbasicmavd.blogspot.com/