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.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Chapter 3: Using Variables and Constants
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Variables / Scope. Variable Memory location whose value can change as the program is running. Used to hold temporary information Used to control the type.
1.
String Variables Visual Basic for Applications 4.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
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.
CIS 115 Lecture 5.  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can be referred.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Chapter 8: String Manipulation
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter 4: The Selection Structure
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
1 JavaScript in Context. Server-Side Programming.
Input, Output, and Processing
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Items in Visual Basic programs
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
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.
# 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)
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
CHAPTER THREE Representing Data: Constants and Variables.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
Introduction to Computer CC111 Week 09 Visual Basic 2 Visual Basic Variables 1.
Chapter 1: An Introduction to Visual Basic .NET
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 3: Using Variables and Constants
Working with Forms in Visual Basic
2. Understanding VB Variables
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Variables and Arithmetic Operations
Microsoft Visual Basic 2005 BASICS
WEB PROGRAMMING JavaScript.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
CHAPTER FOUR VARIABLES AND CONSTANTS
Introduction to Programming
Presentation transcript:

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 used in calculations Val returns a Double-type, which is often larger than necessary Can store only one piece of data at any time Data is processed faster

Tutorial 32 Data Types Byte Boolean Currency Date Double Integer Long Object Single String Variant

Tutorial 33 Use the Appropriate Data Type Integer or Long - Used to store whole numbers Single, Double, Currency - Used to store numbers with a decimal fraction String - Used to store strings Boolean - Used to store Boolean values (True and False) Date - Used to store date and time information Object - Used to store a reference to an object Byte - Used to store binary data Variant - Flexible, but not efficient

Tutorial 34 Variable Names Should be meaningful First three characters should represent the data type Remainder of name should represent the variable’s purpose

Tutorial 35 Three-character Ids Byte byt Booleanbln Currency cur Date/Time dtm Doubledbl Integerint Longlng Objectobj Singlesng Stringstr Variantvnt

Tutorial 36 Rules for Naming Variables Name must begin with a letter Name can contain only letters, numbers, and the underscore. No punctuation characters or spaces are allowed Name cannot exceeds 255 characters Name cannot be a reserved word

Tutorial 37 Creating (declaring) a Variable Dim variablename [As datatype] Public variablename [As datatype]

Tutorial 38 Assigning Values to Variables Assignment statement variablename = value Examples: sngHours = 38.5 curBonus = curSales *.1 strName = “Susan”

Tutorial 39 Constants Literal constant an item of data whose value cannot change while the program is running Examples: 7 “Janet” Symbolic constant a memory location whose contents cannot be changed while the program is running Examples: conPi conRate

Tutorial 310 Scope of a Variable Indicates which procedures can use the variable Determined by where the Dim or Public statement is entered Can be either global, form-level, or local

Tutorial 311 Local Variables Created with the Dim statement The Dim statement is entered in an object’s event procedure Only the procedure in which it is declared can use the variable Removed from memory when the procedure ends

Tutorial 312 Form-level Variables Created with the Dim statement The Dim statement is entered in a form’s General declarations section Can be used by any of the procedures in the form Removed from memory when the application ends

Tutorial 313 Global Variables Created with the Public statement The Public statement is entered in a code module’s General declarations section Used in multi-form projects and can be used by any of the procedures in any of the project’s forms Removed from memory when the application ends

Tutorial 314 Option Explicit Statement Doesn’t allow you to create variables “on the fly” Enter in every form’s, and every code module’s, General declarations section Use Tools, Options, Environment tab, Require Variable Declaration to have Visual Basic include Option Explicit in every new form and module

Tutorial 315 Creating a Symbolic Constant A memory location whose value cannot change during run time Syntax: [Public] Const constname [As datatype] = expression Examples: Const conPi As Single = Public Const conMaxAge as Integer = 65

Tutorial 316 Scope of a Symbolic Constant Indicates which procedures can use the symbolic constant Global: Public Const statement in a code module’s General declarations section Form-level: Const statement in the form’s General declarations section Local: Const statement in an event procedure

Tutorial 317 String Concatenation Ampersand - & Examples: (Assume strFirstName contains “Mary” and sngSales contains 1000) “Hello “ & strFirstName strFirstName & “ sold $“ & sngSales & “.” Results: Hello Mary Mary sold $1000

Tutorial 318 InputBox function Displays one of Visual Basic’s predefined dialog boxes Contains a message, along with an OK button, a Cancel button, and an input area Syntax: InputBox(prompt, title) Use sentence capitalization for the prompt, and book title capitalization for the title Has limitations: can’t control appearance and allows user to enter only one piece of data

Tutorial 319 Newline Character Chr(13) & Chr(10) - issues a carriage return followed by a line feed vbNewLine - one of Visual Basic’s intrinsic constant An intrinsic constant is one that is built into the Visual Basic language

Tutorial 320 Object Browser Dialog box that provides information about objects available to your application The Object Browser lists properties, methods, events, and intrinsic constants

Tutorial 321 Default Command Button Can be selected by pressing the Enter key even when the button does not have the focus Set the button’s Default property to True Only one command button can be the default If used, it is typically the first button If a button’s action is destructive and irreversible, then it should not be the default button

Tutorial 322 InputBox Function Has the following limitations: Can’t control its appearance Allows the user to enter only one piece of data Used for RAD (rapid application development] In the final project, InputBox functions are typically replaced with professional-looking dialog boxes

Tutorial 323 Multi-form Projects Only one form, called the startup form, is automatically loaded and displayed You must include code to load/display the other forms in the project Use the Project menu, Properties, Startup Object list to specify the startup form

Tutorial 324 Loading and Displaying a Form Visual Basic has two statements and two methods that control the loading and displaying of forms Load statement Unload statement Hide method Show method

Tutorial 325 Load and Unload Statements Load statement brings a form into memory, but does not display the form on the screen Syntax: Load object Unload statement removes a form from both memory and the screen Syntax Unload object

Tutorial 326 Show and Hide Methods Show method displays a form on the screen; loads the form if it is not already in memory Syntax: object.Show [style], where style, which is optional, can be either 0 or 1 Hide method removes a form from the screen, but leaves it in memory Syntax: object.Hide

Tutorial 327 Style 0 or omitted means that the form is modeless Example: MSDN Library window 1 means that the form is modal Example: Visual Basic’s Open Project dialog box

Tutorial 328 Standard Windows Dialog Box Created from a form Centered on the screen Not resizable Contains only a Close button Set the form’s BorderStyle property to 3-Fixed Dialog

Tutorial 329 Centering Instructions formname.Top = (Screen.Height - formname.Height)/2 formname.Left = (Screen.Width - formname.Width)/2 Top, Left, Height, and Width properties are measured in twips One twip is 1/1440 of an inch.

Tutorial 330 Timer Control Processes code at regular intervals Interval property Measured in milliseconds A millisecond is 1/1000 of a second Timer event Contains the code that will be processed when each interval has elapsed

Tutorial 331 Removing a Coded Control Remove all of the control’s code before removing the control Unassociated code remains in the application Look in the form’s General declarations section to verify that the application does not contain any unassociated code

Tutorial 332 Appearance of the Mouse Pointer Controlled by the object’s MousePointer property Use either an hourglass or an arrow/hourglass to indicate that the application is busy The hourglass indicates that the mouse pointer is temporarily inactive, whereas the arrow/hourglass indicates that the mouse pointer still can be used in the current application

Tutorial 333 Debugging Technique Always enter the Option Explicit statement in the General declarations of every form and module If your application uses the InputBox function, test your application to see how it handles the various InputBox responses When using the Val function, remember that Visual Basic must be able to interpret the string expression as a numeric value