VB.Net Introduction. What is programming? Writing computer programs means writing instructions in a logical sequence, that will make the computer follow.

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
ISYS 573 Special Topic – VB.Net David Chao. The History of VB Early 1960s:BASIC-Beginner’s All-Purpose Symbolic Instruction Code –Teaching –Simple syntax,
.NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically. –Programming in.
VB.Net Introduction - 2. Counter Example: Keep track the number of times a user clicks a button Need to declare a variable: Dim Counter As Integer Need.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
VB.Net Introduction. .NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically.
VB.Net Introduction. .NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically.
VB.Net Introduction. .NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically.
VB.Net Introduction. Visual Studio 2010 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# or VB –Windows.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic Chapter 1 Mr. Wangler.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 1: Introduction to Computers and Programming.
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter 2: Using Data.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
C# Introduction ISYS 350. Visual Studio 2013 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
Chapter Two Creating a First Project in Visual Basic.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Applications Development
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Programming with Microsoft Visual Basic th Edition
VB.Net Introduction. Visual Studio 2008 It supports VB.Net, J#, C#, and C++. Demo: –Start page: Recent projects –Starting project: File/New Project/Project.
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
VB.Net Introduction. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# /VB/Other language.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
CHAPTER THREE Representing Data: Constants and Variables.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
C# Introduction ISYS 350.
Visual Basic.NET Windows Programming
A variable is a name for a value stored in memory.
C# Introduction ISYS 350.
C# Introduction ISYS 350.
C# Introduction ISYS 350.
C# Introduction ISYS 350.
Variables and Arithmetic Operations
C# Introduction ISYS 350.
C# Introduction ISYS 350.
CIS16 Application Development Programming with Visual Basic
C# Introduction ISYS 350.
C# Introduction ISYS 350.
VB.Net Introduction.
Introduction to Programming
C# Introduction ISYS 350.
Presentation transcript:

VB.Net Introduction

What is programming? Writing computer programs means writing instructions in a logical sequence, that will make the computer follow and run a program based on those instructions.

Write a Program that asks user to enter two numbers and displays the sum A program typically consists of three parts: –Input, process, output For this program: –Inputs: two numbers –Process: add the two numbers –Output: the sum This program must be able to handle any two numbers.

What is a variable? A named location where a value is stored. Examples: –Variables: X, Y –Variables: Number1, Number2, Sum –Variables Salary, TaxRate –Variables CustomerName, CityName Meaningful names Numeric data and text (or string) data

Input, process, output Input: Enter two numbers and save them in variables Num1, Num2 Process: Add the two numbers and same the result in a variable Sum Output: Display Sum

User Interface for Input/Output Command interface –Example: Start/Run/Cmd Graphical User Interface, GUI –Example: Mortgage calculator calc.com/mortgage/simple.html

Assignment Statement Example: Sum=Num1 + Num2 Tax = Salary * TaxRate

Write a Program that asks user to enter two numbers and displays the larger number For this program: –Inputs: two numbers Num1, Num2 –Process: Determine the larger number, Larger If Num1 is greater than Num2 then Larger = Num1 Otherwise, Larger = Num2 –Output: Display larger

Write a Program that asks user to enter three numbers and displays the largest number For this program: –Inputs: three numbers Num1, Num2, Num3 –Process: How to determine the largest number? There are many ways to do this. –Output: the largest number How about 5 numbers? Or any number of values?

Write a Program that asks user to enter 5 numbers and displays the largest number Inputs: Num1, Num2, Num3, Num4, Num5 Process: Largest = Num1 If Num2>Largest Then largest = Num2 If Num3>Largest Then largest = Num3 If Num4>Largest Then largest = Num4 If Num5>Largest Then largest = Num5 Output: Largest Note: Pseudo Code

Write a Program that asks user to enter any numbers and displays the largest number Process: Largest = the first number Get the next number If the next number is greater than Largest Then Largest = the next number Repeat this part until no more data Note: Loop

Fundamental Programming Constructs Variables, expressions, and assignment Input/Output Sequence Decision Loop

A metaphor with cooking Programming is like writing down a recipe for someone else to use: –Ingredients –Cooking instructions –End product

Integrated Development Environment, IDE An integrated development environment (IDE) also known as integrated design environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: –a source code editor –a compiler and/or an interpreter –build automation tools –a debugger Examples: Visual Studio for.Net, NetBeans for Java

Install Visual Studio You need a blank DVD Recordable or Rewritable disk (typically with at least 4.7 GB of storage), not CD. 2. Go to Business Computing Lab. On the right-hand side of the entrance find the workstation with a label: MSDN 3. Turn on the computer. When the computer prompt you for password please enter: setmefree 4. With your DVD disk in the drive, find and click the VS 2008 icon on the desktop to start the process. 5. Once done, install VS 2008 on your computer. You don't need any key to install.

Visual Studio 2008 It supports VB.Net, J#, C#, and C++. Demo: –Start page: Recent projects –Starting project: File/New Project/Project types: Windows Application –View: Solution Explorer/Data Sources Server Explorer Property Window ToolBox –Form design view/Form code view –Tools/Option –Environment –Projects and Solutions »VB defaults –Project/Add New Item –Project properties: Right-click project name and choose Properties Start Up form –Property window example

Introduction to Visual Basic.Net Event-driven programming –The interface for a VB program consists of one or more forms, containing one or more controls (screen objects). –Form and controls have events that can respond to. Typical events include clicking a mouse button, type a character on the keyboard, changing a value, etc. –Event procedure

Typical Interface Controls Example: Form TextBox Label Button CheckBox RadioButton ListBox Etc.

Form Properties: –Name, FormBorderStyle, Text, BackColor, BackImage, Opacity Events: –Load, FormClosing, FormClosed –GotFocus, LostFocus –MouseHover, Click, DoubleCLick

Text Box Properties: –BorderStyle, Text – PasswordChar –Multiline, ScrollBar To refer to a property: –ControlName.PropertyName –Ex. TextBox1.Text To assign the text property to a variable: –Ex. Num1= TextBox1.Text

Typical VB.Net Programming Tasks Creating the GUI elements that make up the application’s user interface. –Visualize the application. –Make a list of the controls needed. Setting the properties of the GUI elements Writing procedures that respond to events and perform other operations.

Demo First Name Last Name Full Name.Control properties.Event: Click, MouseMove, Form Load, etc..Event procedures Sum: textBox3.text=TextBox1.text + TextBox2.text Demo: Control text alignment using the TextAlign property

Demo Num1 Num2 Sum =.Control properties.Event: Click, MouseMove, Form Load, etc..Event procedures Sum: textBox3.text=CStr(CDbl(textBox1.text)+CDbl(textBox2.text)) Or (CDbl(textBox1.text)+CDbl(textBox2.text)).toString.

Configure VB Project Project property page –Application –Compile –References Tools/Options –Environment –Projects and Solutions »VB defaults

VB Defaults Option Explicit: –On --- must declare variables before use Option Strict: –Off --- VB will convert the data Option Compare: –Binary --- case sensitive –Text --- case insensitive Option Infer –On --- When you set Option Infer to On, you can declare variables without explicitly stating a data type. The compiler infers the data type of a variable from the type of its initialization expression.

Variable Declarations Option Explicit Dim variableName as DataType Variable naming rules: –The first character must be a letter or an underscore character. –Use only letters, digits, and underscore. –Cannot contain spaces or periods. –No VB keywords Naming conventions: –Descriptive –Consistent lower and upper case characters. Ex. Camel casing: lowerUpper, employeeName

Control Naming Conventions The first three letters should be a lowercase prefix that indicates the control’s type. –frm, txt, lbl, btn. The first letter after the prefix should be uppercase. –txtSalary, lblMessage The part of the control name after the prefix should describe the control’s purpose in the application.

VB Data Types Boolean (True/False):2 bytes Byte: Holds a whole number from 0 to 255. Char: single character Date: date and time, 8 bytes. Decimal: Real number up to 29 significant digits, 16 bytes Double: real, 8 bytes Single: real, 4 bytes Integer: 4 bytes(int32, uint32) Long: 8 bytes integer Short: 2 bytes integer String Object: Holds a reference of an object

Variable Declaration Examples Dim empName as String Declare multiple variables with one Dim: –Dim empName, dependentName, empSSN as String Dim X As Integer, Y As Single Initiatialization –Dim interestRate as Double =

Data Conversion Implicit conversion: When you assign a value of one data type to a variable of another data type, VB attempts to convert the value being assigned to the data type of the variable if the OptionStrict is set to Off. Explicit conversion: –VB.Net Functions: CStr, Ccur, CDbl, Cint, CLng, CSng, Cdate,Val, etc. –.Net System.Convert Type class’s methods: –toString

Date Data Type Variables of the Date data type can hold both a date and a time. The smallest value is midnight (00:00:00) of Jan 1 of the year 1. The largest value is 11:59:59 PM of Dec. 31 of the year Date literals: A date literal may contain the date, the time, or both, and must be enclosed in # symbols: –#1/30/2003#, #1/31/2003 2:10:00 PM# –#6:30 PM#, #18:30:00# Note: ControlPanel/RegionalOptions/Date

Date Literal Example: –Dim startDate as dateTime –startDate = #1/30/2003# Use the System.Convert.ToDateTime function to convert a string to a date value: –startDate = System.Convert.ToDateTime(“1/30/2003”) –If date string is entered in a text box: startDate = System.Convert.ToDateTime(txtDate.text) Or startDate=Cdate(txtDate.text) Date data type format methods

Some Date Functions Now: Current date and time Today: Current date TimeOfDay DateDiff: Demo –Days between two dates –Days to Christmas DateDiff(DateInterval.Day, Today(), #12/25/2009#) –Date data type properties and methods

Using Online Help Example:Search Help for DateDiff MSDN VB Developer Center – us/vbasic/default.aspx –Library/Visual Studio/Visual Basic Reference –Language reference »Functions: » DateDiff Function »Statements

Arithmetic and String Operators +, -, *, /. \, ^, ( ) String Concatenation: &, +

Arithmetic Operators +, -, *, /, ^, ( ) Evaluating an expression –Examples: – * 3 3 – 4 / 2 8 / 4 * 2 2 * 3 ^ 2 (2 * 3) + 2 ^ 3

Order of Evaluation OperatorMultiples 1 ( )Inner to outer, left to right 2. ^left to right 3. *, /left to right 4. +, -left to right

Formula to Expression

Example: Create a form to compute the future value FutureValue = PresentValue x (1+intRate) Years

Variable Scope Block-level scope: declared within a block of code terminated by an end, loop or next statement. –If city = “Rome” then Dim message as string = “the city is in Italy” MessageBox.Show(message) –End if Procedural-level scope: declared in a procedure Class-level, module-level scope: declared in a class or module but outside any procedure with either Dim or Private keyword. Project-level scope: a module variable declared with the Public keyword.