User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
Variables and Constants
Fundamentals of Programming in Visual Basic
VBA Modules, Functions, Variables, and Constants
Chapter 4 - Visual Basic Schneider
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
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)
ITP 150 Week 4 Variables. ITP Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor.
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.
User-defined Data Types VB provides programmers with the ability to create user-defined types. User-defined Types are collections of related variables.
Control Arrays, Records, and Record Arrays in V.B. Week 10.
Chapter 9 Random Access Files.
Manipulating Strings.
Apply Sub Procedures/Methods and User Defined Functions
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.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
CS0004: Introduction to Programming Variables – Strings.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Chapter four selected exercises with solutions. 4.2.
Lecture 8 Visual Basic (2).
Database Management School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 16, Monday 12/09/2002)
Types and Loops.
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.
Lecture Set 12 Sequential Files and Structures Part D - Structures.
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.
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)
Types of Visual Basic Data Numeric Data Non Numeric Data.
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)
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
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.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
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.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
VBA - Excel VBA is Visual Basic for Applications
Variables Mr. Crone.
User-Defined Data Types
Chapter 7 Arrays.
2. Understanding VB Variables
Methods of accessing a File
Microsoft Visual Basic 2005 BASICS
Intro to Programming Concepts
For...Next Statements.
Presentation transcript:

User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)

2 Outline and Objectives n Fixed-Length String Variables n Records

3 Fixed-Length Strings Versus Variable-Length Strings n So far, we have been using Variable-Length string variables CharacteristicsExample Can contain strings of variable lengthName = “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 Variable-Length string variables

4 Fixed-Length Strings Versus Variable-Length Strings n String variables can be of Fixed-Length n Fixed-Length 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 n If strings longer than n are assigned to a Fixed-Length string – Only the n first characters will appear n If strings shorter than n are assigned to a Fixed-Length string – Spaces will be added to the end of the string

5 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 " " picOutput.Print city & "***" picOutput.Print town & "***" picOutput.Print municipality & "***" End Sub

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

7 Using Records in VB n In VB, each character of a string is stored in a piece of memory known as a byte n So, a field of type String * n requires n bytes of memory n 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: _ _ _ _

8 Using Records in VB 1) 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 Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ Public Type collegeData nom As String * 10 State As String * 2 YearFounded As Integer End Type Example

9 Using Records in VB 2) Declare the Record variable in the Form code (usually in an event procedure) using statements of the form: Dim RecordVariable As RecordType n 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 a reference like college.FieldName Name:_ _ _ _ _ _ _ _ _ _ State: _ _ Year Founded: _ _ _ _ college.nom college.state college.yearFounded college

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

11 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

12 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 Name: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Street: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ City: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ State: _ _ Zip: : _ _ _ _ _ _ _ _ _ _

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