Introduction to Microsoft Visual Basic.NET

Introduction to Microsoft Visual Basic.NET

Cairo University Faculty of Economics and Political Science Social Science Computing Department Ms. Nahed Taha Computer Applications in Modern Information societies (2) Second Year 2015-2016 Part Two Course Information • • • • • • • • • 2 Table of Content • Part One: Notes on Coding…………………….……………….54 • Introduction to Visual- Basic. Net………........4 • Launching Visual Studio……………...……....9 • Part Three: • Start A New Project…………………..……....11 • VB. Operators and Functions……………...59 • Screen Elements…………………………........13 • Part Four: • Adding Controls Using Toolbox………........16 • Decisions Statements……………………….60 • Controls Properties………………..…………19 • Debugging A Program…………………..…..38 • Part Five: • Saving A Program…………………………....40 • Looping Statements………………………...70 • Part Two: • Create Variables in VB.NET…………............43 Introduction to Visual- Basic. Net Microsoft Visual Basic . NET • Microsoft Visual Basic is a programming environment used to create graphical user interface (GUI) applications for the Microsoft Windows family of operating systems. • It usually ships either by itself or as part of Microsoft Visual Studio. 5 Microsoft Visual Basic . NET • Microsoft's Visual Studio includes several different programming languages: • Visual Basic, • Visual C# (C sharp), • Visual C++ (cee-plus-plus), • Visual F# (F sharp), • JScript and • Web Development (called ASP.NET). • It also includes the .NET 4 Framework upon which these languages operate. 6 Microsoft Visual Basic . NET • Visual Basic is an object-oriented programming language. • You work with objects in building an application. • Examples: Form objects, Button objects, TextBox objects, Label objects, ListBox objects, PictureBox objects, and more. 7 Microsoft Visual Basic . NET • There are three primary steps involved in building a Visual Basic application: 1. Draw the user interface 2. Assign properties to controls 3. Attach code to controls 8 Launching Visual Studio Launching Visual Studio 10 Start A New Project Start A New Project 12 Screen Elements Screen Elements Solution Explorer Window: Displays Toolbars filenames for files that comprise a project. Form Designer (Document Window) Toolbox: Contains controls that are used to build forms. Properties Window: Displays properties of the currently selected object. Error List Window 14 Toolbox Quick Search Tool Description Button Raises an event when the user clicks it. CheckBox Enables the user to select or clear the associated option. ComboBox Displays an editable text with a dropdown list of permitted values. Label Provides runtime information or descriptive text for a control. ListBox Displays a list from which the user can select items. PictureBox Displays an image. RadioButton Enables the user to select a single option from a group of choices when paired with other radio buttons. TextBox Is used to display information entered at design time, by a user at run-time, or assigned within code. The displayed text may be edited. GroupBox Displays a frame around a group of controls with an optional caption. 15 Adding Controls Using Toolbox Activity (1) Adding Controls using Toolbox Create a form that has 3 textboxes and 3 labels Double Click/Drag and Drop 17 Activity (1) Adding Controls using Toolbox Create a form that has 3 textboxes and 3 labels Double Click/Drag and Drop √ 18 Controls Properties Controls Properties • Controls you added to the form (textboxes and labels), and the form itself, are called control objects. • In VB.NET, you can change the appearance properties of a control (text, Text alignment, Font, color, etc.) through the Properties Window (menu). • Example: If your television were a control, it too would have properties: On/Off button property, color property, volume property, and so on. 20 Activity (2) Controls Properties Change the properties of the form you’ve created earlier to be look like this: 21 Activity (2) Controls Properties (1) Change the value of the text property of a form Click on the Form Click inside the area next to "Text", and delete the word “Form1” When "Form1" has been deleted, type the words “My First Form” √ 22 Activity (2) Controls Properties (2) Change the value of the text properties of the 3 labels Click inside the area next to "Text", and delete the word “Label1" When “Label1" has been deleted, type the Click on the label1 words “First Name" √ Do the same for label 2 and label 3 23 Activity (2) Controls Properties (3) Change the font size of the labels Click on the label1 In the properties menu, select the Font property and click on the … Button 24 Activity (2) Controls Properties (3) Change the font size of the labels √ Change the following: Font: MMa Century Font Style: Bold Size: 12 Do the same for label 2 and label 3 25 Activity (2) Controls Properties (4) Change the color property of the form Click on the Form 26 Activity (3) Create a Pizza Order to be look like this: 27 Activity (3) (1) Add Controls (GroupBox, RadioButton, CheckBox, PictureBox, ComboBox, Button) GroupBox [RadioButton] PictureBox GroupBox [Check Box] Combo Box Button Radio Button 28 Activity (3) (2) Set Form Properties Form: Color Property [Choose any Color] Form: Text [Pizza Order Form] 29 Activity (3) (3) Set GroupBox and RadioButton Properties Group Box: Text [Size] Radio Button: Text [Small, Medium or Large] Radio Button: Text [Eat in or Eat out] 30 Activity (3) (4) Set GroupBox and CheckBox Properties GroupBox : Text [Toppings] CheckBox : Text [Black Olives] 31 Activity (3) (5) Set Picture Properties To add a picture: (1) Click on the picture box. (2) In the properties menu, select image property and click on … Button 32 Activity (3) (5) Set Picture Properties 33 Activity (3) (5) Set Picture Properties 34 To add a items to a combo Box: (1) Click on the combo box. Activity (3) (2) In the properties menu, select Items property and click on … Button. (6) Set ComboBox Properties (3) Type Items each on a separate line. ComboBox :Text [Crust Type] ComboBox: Items: Thin Stuffed Crust Deep Pan 35 Activity (3) (6) Set ComboBox Properties √ 36 Activity (3) (7) Set Button Properties Button1: Text [Order] Button2: Text [Close] 37 Debugging A Program Debugging A Program • Debugging (Running) is the process of locating and fixing bugs (errors) in computer program code. You can start debugging mode by: (1) Clicking on the Green Arrow (2) Clicking on Debug from menu bar > Start Debugging . (3) Pressing F5 on your keyboard . 39 Saving A Program Saving A Program 41 Saving A Program Click here To change the Location of the File 42 Create Variables in VB.NET VB .NET Variables • A variable is a storage area of the computer's memory. • Variable Declaration Syntax : Dim VariableName As DataType VariableName: the variable we declare for hold the values DataType: the type of data that the variable can hold. • You can declare multiple variables of the same or different type in the same line, as follows: Dim Qty As Integer, Amount As Decimal, CardNum As String Dim Length, Width, Height As Integer, Volume, Area As Double 44 VB .NET Variables • Visual Basic recognizes the following five categories of variables: • Numeric: store numbers. • Integer: store whole numbers. • Decimal: useful when we want a precise number of decimal places. • Single: floating-point numbers with limited precision. • Double: floating-point numbers with extreme precision. • String: store text. • Boolean: store True or False data. • Date: store date (year, month, day, time) data. • Object: store any type of data. 45 Activity (1) Write a programme to add two numbers together and display the answer in a msgbox. √ 46 Activity (2) Write a programme to add two numbers together and display the answer in a textbox. √ 47 Activity (3) Write a programme to add ANY two numbers and display the answer in a textbox. √ 48 Activity (4) Create the following form that contains two labels for variables (a) and (b) and two textboxes for displaying the values of the variables. • The Single and Double data type names come from single-precision and double- precision numbers. • Double-precision numbers are stored internally with greater accuracy than single precision numbers. • In fact, computers must store values in a fixed number of bytes, so the accuracy will be lost. √ 49 Activity (5) Create a third textbox to display the difference (a-b) √ 50 Activity (6) If the information we want to store in our variables is a First Name and a Last Name. • A string is a sequence of characters, and you use double quotes to mark its beginning and end. • Concatenation means linking something together in a chain or series. If you have two strings that you join together, one after the other, you say they are concatenated. You can think of concatenation as addition for strings. • The ampersand symbol ( & ) is used to join strings together. √ 51 Activity (7) If the information we want to store in our variables is a First Name and a Last Name. As you can see, the two words are actually joined as one. We can add a bit of space between the two words by using another ampersand. √ 52 Activity (8) If the information we want to store in our variables is a First Name and a Last Name. √ 53 Notes on Coding (Text) VS. (Name) Property 55 Code Comments • You can write comments to yourself or any other programmer to indicate what a code sentence is for by adding the symbol ( ‘ ) before the comment you want to add. 56 Message Boxes • There are two ways to display output in a message box: Msgbox (Result) and Message.Show (Result, “Solution”). 57 Message Boxes 58 Visual Basic Operators and Functions Homework Solve Activity One and Two (Page 30-35). Decision Statements Activity (1) If… Then Statements Create a simple program to display the message “Number is indeed 27!” when the variable called Number is 27. √ 61 Activity (2) If… Then Statements Change the value of the variable to 1000. When you run the program, nothing will happen when you click the button.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    81 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us