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.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Using VB with MS Applications R. Juhl, Delta College.
Customizing Reports. Custom Reports A report is a formatted hardcopy of the contents of one or more tables from a database. Although you can format and.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
Control Arrays. All the components in the Visual Basic toolbox are referred to as controls A control array is a group of controls of the same type that.
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.
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.
Lec4 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 4 Back To Index v Iteration - Looping v Arrays.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Controls General Discussion. VB Controls Visual Basic Controls A control is the generic name for any object placed on a form Controls may be images,
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
Chapter 8: String Manipulation
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Why to Create a Procedure
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
Chapter 4: The Selection Process in Visual Basic.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Copyright © 2001 by Wiley. All rights reserved. Chapter 4: The Selection Process in Visual Basic Selection Process Two Alternative Structure If..Then..ElseIf.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Chapter Six: Working With Arrays in Visual Basic.
You can use Access forms to create an interface to your reports and queries. You can add: Buttons to initiate reports and queries Combo Boxes, List.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
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”
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
Applications Development
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
1 Advanced Computer Programming Lab Calculator Project.
Chapter 7 P 1 Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items -
Two Forms Please use speaker notes for additional information!
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
VAT Calculator program Controls Properties Code Results.
Pay Example (PFirst98) Please use speaker notes for additional information!
Word Processor Version.2. Methods Visual Basic is –Object Oriented –Event Driven Objects –Properties –Methods.
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
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.
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.
21/03/ Working with Controls Text and List Boxes.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
1 By Dr. HANY ELSALAMONY. 1. What are differences between interpreted and compiled languages? 2. What are the programming steps to creating the Visual.
Multiple Forms and Menus
CSI 101 Elements of Computing – Spring 2009
Using Procedures and Exception Handling
Department Array in Visual Basic
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Visual Basic: Week 5 Review User defined functions
CHAPTER FOUR VARIABLES AND CONSTANTS
Group Boxes, Radio buttons and Checked List Boxes
GUI Programming in Visual Studio .NET
Presentation transcript:

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 with a common name. For example, at the Pantherburger Shop, rather than having hamburgers, fries and drinks each with its own price and quantity measures we might better describe the situation as an array of objects.

Arrays2 Data Arrays (1) A variable like Stuff defines a data object into which a single quantity can be placed. A variable like Product defines a data object into which an array of information can be placed.

Arrays3 Data Arrays (2) A data array is defined the same way a normal variable is: Dim intI as Integer Dim strProduct(3) as String Dim curValue(3) as Currency Dim intNmbr(3) as Integer For intI = 0 to 3 intNmbr(intI) = 0 Next intI

Arrays4 To Learn More... Help on Data Arrays can be found in the Textbook on pages (chapter 6) Help can also be found by searching the Visual Basic Documentation on the system with the keyword “dim”. (“dim” is just short for dimension.)

Arrays5 Arrays of Objects Just as there are data arrays, there may be arrays of objects, such as command buttons, labels or picture boxes. An array of labels might be made with one label for each product, or for each price. An array of command might be made to handle adding products. Making such arrays involves some trickery...

Arrays6 Object Trickery (1) Create an toolbox object, perhaps a command, changing its (name) and caption.

Arrays7 Object Trickery (2) 1.Copy and paste the object (Ctrl-C)(Ctrl-V) or Edit/Copy then Edit/Paste. 2.The message “Do you want to create a control array?” appears. Answer “yes”. 3.Type Edit/Paste or (Ctrl-V) several more times to make an array of commands.

Arrays8 Object Trickery (3) The Properties Window shows it all. Note that the 4th command created is shown as “cmdButn(3)”

Arrays9 Object Trickery (4) If you line them up carefully [put cmdButn(0) on top and cmdButn(3) on the bottom] you have an array of commands. Double click on any one of them and you get the code window.

Arrays10 Object Trickery (5) The window is a bit strange. There is now a “parameter” inside the normally blank parentheses: Private Sub cmdButn_Click(Index As Integer) lblOutput.Caption = "## " & Index & " ##" End Sub (I later added the second line, using the parameter “Index” as a variable.)

Arrays11 Object Trickery (6) Run the process Click each button Observe the effect

Arrays12 Arrays of Objects Using the same procedure, you can make arrays of labels, or of pictures, or of check boxes, etc. You can change the PantherBurger program to make arrays of products, commands, product counts, and total costs.

Arrays13 Combination Effects

Arrays14 Initialization Code Option Explicit Dim strProd(3) As String Dim curVal(3) As Currency Private Sub Form_Load() strProd(0) = "Burger” : strProd(1) = ”Ch’burger" strProd(2) = "Fries” : strProd(3) = "SoftDrink" curVal(0) = 0.99 : curVal(1) = 1.27 curVal(2) = 0.83 : curVal(3) = 1.02 End Sub

Arrays15 Selling the Burgers Private Sub cmdAdder_Click(Index As Integer) lblNmbr(Index).Caption = lblNmbr(Index).Caption + 1 cmdTotalize End Sub Private Sub cmdSubber_Click(Index As Integer) lblNmbr(Index).Caption = lblNmbr(Index).Caption - 1 If blNmbr(Index).Caption < 0 Then lblNmbr(Index).Caption = 0 End If cmdTotalize End Sub

Arrays16 Doing the Totals Private Sub cmdTotalize() curSubtot = 0 For intI = 0 To 3 lblCost(i).Caption = curValu(intI) * _ lblNmbr(intI).Caption If lblCost(i).Caption > 0 Then lblCost(i).Visible = True Else lblCost(i).Visible = False End If curSubtot = curSubtot + lblCost(intI).Caption Next intI lblSubtt.Caption = Format(curSubtot, "$#0.00")..

Arrays17 Increasing the Menu (1) Option Explicit Dim strBprod(3) As String, strLprod(3) As String Dim curBval(3) As Currency, curLval(3) As Currency Private Sub Form_Load() strBprod(0) = ”Eggs” : strBprod(1) = ”Bacon" strBprod(2) = ”Toast” : strBprod(3) = ”Coffee" strLprod(0) = "Burger” : strLprod(1) = "cheesburger" strLprod(2) = "Fries” : strLprod(3) = "SoftDrink" curBval(0) = 1.99 : curBval(1) = 1.11 curBval(2) = 0.77 : curBval(3) = 1.02 curLval(0) = 0.99 : curLval(1) = 1.27 curLval(2) = 0.83 : curLval(3) = 1.02 End Sub

Arrays18 Increasing the Menu (2) If we have commands “Breakfast” and “Lunch” the entire menu can be altered: Private Sub cmdBreakfast_Click() For intI = 0 to 3 strProd(intI) = strBprod(intI) curVal(intI) = curBval(intI) Next intI End Sub Private Sub cmdLunch_Click() For intI = 0 to 3 strProd(intI) = strLprod(intI) curVal(intI) = curLval(intI) Next intI End Sub