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.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
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.
Introduction to VBA Programming. Many Types of Statements VBA statements Access object model’s methods and properties Data Access Object’s methods and.
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.
Multiple Forms & Procedures. Form Methods: –Show, Hide, Activate, Close Events: –Load, Activated, Closing, Closed.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
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.
Variables and Constants
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
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Why to Create a Procedure
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.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
VB.Net Introduction. What is programming? Writing computer programs means writing instructions in a logical sequence, that will make the computer follow.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
C# Introduction ISYS 350. Visual Studio 2013 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Applications Development
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.
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.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
VB.Net Introduction. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# /VB/Other language.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
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.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
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.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
C# Introduction ISYS 350.
A variable is a name for a value stored in memory.
IS 350 Application Structure
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Introduction to VBA Programming
C# Introduction ISYS 350.
C# Introduction ISYS 350.
2. Understanding VB Variables
C# Introduction ISYS 350.
C# Introduction ISYS 350.
Variables and Arithmetic Operations
C# Introduction ISYS 350.
Introduction to VBA Programming
C# Introduction ISYS 350.
C# Introduction ISYS 350.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
C# Introduction ISYS 350.
VB.Net Introduction.
C# Introduction ISYS 350.
Presentation transcript:

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. –Programming in the.NET Framework means making use of the classes exposed by the Framework, building your own classes on top of these and manipulating the resulting objects. Creating Internet applications and Windows applications

VB.NET is Object-Oriented Everything from the simplest data types provided by VB to the complex windows is a class. –Ex: Dim iNum as Integer iNum=10 Debug.WriteLine (“The number is: “ & iNum.ToString)

Visual Studio.NET It is the development environment for creating applications based on the.NET Framework. It supports VB.Net, J#, C#, and C++. Demo: –Start page: MyProfile –Starting project: Project types, name and location, –Solutions and projects, renaming a project, property page, AutoHide, Dock/Float –Configure start up environment: Tools/Option –View/Solution, View/Class, Project/Add Windows Form, Project/Add New Item –Form, Code view, File Properties and Object properties

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 control has a number of events that it can respond to. Typical events include clicking a mouse button, type a character on the keyboard, changing a value, etc. –Event procedure

Form Properties: –Name, FormBorder, Text, BackColor, BackImage, Opacity Events: –Load, Closed Rename a form (hard to rename): –Change the name and text property. –Rename the form in the Solution Explorer. –Change the name in the code window. –Change the StartUp in the Project Property.

Typical VB.Net Controls TextBox Label Button CheckBox RadioButton ListBox ComboBox PictureBox

Text Box Properties: –AutoSize, BorderStyle, CauseValidation, Enabled, Locked, Multiline, PasswordChar, ReadOnly, ScrollBar, TabIndex, Text, Visible, etc. Properties can be set at the design time or at the run time using code. To refer to a property: –ControlName.PropertyName –Ex. 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 Num1 Num2 Sum =.Control properties.Event: Click, MouseMove, FormLoad, etc..Event procedures Sum: textBox3.text=CStr(CDbl(textBox1.text)+CDbl(textBox2.text)) Or (CDbl(textBox1.text)+CDbl(textBox2.text)).toString.Challenge: How to draw a horizontal line?.Demo: Text alignment

VB Projects A VB project consists of several files. Visual Studio.Net automatically creates a project folder to keep all project files in the folder. –Solution file –Project file –Form file –Modules –Class file –Etc.

Configure VB Project Project property page –General – Build: Option Explicit – Imports

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 =

Variable Default Value Variables with a numeric data type: 0 Boolean variables: False Date variables: 12:00:00 AM, January 1 of the year 1. String variables: Nothing

Object Reference Declare object variales: –Dim varName As Classname –varName = New Classname() –Or: Dim varName As New Classname() Dereferencing objects: –varName = Nothing

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” MsgBox(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.

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 to Christmas –Date data type properties and methods

Arithmetic and String Operators +, -, *, /. \, ^ String Concatenation: &, + Compound operator: : X= X+1 or X +=1

IF Statement IF condition THEN statements [ELSEIF condition-n THEN [elseifstatements] [ELSE [elsestatements]]] End If

Select Case Structure SELECT CASE testexpression [CASE expressionlist-n [Statements] [CASE ELSE [elsestatements] END SELECT

Select Case Example SELECT CASE temperature CASE <40 Text1.text=“cold” CASE < 60 Text1.text=“cool” CASE 60 to 80 Text1.text=“warm” CASE ELSE Text1.text=“Hot” End Select

Loop FOR index – start TO end [STEP step] [statements] [EXIT FOR] NEXT index DO [{WHILE| UNTIL} condition] [statements] [EXIT DO] LOOP

Do While/Do Until Private Sub Command1_Click() Dim counter As Integer counter = 0 Do While counter <= 5 Debug.write(counter) counter = counter + 1 Loop Text1.Text = counter End Sub Private Sub Command2_Click() Dim counter As Integer counter = 0 Do Until counter > 5 Debug.write(counter) counter = counter + 1 Loop Text1.Text = counter End Sub

With … End With With TextBox1.Height = 250.Width = 600.Text = “Hello” End With Convenient shorthand to execute a series of statements on a single object. Within the block, the reference to the object is implicit and need not be written.

Procedures. Sub procedure: Sub SubName(Arguments) … End Sub –To call a sub procedure SUB1 CALL SUB1(Argument1, Argument2, …)

Function Private Function tax(salary) As Double tax = salary * 0.1 End Function –Or Private Function tax(salary) Return salary * 0.1 End Function

Call by Reference Call by Value ByRef –The address of the item is passed. Any changes made to the passing variable are made to the variable itself. ByVal –Default –Only the variable’s value is passed.

ByRef, ByVal example Private Sub Button1_Click() Dim myStr As String myStr = TextBox1.Text Call ChangeTextRef (myStr) TextBox1.Text = myStr End Sub Private Sub ChangeTextRef(ByRef strInput As String) strInput = "New Text" End Sub