Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare.

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.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
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.
1 Visual Basic Programming II Lecture 3 MIS233 Instructor – Larry Langellier.
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
VBA Modules, Functions, Variables, and Constants
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
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.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
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.
 Excel – Basic Elements  Using Macros  Excel VBA Basics  Excel VBA Advanced.
IE 212: Computational Methods for Industrial Engineering
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 05 Learning To Program.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
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 Set 5 Control Structures Part A - Decisions Structures.
ENGR 112 Decision Structures.
Types and Loops.
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.
Chapter Six: Working With Arrays in Visual Basic.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Types of Visual Basic Data Numeric Data Non Numeric Data.
Visual Basic Programming I 56:150 Information System Design.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
Programming with Microsoft Visual Basic th Edition
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
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.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
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.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
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
IE 8580 Module 4: DIY Monte Carlo Simulation
A variable is a name for a value stored in memory.
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
CIS16 Application Development Programming with Visual Basic
T. Jumana Abu Shmais – AOU - Riyadh
Fundamentals of visual basic
CIS16 Application Development and Programming using Visual Basic.net
Quick Test Professional Training Part 1
Introduction to Computer Programming IT-104
Presentation transcript:

Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare a variable with a Dim statement Dim VariableName [As DataType ] Variable declared with the Dim statement within a procedure exists only as long as the procedure is executing

Variables,Constants and Data types When the procedure is completed, the value of the variable disappears The value of the variable in a procedure is Local to that procedure A variable name –must begin with a letter –must not exceed 255 characters

Variables,Constants and Data types Data types are –Numeric data types Integer Long2,147,xxx,xxx Single 3.4*10**38 Double1.8*10**308 Currency Example Dim Amnt as Double, (Prev,Temp) as Integer Dim NameAndLName As String

Variables,Constants and Data types The String Data type –String type data type can be declared as Max length of a string variable can Dim Name As string * 24 ‘Fixed length’ Dim Adress As string ‘Variable size’

Variables,Constants and Data types The Byte Data Type If the variable contains binary data, Declare it as an array of the Byte data type. Dim Temp(1 to 100) As Byte;

Variables,Constants and Data types The Boolean Data type If you have variable that will contain true/false, or on/off information, you can declare it to be of type Boolean Dim Flag As Boolean

Variables,Constants and Data types The Variant Data type A variant is capable of storing all system- defined types of data. You don’t have to convert between these types of data. Dim SomeValue‘Variant by default ‘

Variables,Constants and Data types The Object Data type Object variables are stored as 32-bit addresses. A variable declared as Object is one that can be assigned(using the set Statement) to refer to any actual object. Dim ObjDb As Object Set ObjDb =OpenDatabase(“c:\vb5\Biblio.mdb”)

Variables,Constants and Data types Converting Data Types Visual Basic Provides several conversion functions you can use to convert values into a specified data type ConversionConverts anConversionConverts an Functionexpression toFunctionExpression to CboolBooleanCintInteger CbyteByteCLngLong CcurCurrencyCSngSingle CdateDateCStrString CDblDoubleCvarVariant

Variables,Constants and Data types There are other ways to declare variables –Declaring a variable in the declaration section of a Form, Standard module, or Class module, rather than within a procedure, makes the variable available to all the procedures in the module –Declaring a variable using Public keyword makes it available throughout your application –Declaring a variable using the Static keyword preserves its value even when a procedure ends.

Variables,Constants and Data types To avoid the problem of misnaming variables place Option explicit –in the declaration section of a class, form, or standard module –OR –From Tools(Options(Editor(RequireVariableDeclarati on))

Array Declaration Array allow you to refer to a series of variables by the same name and to use a number(an index) to tell them apart All the elements in an array have the same data type –Fixed-size arrays –Dynamic arrays(Can change at run-time)

Array Declaration Declaring Fixed size arraysUsing Dim Statement Dim Counter(20) As Integer ‘ 21 elements’ Dim Sums(100 To 120) As Double Dim Multi(3, 1 To 10, -40 To 50) As Long LBound and Ubound functions returns upper and loower limits of a given dimension For I = LBound(Multi,3) To UBound(Multi,3)

Array Declaration There are 3 ways to declara fixed size arrays –To create Public arrays, use Public statement in the declaration section of a module –To create a Module-level array, use the private statement in the declaration section of a module –To create a local array, use the Private statement in a procedure

Array Declaration Dynamic Arrays –Using either Public, Dim, Static –First declare the array declaration Dim TempArr() –Then using Redim statement Redim TempArr(X+1)

Control Structures Decision Structures Visual basic Procedures can test conditions and then, depending on the results of that test, perform different operations. If.. Then If.. Then.. Else Select Case

Control Structures If.. Then Structure If condition Then Statement If condition Then Statements endif

Control Structures If.. Then.. Else Structure If condition Then [Statementblock-1] [ElseIf condition2 Then [statement-2]] … [Else [Statemnt-n]] Endif

Control Structures Select Case statement Select Case testexpression [Case expressionlist1 [statemntblock-1]] [Case expressionlist2 [statement-2]].. Case else [statementblock-n]] end select

Control Structures Loop Structure Loop structure allow you to execute one or more lines of code repetitively –Do.. Loop –For.. Next –For Each.. Next

Control Structures Do.. Loop –Test First Condition Do [While / Until] Condition Stataments Loop

Control Structures –Test Last Condition Do Statements Loop [While/Until] condition

Control Structures For.. Next condition For Counter = start To end [Step increment] statements Next[counter]

Control Structures For Each…Next It repeats a group of statements for each element in a collection of objects or in an array instead of repeating the statement a specified number of times For Each elemen In Group statements Next [element]

Scoping Variables Depending on how it is declared, a variable is scoped as either a procedure-level or module-level

Exiting From Loops Exiting from loops Ubnormal exiting from loops –Exit For –Exit Do –Exit Sub

String Functions –Len(a) :Returns the length of a string –Mid(a1,Start,length) :returns a specified number of characters(length), from a string a1, starting position of Start. –Instr(Start,a1,a2) :Returns the first occurrences of one string(a2), within another string(a1), starting(Start) position of a2

String Functions Left(a1,a2) :Returns a specified(a2) number of characters from the left of string(a1) Right(a1,a2) :Returns a specified(a2) number of characters from the Right of string(a1) Str(a1) : Returns a string representation of a number a1

Examples Select Case Asc(userInput) Case 65 To 90 Msg = “You entered the uppercase letter” Msg=Msg&Chr(Asc(UserInput))&”.” Case 97 To 122 Msg =“You entered the lower case letter “ Msg=Msg&Chr(Asc(UserInput))&”.” Case 1, 3, 5 Msg=“You entered odd number” Case else Msg=“You did not enter a letter or a number.” End Select

Example You can use multiple expressions or ranges in each Case clause Case 1 To 4, 7 To 9, 11, 13 Case is > MaxNumber Case “everything”,”nuts” To “soup”, TestIteem

Gosub..Return Statement Branch to, and return from A subroutine within a procedure Sub Form_Click() Dim Num Num = InputBox(“Type A Number”) Gosub Routine Goto NextPart Routine: Num = Num / 2 Return NextPart : MsgBox “Half Of Your Number is “ & Num End Sub

Examples For I = 1 To 10 For j = 1 to 10 … Next j Next I Nl = Chr(13) & Chr(10) For Rep = 5 To 1 Step - 1 For I = Asc(“A”) To Asc(“Z”) Msg = Msg & Chr(I) Next i Msg = Msg & Nl Next Rep MsgBox Msg