Visual Basic Programming I 56:150 Information System Design.

Slides:



Advertisements
Similar presentations
ISOM3230 Business Applications Programming
Advertisements

Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Introduction to the C# Programming Language for the VB Programmer.
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
VBA Modules, Functions, Variables, and Constants
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
ITP 150 Week 4 Variables. ITP Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
IE 212: Computational Methods for Industrial Engineering
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
Lecture 8 Visual Basic (2).
Lecture Set 5 Control Structures Part A - Decisions Structures.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
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.
Types of Visual Basic Data Numeric Data Non Numeric Data.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Programming with Microsoft Visual Basic th Edition
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
Introduction to Programming Lecture 2 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.
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.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
By “FlyingBono” 2009_02By FlyingBono.  ASP code is embedded in HTML using tags.  A ASP scripting block always starts with.  Server scripts are executed.
Programming Right from the Start with Visual Basic .NET 1/e
Introduction to Programming Lecture 2
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
Visual Basic 6 (VB6) Data Types, And Operators
2. Understanding VB Variables
Chapter 19 JavaScript.
Making Decisions in a Program
Chapter 6 Variables What is VBScript?
Chapter 3: Introduction to Problem Solving and Control Statements
CIS16 Application Development Programming with Visual Basic
Microsoft Visual Basic 2005: Reloaded Second Edition
Quick Test Professional Training Part 1
Chapter 3 Programming Fundamentals
Introduction to Computer Programming IT-104
Presentation transcript:

Visual Basic Programming I 56:150 Information System Design

Introduction Visual Basic has evolved from the original BASIC language and now contains several hundred statements, functions, and keywords, many of which relate directly to the Windows GUI The Visual Basic programming system, Applications Edition included in Microsoft Excel, Microsoft Access, and many other Windows applications uses the same language. The investment you make in learning Visual Basic will carry over to these other areas.

Data Type Byte1-byte (0-255) Boolean2-byte (True or False) Integer 2-byte ( -32,768 to 32767) Long4-byte ( -2,147,483,648 to 2,147,483,647) Date8-byte (Jan. 1, 100 to Dec. 31, 9999) String0 – bytes

Data Type Single4-byte (Single-precision floating-point value) Double8-byte (Double-precision floating-point value) Currency8-byte (Currency value) DecimalDecimal value Variant capable of storing all system-defined types of data Variant data can contain a special value “Null” object types

Declare Variables To declare a variable is to tell the program about it in advance. You declare a variable with the Dim statement, supplying a name for the variable: Dim variablename [As type] if type is not specified, it will be variant. “dim” could be replaced by static, private, public for different purposes.

Variable Name: Must begin with a letter. Case Insensitive. Can't contain an embedded period or embedded type-declaration character. Must not exceed 255 characters. Must be unique within the same scope, which is the range from which the variable can be referenced — a procedure, a form, and so on.

Implicit vs. Explicit Declaration Function SafeSqr(num) TempVal = Abs(num) SafeSqr = Sqr(TempVal) End Function What if you write the second Tempval as Temval mistakenly? Option Explicit

Scope of Variables ScopePrivatePublic Procedure- level Variables are private to the procedure in which they appear. Not applicable Module- level Variables are private to the module in which they appear. Variables are available to all modules.

Constants [Public|Private] Const constantname[As type] = expression Const conPi = Const conMaxPlanets As Integer = 9 Const conPi = 3.14, conMaxPlanets = 9, _ conWorldPop = 6E+09 Const conPi2 = conPi * 2

Define fixed-size array Follow the array name by the upper bound in parenthesis. The default lower bound is 0. Dim Sums(20) As Double Public Counters(14) As Integer The lower and upper bound can both be determined Dim Sums(100 To 120) As String

Dynamic Array Dim DynArray() ReDim Matrix1(19, 29) ’multidimensional ’array A dynamic array can be resized at any time. “Preserve” can be used to keep the contents while enlarging a dynamic array. (ReDim Preserve arrayname(dimensions)

Operators Arithmetic operators +, –, *, /, mod \ integer division operator ^Exponent operator Comparison Operators =,, >, = is result = obj1 is obj2

Operators Logical operators Not, And, Or, Xor Concatenation operators & To connect two strings. Debug. Print “This” & “is” & “a” & “test”

Other Symbols ’ to make comments _ to continue a line.

Decision Structure If…Then If condition Then statement If condition Then statements End If

Decision Structure If…Then…Else If condition1 Then [statementblock-1] [ElseIf condition2 Then [statementblock-2]]... [Else [statementblock-n]] End If

Decision Structure Select Case Select Case testExpression [Case expressionlist1 [statementblock-1]] [Case expressionlist2 [statementblock-2]]. [Case Else [statementblock-n]] End Select Case else is optional

Loop Structure Do...Loop Do (While | Until) condition statements Loop Do statements Loop (While | Until) condition

Loop Structure For...Next For counter = start To end [Step increment] statements Next [counter]

Sub Procedure A Sub procedure is a block of code that is executed in response to an event. [Private|Public][Static] Sub procedurename (arguments) statements End Sub The arguments for a procedure are like a variable declaration, declaring values that are passed in from the calling procedure.

Function Procedure Unlike a Sub procedure, a Function procedure can return a value to the calling procedure [Private|Public][Static]Function procedurename (arguments) [As type] statements End Function

Function Procedure Function procedures have data types, just as variables do. This determines the type of the return value. Return a value by assigning it to the procedurename itself. Function Hypotenuse (A As Integer, B As _ Integer) As String Hypotenuse = Sqr(A ^ 2 + B ^ 2) End Function

Passing arguments by value Only a copy of a variable is passed when an argument is passed by value. If the procedure changes the value, the change affects only the copy and not the variable itself. Use the ByVal keyword to indicate an argument passed by value. Sub PostAccounts(ByVal intAcctNum as Integer) statements End Sub

Passing arguments by reference the variable's value can be permanently changed by the procedure to which it is passed. Passing by reference is the default in Visual Basic.

References