Você está na página 1de 30

An Introduction to Visual Basic.

net
By

Eng. Mohammed Badrt Mostafa


Teaching assistant-Faculty of engineering Mechanical department-Assiut university Mobile: 01110544110 E-mail: eng.mbm1986@hotmail.com Website: mbmeducation.blogspot.com

Section one
The interface

Why visual basic?


.net framework technology and its merit towards the programming languages and the freedom to choose any language. Ease of understanding.[simple/natural code]. Very common between developers.

Turning to Object-oriented programming(OOP)


OOP programming enables you to develop an .exe program that can run at any PC. The beautiful appearance of the program than that in the structured programming.

The idea of OOP programming.


OOP programming depends on that the program contains of objects. Each object has characteristics and properties. Our code is handling with these objects. This way of programming is called the event driven programming. As objects contains many events that our code will deal with what should happed when the object is exposed to that event.

Click to edit Master text styles Second level Third level Fourth level Fifth level Component s of the program Form[th e program interface ] List of objec ts Properties of the selected object

The idea of OOP The most common event you know is the click event programming-cont. for the button object. e.g.; the program closes when you click on the close button Example: object(internally, we coded that object to close
when it is exposed to the click event).

Objects
Click to edit Master text styles Second level Third level Fourth level Fifth level

Objects that are commonly used and can show in any Textboxes(which receive inputs outputs in). calculation describe what the program. Labels(which is used to
object is for). Buttons(which are basic item of any program). Radio buttons(which give us options to choose from). List boxes(which make you choose an item from a list, or to appear many items on the list e.g; the state you choose in the county section when creating a new mail account).

Objects that are commonly used in any Combo boxes(which are used to choose among calculation program-cont. different items. It apparently differ from the list
box in the arrow built in it e.g; the country selection in creating mail account). Check boxes(which enables you to choose from different options. You can mark on many items, on the contrary, the radio button makes you choose one option).

Objects that are commonly used in any Group box(which make you contain many calculation programobjects for a certain shared task in a container). cont.
Menu strip(which enhance your program by menus).

Section two
Programming

Where to program[the code editor]

The visual studio provides you with a code editor in which you type your code. The code editor is designed to-by defaulttype the start and end of each code block. The code editor automatically changes the font you type with the type of the code your write as we will see soon.

Programming Essentials

There are basic items for any program that any program depends on. The difference between one programming language to another is the syntax that expresses each of them and they are: Variable declaration. Assignments. Branching. Looping.

1- Variable declaration
The variable is that thing that holds your data. The variable declaration takes this form: [scope keyword] variable name As [data type] There are different data types: String-Numeric-Boolean-Date

1- Variable declarationcont.
String data type deals with characters in a set, no matter what these characters are: numbers, letters. The Boolean data type is true/false data type, so, it is repeatedly used in conditional statements. The date data type deals with dates. The numeric data type deals with numbers. These are many data types for the numeric one. The commonly used is Decimal.

The keyword that is used in the variable declaration statement determines the scope of that variable, or, to what extents in the program the variable will be valid to use, or, which part of the program will see the variable and it will be invisible for the other parts. The most common keyword used is: Dim If we take an example to declare a variable called essam, that hold a numeric(decimal) data, the statement will be like: Dim essam as decimal

1- The variable declaration-cont.

3- Branching

Branching means that you use a conditional statements in your code. Two types of these statements are provided: If statement-Select case statement The if statement takes the form: If(condition) then else if Else (when needed)

3- Branching-cont.
The select case statement takes the form: Select case variable name Case() to () Statements Case is <>=() Statements End select.

4- Looping
Looping is used to do the same operation(execute the same code) for a certain number. The best and most commonly used code for looping is the For-Next For counter=start to end [step()] Statements Next [counter]

2- Assignments

You must remember that each object has properties and characteristics. The way you deal with the object is that: you type the object name, dot, then a menu will appear to you to choose what property or method of that object you want to use in your code. Example: if I want to put a name(Essam) in a textbox named textbox1, then you will type that: textbox1.text=essam Here, we typed the object(textbox1) name,then,

Procedures
Each block you type your code in is a procedure. This procedure as default has a declaring pre-written code for you. Your task is to choose the procedure that you put your code in. you-in more accurate and specific way-choose the event that your code will be carried out based on it. As explained about choosing the property text for the textbox object properties, also, we choose the suitable event that will generate the procedure for you in which you will type in your code.

Example
In this example, you will see how to design and code a program that multiplies two numbers. We will refer to every thing that we learned from this presentation.

The interface
Click to edit Master text styles Second level Third level Fourth level Fifth level

This Program contains 8 object that are: form, three labels, three text boxes, one button.

Before we code
Click to edit Master text styles Second level Third level Fourth level Fifth level

From here, we choose the object we want to program Available events for that object

When we code
Click to edit Master text styles Second level Third level Fourth level Fifth level The obje ct nam e

List of properties and method to

The code
Automatically generated start & end Click to edit Master text styles Second level Third level Fourth level Fifth level

Assignment statement

e assignment font is black and the start/end statement are b

The Result
Click to edit Master text styles Second level Third level Fourth level Fifth level

We types 6 and 5, then we activated the click event procedure by clicking on the button object which did the operation of multiplication and showed us the result in the third textbox. You must

Conclusion
When we want to design a program that performs a certain task, we draw its interface at first. That interface is a number of different objects. In your mind, the time you choose the object, you know previously what this object is used for and the suitable event for it. Then you turn to the code editor. Choose the object that you will program, choose the suitable event. The procedure will appear to you requiring your code.

Conclusion-cont.
You will start your code that includes the four major items of programming we mentioned before restricted by their rules. Then you run the program to test it. Finally, you package your program.

Congratulations

Você também pode gostar