User-Defined Data Types

Slides:



Advertisements
Similar presentations
ICDL Software Applications - Database Concepts. Unit 6 Data and Data Representation Database Concepts –File Structure –Relationships Database Design –Data.
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
VBA for MS Excel Hamze Msheik. Open the Visual Basic Editor in Excel 2007 Click on the Microsoft Office button in the top left of the Excel window and.
VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
Variables and Constants
VBA Modules, Functions, Variables, and Constants
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
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 Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
Chapter 9 Random Access Files.
Manipulating Strings.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
CS0004: Introduction to Programming Variables – Numbers.
Object Variables Visual Basic for Applications 3.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Copyright © 2001 by Wiley. All rights reserved. Chapter 12: Programmer- Defined Types, Direct Access Files, and Object Classes Programmer Defined Data.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter four selected exercises with solutions. 4.2.
Database Management School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 16, Monday 12/09/2002)
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
MIS 216 Exam1 Review Spring What to expect Questions like those on the home works and on the quizzes Evaluate code Create code Multiple choice and.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (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.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
CSIT 208, Section Instructor: P eter C hen Introduction to Programming with QBasic to Visual Basic Lecture 9.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
User Defined Data Types The Type Statement. Creating Your Own Data Types You can combine variables of several different types to create user-defined types.
Chapter six exercises
Programming with Microsoft Visual Basic th Edition
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.
BACS 287 File-Based Programming. BACS 287 Data Hierarchy  Database - Collection of files, relationships, integrity information, etc  Files - All records.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
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.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
Representing Data: Constants and Variables
Unit 2 Technology Systems
Stack and Heap Memory Stack resident variables include:
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
Variables Mr. Crone.
Chapter 7 Arrays.
2. Understanding VB Variables
Methods of accessing a File
Chapter 4 - Visual Basic Schneider
Microsoft Visual Basic 2005 BASICS
CS285 Introduction - Visual Basic
Intro to Programming Concepts
Chapter 8 - Functions and Functionality
For...Next Statements.
Presentation transcript:

User-Defined Data Types School of Business Eastern Illinois University User-Defined Data Types (Week 12, Friday 4/11/2003) © Abdou Illia, Spring 2003

Outline and Objectives Fixed-Length String Variables Records

Fixed-Length Strings Versus Variable-Length Strings So far, we have been using Variable-Length string variables Variable-Length string variables Characteristics Example Can contain strings of variable length Name = “Lee” or Name = “Jimmy” Are declared without mentioning a specific length Dim Name As String Have a VB built-in data type (String) Could be used in programs without being declared

Fixed-Length Strings Versus Variable-Length Strings String variables can be of Fixed-Length Fixed-Length string variables Are declared using statements of the form: Dim VariableName As String * n Where n (representing the length of the string) is a positive integer Are named following the same rules as other variable types If strings longer than n are assigned to a Fixed-Length string Only the n first characters will appear If strings shorter than n are assigned to a Fixed-Length string Spaces will be added to the end of the string

Fixed-Length strings: Example Private Sub cmdGo_Click() ‘ Illustrate fixed-length strings Dim town As String Dim city As String * 9 Dim municipality As String * 12 town = "Chicago" city = "Chicago" municipality = "Chicago" picOutput.Cls picOutput.Print "123456789012345" picOutput.Print city & "***" picOutput.Print town & "***" picOutput.Print municipality & "***" End Sub

Records Students.txt “ST001”,”Andrea”,1982 “ST002”,”John”,1979 “ST003”,”Bill”,1981 Records Each data file is a collection of records Each record is a collection of fields In a record, each field has a name. Example: StudentID, State a type. Example: numeric, string a length which is a number of spaces allocated to it Records’ fields are usually hold Using fixed-length variables Records are user-defined data types Name:_ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _

Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ Using Records in VB In VB, each character of a string is stored in a piece of memory known as a byte So, a field of type String * n requires n bytes of memory In VB, numbers (Integer, Single, etc.) are stored in a different manner than strings Integer numbers are always stored using 2 bytes Single numbers are always stored using 4 bytes

Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ Using Records in VB Declare the record’s layout in General declaration section of a form or in a BAS Module (Project/Add Module…) using statements of the form: [Public/Private] Type RecordType FieldName1 As FieldType1 FieldName2 As FieldType2 …….. End Type Public Type collegeData nom As String * 10 State As String * 2 YearFounded As Integer End Type Example

Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ Using Records in VB Declare the Record variable in the code window of the form (usually in an event procedure) using statements like: Dim RecordVariable As RecordType Example: Dim college As collegeData Make VB create necessary memory space to hold data in the three fields of the record variable “college”. Each field can be accessed using a reference like college.FieldName college college.nom college.state college.yearFounded

Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ Using Records in VB Assign values to each field using Assignment statements. Note: Value can be assigned - Using forms - Using data stored in a file - etc. Examples: college.nom = "Harvard" college.state = "MA" college.yearFounded = 1636 college.nom = txtCollegeName college.state = txtState college.yearFounded = Val(txtYear)

Examples ‘ In General declaration section of the form Private Type vitamins A As Single B As Single End Type Private Sub cmdDisplay_Click() Dim Minimum As vitamins Minimum.A = 500 Minimum.B = 200 picOutput.Print Minimum.A picOutput.Print Minimum.B End Sub

Examples ‘ In BAS Module Public Type address Name As String * 25 Street:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ City: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ State: _ _ Zip: :_ _ _ _ _ _ _ _ _ _ Examples ‘ In BAS Module Public Type address Name As String * 25 Street As String * 30 City As String * 20 State As String * 2 Zip As String * 10 End Type Private Sub cmdDisplay_Click() Dim Institution As address Institution.Name = "WhiteHouse" Institution.Street = “1600 Pennsylvania Avenue“ Institution.City = “Whashington“ Institution.State = “DC“ Institution.Zip = “20500“ End Sub

Exercises Write a Type block to declare the layout of a record with the given names and fields Name: Student; Fields: SSN, Name, Grade Name: Planet; Fields: PlanetName, DistanceFromSun Name: Sales; Fields: Store, AmountOfSales For each of the above three cases, write a procedure that declare a record variable and assign values to each of its fields.