ITP 150 Week 4 Variables. ITP 150 - Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor.

Slides:



Advertisements
Similar presentations
Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
Advertisements

Working with Intrinsic Controls and ActiveX Controls
Tutorial 31 Variable Memory location whose value can change as the program is running. Used to hold temporary information Used to control the type of data.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
VARIABLES: Your Own Piece of the ram. Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation.
Introduction to the C# Programming Language for the VB Programmer.
VBA Modules, Functions, Variables, and Constants
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Visual Basic Project 2 IDS 306 Spring 1999 V. Murphy.
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
Modeling using VBA. Using Toolbox This is a label This is a button Using the Toolbox select a GUI element and by mouse-click place it on the frame This.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
1 Pertemuan 03 Representing Data Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
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 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Why to Create a Procedure
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Lecture 8 Visual Basic (2).
Date Variables Visual Basic for Applications 5. Objectives n In this tutorial, you will learn how to: n Reserve a Date variable n Use an assignment statement.
Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Types of Visual Basic Data Numeric Data Non Numeric Data.
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.
Visual Basic Programming I 56:150 Information System Design.
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
BACS 287 Programming Fundamentals 5. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Procedures Built-in Functions User-defined.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
Variables in VB. What is a variable? ► A named memory location that stores a value.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Making Interactive Programs with Visual Basic .NET
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.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 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.
Programming Right from the Start with Visual Basic .NET 1/e
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic 6 (VB6) Data Types, And Operators
2. Understanding VB Variables
Microsoft Access Illustrated
Chapter 6 Variables What is VBScript?
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CS285 Introduction - Visual Basic
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Presentation transcript:

ITP 150 Week 4 Variables

ITP Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor BorderStyleFillStyle CaptionName EnabledVisible Move Clear SetFocusAddItem ActivateDragOverLoad ChangeGotFocusLostFocus ClickKeyDownMouseDown DblClickKeyPressMouseMove DragDropKeyUpMouseUp

ITP Lecturer: A. Borquez3 Controls for Displaying and Entering Text To provide this feature Use this control Text that can be edited by the user, for example Text box an order entry field or a password box Text that is displayed only, for example to identify Label a field on a form or display instructions to the user

Controls That Present Choices to Users To provide this feature Use this control A small set of choices from which a user can choose one or Option buttons more options. Check boxes A small set of options from which (use frames if a user can choose just one. additional groups are needed) A scrollable list of choices from which the user can choose. List box A scrollable list of choices along with a text edit field. Combo box The user can either choose from the list or type a choice in the edit field.

Controls That Display Pictures and Graphics To provide this featureUse this control A container for other controls.Picture box Printing or graphics methods. Picture box Displaying a picture. Image control or picture box Displaying a simple graphical element Shape or line control

ITP Lecturer: A. Borquez6 Managing Forms

ITP Lecturer: A. Borquez7 Variables  In Visual Basic, you use variables to temporarily store values during the execution of an application  Variables have a name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store)  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]

ITP Lecturer: A. Borquez8 Variable rules…...  Must begin with a letter.  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.

ITP Lecturer: A. Borquez9 Visual Basic Variables Variables: temporarily store values during the execution of an application. Variables have a: name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store). Variables can be used in many ways, including:  As a counter that stores the number of times a procedure or code block executes.  As a temporary storage for property values.  As a place to hold a value returned from a function.  As a place to store directory or file names.

ITP Lecturer: A. Borquez10 Other Variable issues to think about….  Implicit vs. Explicit Declarations  Declaring a variable in the Declarations section of a form, standard, or class module, rather than within a procedure, makes the variable available to all the procedures in the module.  Declaring a variable using the Public keyword makes it available throughout your application.  Declaring a local variable using the Static keyword preserves its value even when a procedure ends.

ITP Lecturer: A. Borquez11 Variable Data Types Data typeStorage size Byte1 byte Boolean2 bytes Integer2 bytes Long (long integer)4 bytes Single (single floating-point)4 bytes Double(double floating-point)8 bytes Currency (scaled integer)8 bytes Date8 bytes Object4 bytes + size of object String (variable-length)10 bytes + string length String (fixed-length)length of string Variant16 bytes Data typeStorage size Byte1 byte Boolean2 bytes Integer2 bytes Long (long integer)4 bytes Single (single floating-point)4 bytes Double(double floating-point)8 bytes Currency (scaled integer)8 bytes Date8 bytes Object4 bytes + size of object String (variable-length)10 bytes + string length String (fixed-length)length of string Variant16 bytes

ITP Lecturer: A. Borquez12 Variable Data Types Naming Conventions Data typePrefix Bytebyt Booleanbln Integerint Longlng Singlesng Doubledbl Currencycur Datedtm Objectobj Stringstr Variantvar Data typePrefix Bytebyt Booleanbln Integerint Longlng Singlesng Doubledbl Currencycur Datedtm Objectobj Stringstr Variantvar

Understanding the Scope of Variables Scope Private Public Procedure-level Variables are private to Not applicable. You the procedure in which cannot declare public they appear. variables within a procedure. Module-level Variables are private toVariables are available the module in which to all modules. they appear.

ITP Lecturer: A. Borquez14 Introduction to Procedures There are two major benefits of programming with procedures:  Procedures allow you to break your programs into discrete logical units, each of which you can debug more easily than an entire program without procedures.  Procedures used in one program can act as building blocks for other programs, usually with little or no modification.

ITP Lecturer: A. Borquez15 Working with Date and Time Dim dtNewDate As Date dtNewDate = dtDate + 5 MsgBox "The current date and time is " & Now() MsgBox "The date is " & Date() MsgBox "The time is " & Time() Now, Date, and Time functions

ITP Lecturer: A. Borquez16 VB Date/Time Functions FunctionExample Value displayed Year()Year(Now) 1999 Month()Month(Now) 2 Day()Day(Now) 22 Weekday()Weekday(Now) 7 Hour()Hour(Now) 11 Minute()Minute(Now) 38 Second()Second(Now) 9

The DateDiff Function The DateDiff function returns the number of time intervals between two dates. DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]]) Dim dtTheDate As Date Dim strMsg As String dtTheDate = InputBox("Enter a date") strMsg = "Days from today: " & DateDiff("d", Now, dtTheDate) MsgBox strMsg

VB Format Function the Format function accepts a numeric value and converts it to a string Format syntaxResult Format(Now, “m/d/yy”)1/27/99 Format(Now, “dddd, mmmm dd, yyyy”)Wednesday, January 27, 1999 Format(Now, “d-mmm”)27-Jan Format(Now, “mmmm-yy”)January-99 Format(Now, “hh:mm AM/PM”)07:18 AM Format(Now, “h:mm:ss a/p”)7:18:00 a Format(Now, “d-mmmm h:mm”)3-January 7:18 txtDate.Text = Format(Now, "Long Date") txtCost.Text = Format(1000, "Currency") Using Named Formats

ITP Lecturer: A. Borquez19 Sub Procedures vs. Function Procedures  Sub procedures do not return a value.  Function procedures return a value.  Sub procedures do not return a value.  Function procedures return a value.

ITP Lecturer: A. Borquez20 A Closer Look at Sub_Procedures... A Sub procedure is a block of code that is executed in response to an event. By breaking the code in a module into Sub procedures, it becomes much easier to find or modify the code in your application. A Sub procedure is a block of code that is executed in response to an event. By breaking the code in a module into Sub procedures, it becomes much easier to find or modify the code in your application. [Private|Public][Static]Sub procedurename (arguments) statements Each time the procedure is called, the statements between Sub and End Sub are executed. Sub procedures can be placed in standard modules, class modules, and form modules. Sub procedures are by default Public in all modules Each time the procedure is called, the statements between Sub and End Sub are executed. Sub procedures can be placed in standard modules, class modules, and form modules. Sub procedures are by default Public in all modules

A Closer Look at Functions…. Visual Basic includes built-in, or intrinsic functions, like Sqr, Val, or Chr. You can use the Function statement to write your own Function procedures. Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. Function procedures have data types, just as variables do. You return a value by assigning it to the procedurename itself. [Private|Public][Static]Function procedurename (arguments) [As type] statements