an introduction to vb

Upload: mohammed-badrt-mostafa-effat

Post on 06-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 An Introduction to VB

    1/30

    An Introduction toVisual Basic.net

    By

    Eng. Mohammed Badrt Mostafa

    Teaching assistant-Faculty of engineering

    Mechanical department-Assiut university

    Mobile: 01110544110

    E-mail: [email protected]

    Website: mbmeducation.blogspot.com

    mailto:[email protected]:[email protected]
  • 8/3/2019 An Introduction to VB

    2/30

    Section one

    The interface

  • 8/3/2019 An Introduction to VB

    3/30

    Why visual basic?

    .net framework technology and its merit towards

    the programming languages and the freedom tochoose any language.

    Ease of understanding.[simple/natural code].

    Very common between developers.

  • 8/3/2019 An Introduction to VB

    4/30

    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 thanthat in the structured programming.

  • 8/3/2019 An Introduction to VB

    5/30

    The idea of OOPprogramming.OOP programming depends on that the programcontains of objects. Each object has characteristics

    and properties. Our code is handling with theseobjects.

    This way of programming is called the eventdriven programming. As objects contains manyevents that our code will deal with what shouldhapped when the object is exposed to that event.

  • 8/3/2019 An Introduction to VB

    6/30

    Click to edit Master text stylesSecond level Third level Fourth level Fifth level

    Form[the

    programinterface

    ]

    Listof

    objec

    ts

    Components of theprogram

    Properties ofthe selected

    object

  • 8/3/2019 An Introduction to VB

    7/30

    The idea of OOPprogramming-cont.

    Example:

    The most common event you know is the clickevent for the button object. e.g.; the program

    closes when you click on the close buttonobject(internally, we coded that object to closewhen it is exposed to the click event).

  • 8/3/2019 An Introduction to VB

    8/30

    ObjectsClick to edit Master text styles

    Second level Third level Fourth level Fifth level

  • 8/3/2019 An Introduction to VB

    9/30

    Objects that arecommonly used in anycalculation program.

    Textboxes(which receive inputs and can showoutputs in).

    Labels(which is used to describe what the

    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 itemfrom a list, or to appear many items on the liste.g; the state you choose in the countysection when creating a new mail account).

  • 8/3/2019 An Introduction to VB

    10/30

    Objects that arecommonly used in any

    calculation program-cont.

    Combo boxes(which are used to choose among

    different items. It apparently differ from the listbox in the arrow built in it e.g; the countryselection 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 youchoose one option).

  • 8/3/2019 An Introduction to VB

    11/30

    Objects that arecommonly used in anycalculation program-

    cont.

    Group box(which make you contain many

    objects for a certain shared task in a container).

    Menu strip(which enhance your program bymenus).

  • 8/3/2019 An Introduction to VB

    12/30

    Section two

    Programming

  • 8/3/2019 An Introduction to VB

    13/30

    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 default-type the start and end of each code block.

    The code editor automatically changes thefont you type with the type of the code yourwrite as we will see soon.

  • 8/3/2019 An Introduction to VB

    14/30

    Programming Essentials

    There are basic items for any program that

    any program depends on. The differencebetween one programming language toanother is the syntax that expresses each ofthem and they are:

    Variable declaration. Assignments. Branching. Looping.

  • 8/3/2019 An Introduction to VB

    15/30

    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

  • 8/3/2019 An Introduction to VB

    16/30

    1- Variable declaration-

    cont.String data type deals with characters in a set, nomatter what these characters are: numbers, letters.

    The Boolean data type is true/false data type, so, it isrepeatedly used in conditional statements.

    The date data type deals with dates.

    The numeric data type deals with numbers. Theseare many data types for the numeric one. Thecommonly used is Decimal.

  • 8/3/2019 An Introduction to VB

    17/30

    1- The variable

    declaration-cont.The keyword that is used in the variabledeclaration statement determines the scopeof 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 variableand 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 asdecimal

  • 8/3/2019 An Introduction to VB

    18/30

    3- Branching

    Branching means that you use a conditionalstatements 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 ifElse (when needed)

  • 8/3/2019 An Introduction to VB

    19/30

    3- Branching-cont.

    The select case statement takes the form:

    Select case variable name

    Case() to ()

    Statements

    Case is =()

    Statements

    End select.

  • 8/3/2019 An Introduction to VB

    20/30

    4- Looping

    Looping is used to do the sameoperation(execute the same code) for a certainnumber.

    The best and most commonly used code forlooping is the For-Next

    For counter=start to end [step()]

    Statements

    Next [counter]

  • 8/3/2019 An Introduction to VB

    21/30

    2- Assignments

    You must remember that each object hasproperties and characteristics. The way you dealwith the object is that:you type the object name, dot, then a menu

    will appear to you to choose what property ormethod of that object you want to use in yourcode.

    Example: if I want to put a name(Essam) in atextbox named textbox1, then you will typethat:

    textbox1.text=essam

    Here, we typed the object(textbox1) name,then,

  • 8/3/2019 An Introduction to VB

    22/30

    Procedures

    Each block you type your code in is a procedure. Thisprocedure as default has a declaring pre-written codefor you.

    Your task is to choose the procedure that you put yourcode in. you-in more accurate and specific way-choosethe 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 suitableevent that will generate the procedure for you in whichyou will type in your code.

  • 8/3/2019 An Introduction to VB

    23/30

    Example

    In this example, you will see how to design andcode a program that multiplies two numbers.We will refer to every thing that we learned

    from this presentation.

  • 8/3/2019 An Introduction to VB

    24/30

    The interface

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

    Click to edit Master text stylesSecond level Third level Fourth level Fifth level

  • 8/3/2019 An Introduction to VB

    25/30

    Before we codeClick to edit Master text styles

    Second level Third level Fourth level Fifth level

    Availableeventsfor that

    object

    From here,we choose

    the object wewant toprogram

  • 8/3/2019 An Introduction to VB

    26/30

    When we code

    Click to edit Master text stylesSecond level Third level Fourth level Fifth level

    Theobject

    name

    List ofproperties

    andmethod to

  • 8/3/2019 An Introduction to VB

    27/30

    The code

    Click to edit Master text stylesSecond level Third level Fourth level Fifth level

    Automatically generated start & end

    Assignment statement

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

  • 8/3/2019 An Introduction to VB

    28/30

    The ResultClick to edit Master text stylesSecond level Third level Fourth level Fifth level

    We types 6 and 5, then we activated the clickevent procedure by clicking on the button object

    which did the operation of multiplication and

    showed us the result in the third textbox. You must

  • 8/3/2019 An Introduction to VB

    29/30

    Conclusion

    When we want to design a program that performs acertain task, we draw its interface at first.

    That interface is a number of different objects.

    In your mind, the time you choose the object, youknow previously what this object is used for and thesuitable event for it.

    Then you turn to the code editor. Choose the objectthat you will program, choose the suitable event. Theprocedure will appear to you requiring your code.

  • 8/3/2019 An Introduction to VB

    30/30

    Conclusion-cont.

    You will start your code that includes the fourmajor items of programming we mentionedbefore restricted by their rules.

    Then you run the program to test it.

    Finally, you package your program.

    Congratulations