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.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
Variables and Constants
Declaring and Using Variables Visual Basic Data Types.
OOP: Creating Object-Oriented Programs. VB & Object Oriented Programming Objects have properties, methods, and generate events Classes have been predefined.
VBA Modules, Functions, Variables, and Constants
User Defined Types, Collections, Enumerations & Classes CIS 338 Tony Lopez (a Cal Poly student) updated April 2003.
Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
1 Lecture 32 Handling Selected Topics Again!! Structs and Arrays of Structs Special Lectures.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
CSI 101 Elements of Computing Spring 2009 Lecture #6: Data Types and Variables in Visual Basic Wednesday, Februrary 11th, 2009.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
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.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
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.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Tutorial 11 Using and Writing Visual Basic for Applications Code
The animation is already done for you; just copy and paste the slide into your existing presentation. Dony Pranadiyanta, ST.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
8-1 Chapter 8 Using User-Defined Data Types and Object Oriented Programming.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Chapter four selected exercises with solutions. 4.2.
ENGR 112 Decision Structures.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
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.
Chapter 8 - Visual Basic Schneider
1 Working with Objects. 2 Defining a Class in VB.NET A class is a user-defined data type You can declare it as part of a module, but usually in a separate.
Validation "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
CSIT 208, Section Instructor: P eter C hen Introduction to Programming with QBasic to Visual Basic Lecture 9.
Pay Example (PFirst98) Please use speaker notes for additional information!
Chapter 8 P 1 Arrays and Grids Single-dimension arrays Definition An array is a sequence of elements all referred to with a common name. Other terms: table,
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Variables in VB. What is a variable? ► A named memory location that stores a value.
Chapter 13 Copyright 2000 All rights reserved 1 Chapter 13 Object-Oriented Programming.
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.
Two-Dimensional Arrays. Two-dimensional arrays variables store the contents of tables or matrices. Example: Dim arrTable(1 to 5, 1 to 5) As Integer first.
‘Tirgul’ # 5 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5.
© 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 - Break Processing
Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5
IE 8580 Module 4: DIY Monte Carlo Simulation
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
User-Defined Data Types
2. Understanding VB Variables
Methods of accessing a File
Department Array in Visual Basic
البرمجة بلغة فيجول بيسك ستوديو
Lbound and Ubound Functions
CS285 Introduction - Visual Basic
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
Exercise Solution First questions What's output What's input
If, Subroutines and Functions
EXCEL Creating An Array In VBA
Intro to Programming Concepts
For...Next Statements.
Presentation transcript:

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. User-defined types are useful when you want to create a single variable that holds several related pieces of information.

Creating Your Own Data Types You create a user-defined type with the Type statement, which must be placed in the Declarations section of a module. User-defined types can be declared as Private or Public with the appropriate keyword.

Type Statement Syntax: [Private | Public] Type varname elementname As type [elementname As type]... End Type

Type Statement Example Type EmployeeRecord ID As Integer Name As String Address As String Phone As Long HireDate As Date End Type Public Sub CreateRecord() Dim MyRecord As EmployeeRecord MyRecord.ID = End Sub

' Declarations (in a standard module). Public Type SystemInfo CPU As String VideoColors As Integer Cost As Currency PurchaseDate As Variant End Type Public Sub CreateSystem() Dim MySystem As SystemInfo MySystem.CPU = “Pentium 4” MySystem.VidoColors = 256 MySystem.Cost = MySystem.PurchaseDate = #1/1/02# End Sub

Private Sub cmdProcess_Click() picBox.Cls Dim college As collegeData Call GetDat(college) Call DisplayStatement(college) End Sub Private Sub DisplayStatement(school As collegeData) picBox.Print school.name; " was founded in " & _ school.yearFounded; picBox.Print " in "; school.state End Sub Private Sub GetDat(school As collegeData) school.name = txtCollege.Text school.state = txtState.Text school.yearFounded = Val(txtYear.Text) End Sub Public Type collegeData name As String * 30 state As String * 2 yearFounded As Integer End Type

Dim arrDog(1 To 5) As Dog Dim Index As Integer Private Sub cmdAddData_Click() arrDog(Index).Breed = txtBreed.Text arrDog(Index).Color = txtColor.Text arrDog(Index).Age = Val(txtAge.Text) Index = Index + 1 'clear textboxes for new entry txtBreed.Text = "" txtColor.Text = "" txtAge.Text = "" End Sub Private Sub cmdPrintData_Click() For i = 1 To 5 picOutput.Print arrDog(i).Breed & " "; picOutput.Print arrDog(i).Color & " "; picOutput.Print arrDog(i).Age Next i End Sub Private Sub Form_Load() Index = 1 End Sub Public Type Dog Breed As String Color As String Age As Integer End Type