Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

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.
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
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.
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
Chapter 8: String Manipulation
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Chapter 3: Using Variables and Constants
CS0004: Introduction to Programming Variables – Numbers.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Variables "There are 10 kinds of people in the world today – those who understand binary and those who don't!” Unknown.
Class 2 Remote Instruction Introduction to Variables EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure your.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
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.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits.
Class 3 Remote Instruction Computer Math EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure your volume is.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Pay Example (PFirst98) Please use speaker notes for additional information!
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Lesson 4 Mathematical Operators! October 6, 2009.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
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.
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.
Variables Continued In the last session we saw how variables are objects that allow us to store values in the RAM of the computer In this session we shall.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Visual Basic A Quick Tutorial VB Review for ACS 367.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
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.
© 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.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Objects Allow us to represent and control the computer technology Use methods to make the object do something Use properties to find out and change the.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Visual Basic Variables
Working with Forms in Visual Basic
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
Numbers.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
CHAPTER FOUR VARIABLES AND CONSTANTS
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Data Types and Variables

Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures

Visual Basic supports the following data types: Data TypeRange Whole Number: Integer-32,768 to 32,767 Long-2,147,483,648 to 2,147,483,647 Decimal Number: Single-3,402823E+38 to 3,402823E+38 Double-1, E+308 to 1, E+308

Data TypeRange Other Types: String1 to about 65,000 characters DateJanuary 1, 100 to December 31, 9999 BooleanTrue or False

Variable! Definition: Memory locations where temporary data is stored.

Facts about Variables. Variables are a common feature of programming languages. Variables can be used to store and manipulate all kinds of data. Variables get their name from the fact that the value can vary as the program runs. You can assign values to variables using the assignment operator. (=) You should declare variables before you use them.

Declaring Variables The first step to using a variable in your program is to: 1. Let the compiler know that you want to set up a memory location as a variable. 2. What you want to call the variable. 3. What data type you want the variable to have. The above process is called declaring a variable!

Example: To declare a variable, use the Dim statement as show below. Dim VariableName As DataType The following declare a variable named intAnswer with the Integer data type. Dim intAnswer As Integer

Rules for Naming Variables! When naming variables, keep the following rules in mind. 1. Variable names must begin with an alphabetic character ( a letter). 2. Following the first character, letters, numbers, and the underscore (_) are allowed. 3. Variable names cannot include any spaces. 4. Variable names can be up to 255 character long.

Using the Prefix Rule! PrefixData TypeExample intIntegerintPeople lngLonglngInches sngSinglesngWeight dblDoubledblMass strStringstrName dteDatedteAnniversary blnBooleanblnSold

Example Program: Open VB and create a new form the looks like the following:

Add 5 labels. Set the name properties to the following: Label1 should be lblAgeYears Label2 should be lblMonths Label3 should be lblYou Label4 should be lblOutputMonths Label5 should be lblAgeMonths

Set the Name property of the form to frmMonths and the caption to Month Converter. Set the captions of the five labels to: Age in years: Months since last birthday You are X months old.

Add two text boxes to your form. Set the name of the text boxes to txtYears txtMonths Add one command button. Set the name of the command button to cmdMonths Set the caption to Calculate age in months

Change the properties of the following labels to false. lblYou, lblOutputMonths, lblAgemonths Double-click the Calculate age in months button. Key Dim intMonths As Integer at the top of the event procedure and press the Enter key twice.

Enter the following: 'Calculate Months intMonths = (Val(txtYears.Text) * 12) + _ Val(txtMonths.Text) 'Display Number of Months Old lblOutputMonths.Caption = intMonths lblYou.Visible = True lblOutputMonths.Visible = True lblAgemonths.Visible = True

Run and fix your errors. Enter 5 in the Age in years text box. Enter 4 in the Months since last birthday text box. Click the Calculate age in months button. What is your output?

Summary Data can be in the form of numbers, text, dates, pictures, and even sound. Visual Basic supports a set of data types. There are data types for whole numbers, floating point numbers (decimals), text, dates, and more. You can choose to store data in memory locations called variables.

Summary The first step to using a variable is to declare it using the Dim statement. When naming variables, keep the naming rules in mind. It is also a good idea to use naming prefixes to identify the data type of the variable. You should declare variables before you use them. You can assign values to variables using the assignment operator (=).

Homework: Answer the following questions: 1. What is the DIM statement used for? 2. What are the two common integer data types? 3. What are the two common decimal data types? 4. Write Visual Basic code to declare a String variable called strFirstName.