Visual Basic IITG to be expanded. What is Visual Basic? Object Oriented Programming Language (OOP) Graphical User Interface (GUI) Event Driven – Write.

Slides:



Advertisements
Similar presentations
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Introduction to the C# Programming Language for the VB Programmer.
1.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
JavaScript, Third Edition
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
VB .NET Programming Fundamentals
5.05 Apply Looping Structures
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter 4: The Selection Structure
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
CS0004: Introduction to Programming Variables – Strings.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Outline Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA)
Chapter 2: Using Data.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
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.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CPS120: Introduction to Computer Science Operations Lecture 9.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors.
Applications Development
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
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.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic th Edition
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Controlling Program Flow with Decision Structures.
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.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
VISUAL BASIC 6.0 Designed by Mrinal Kanti Nath.
A variable is a name for a value stored in memory.
Visual Basic 6 (VB6) Data Types, And Operators
Variables and Arithmetic Operations
Lecture Set 4 Data Types and Variables
Variables and Arithmetic Operations
Chapter 8 JavaScript: Control Statements, Part 2
CIS16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Presentation transcript:

Visual Basic IITG to be expanded

What is Visual Basic? Object Oriented Programming Language (OOP) Graphical User Interface (GUI) Event Driven – Write code for events you care about

Objects Properties – Characteristics i.e. Color, size, etc. Events – User’s actions Methods – What object does – Always has parenthesis Ex: Object.Method() Based on a class – Template Declared like a variable Use (.) to access properties and variables – Ex: employee.salary = 100

Class Contains definitions of: – Properties – Methods – Events Creating class – Public Class name declare variables as Private or Public Property propertyName() As datatype End Property End Class

Procedures Reusable code Can be called from anywhere in the code Sub Procedure – Performs a task Event-handling – Executes in response to user event or occurrence in program Function Procedure – Returns a value Property Procedure – Return and assign values of properties

Data Types Some basic data types – Boolean – Character – Integer – Long – Double (double precision floating-point) – Decimal – String – Object

Converting Between Numeric Data Types Implicit – Automatic conversion – Narrower to wider data type Explicit – Casting – Done manually within the code – Uses To method

Variables Use Dim (dimensional) at the beginning Declare data type with “As” then data type after variable – Ex: Dim aNumber As Integer Declare multiple variables with commas (,) – Ex: Dim a, b, c As Integer

Constants Use Const (constant) at the beginning Constant variable in uppercase Declarations similar to other variables – Ex: Const TAX_RATE As Double Used for set variables and cannot be changed

Arithmetic Operators Addition ( + ) Subtraction ( - ) Multiplication ( * ) Division ( / ) Exponentiation ( ^ ) Integer Division ( \ ) Modulus (MOD)

Comparison Operators Equality ( = ) Inequality ( <> ) Less than ( < ) Greater than ( > ) Less than or equal to ( <= ) Greater than or equal to ( >= ) These operators can be used for numbers or strings

Concatenation Can combine multiple strings Use “&” or the “+” operator Put parentheses around strings – Ex: Dim x As String = “abc” + “def” + “ghi” Dim y As String = “jkl” & “mno” & “pqr” Can also combine string variables – Ex: Dim a As String = “stu” Dim b As String = “vwx” Dim z As String = a + b Dim w As String = a & b

Logical Operators Negation (Not) Conjunction (And) Disjunction (Or) Exclusion (Xor) – Evaluates to False if both values are the same Short-Circuit Conjunction (AndAlso) – If first value is evaluated to false, then second value is skipped and whole expression is false Short-Circuit Disjunction (orElse) – If first value is evaluated to true, then second value is skipped and whole expression is true

Interface Design Text Box – Allows for user input such as numbers, strings or characters Group Box – Containers for other controls – Improves readability – Place group box in the form first then put controls inside Check Box – Select/deselect one or more item in a group Radio Buttion – Select only one in a group Picture Box – Contains and displays a picture

Converting Strings to Numbers Needed when using values from text properties User data inputted as strings Must be converted to use in calculations Use Parse methods – Data type then dot (.) then Parse with object and data type in parentheses – Ex: Integer.Parse(quantityTextBox.Text)

Converting to Strings and Displaying Numbers Must convert to string to display in text box All values outputted as strings Use ToString method – Ex: result = sum.ToString() Parenthesis are optional – To output to screen use: textBoxName.Text = stringVariable Ex: resultTextBox.Text = result

Loops For…Next loops – Executes for a specific number of iterations Dim counter As Integer For counter = startingValue to endingValue Step 1 If counter = 5 Then Exit For messagebox.Show(“Counter = “ + CStr(counter)) Next counter – Step only necessary when counting by something other than 1 – If statement needed for early exit of For loop

Loops (continued) For Each…Next loops – Similar to For…Next loops – Executes for each element in an array – For Each element As datatype in arrayName Statement Next element “As datatype” is optional element in “Next element” is optional

Loops (continued) While loops – Uses true/false condition – Used when unsure of number of iterations – Dim Number As Integer = 10 While Number > 6 Number = Number – 1 End While Terminating statement is needed

Loops (continued) Do…Loop – Similar to While loops – Do While Number > 6 Number = Number - 1 Loop

If…Then…Else Make decision based on Boolean decision If condition Then statements Else statements End If

Select…Case Used when comparing expression to several different values Evaluates expression once and uses it for every comparison Dim number As Integer = 6 Select Case number Case 1 statement Case 2 statement Case 3, 4 statement Case 5 To 8 statement Case Else‘Optional statement End Select

Handling Exceptions Run-time errors Uses Try/Catch statements – Finally is optional Example: – Try statement of possible error Catch [VariableName As ExceptionType] action for exception [Finally code that executes with or without error] End Try

Handling Exceptions (Continued) Last Catch statement should be generic Use with statements that may cause error If there is an exception while in Try block, control is transferred to Catch block Exceptions are instances of exception class Multiple Catch statements Nested Try/Catch statements

With Statement Used to address multiple functions of the same object With firstNumberText.Focus().SelectAll() End With

Setting Tab Order for Controls One control always has the focus Not all controls can have the focus – i.e. labels and picture boxes Set TabStop property to true or false Set TabIndex property starting with zero

Keyboard Access Keys AKA Hot Keys User presses Alt and the underlined letter of a command – Ex: Alt + x = Exit To create a hot key, place an ampersand before the letter you wish to use in the Text property of the object – Ex: E&xit

Keyboard Access Keys (Continued) To set hot keys to labels and picture boxes: – Set TabIndex of label to one less than TabIndex of corresponding control Ex: TabIndex of First Number is 0 while TabIndex of firstNumberTextBox is 1

Creating and Writing Text Files Use FileStream class Creating/Writing a text file – Declare StreamWriter object Dim sw As StreamWriter = New _ StreamWriter("TestFile.txt") – Use write method sw.Write(“An Example”) – Close file sw.Close()

Reading from a Text File Declaring StreamReader object – Dim sr As StreamReader = New _ StreamReader("TestFile.txt") Reading file and displaying – Do line = sr.ReadLine() Console.WriteLine(Line) Loop Until line Is Nothing Close file – sr.Close()

Other Useful Info. Line continuation character – Used for long program lines – Space after last character, underscore, then enter to go onto next line – Ex: If (x<y) Or _ (x>y) Option Strict – Restricts implicit conversions to only widening conversions – Helps prevent loss of data and errors – At top of code type “Option Strict On”

Other Useful Info. (Continued) Focus method – To set focus on a particular text box – Ex: firstNumberText.Focus() SelectAll method – To select and highlight a text box – Ex: firstNumberText.SelectAll() Clear method – Used to clear text boxes – Ex: firstNumberText.Clear() End method – Used to end program – Ex: End

Review Questions What is the purpose of the Try/Catch statements? What’s special about VB? Can numbers be converted into strings and vice versa? If so, how?