To understand what arrays are and how to use them

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Working with Intrinsic Controls and ActiveX Controls
Text Box controls are used when users are required to type some input (during program execution), or output is displayed on the form (known as the user-
Creating Object Oriented Programs Object oriented (OO) terminology Class vs. object Instantiate an object in a project Understand Class_Initialize / Terminate.
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.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
08/09/ Arrays Defining, Declaring & Processing.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Using Arrays and File Handling
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
Indexing. The Idea of Indexing Indexing means having several data items organized under a single name where the individual items can be referred to by.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Visit to download CodeAwesomeness.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
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.
Microsoft Outlook 2010 Chapter 3 Managing Contacts and Personal Contact Information with Outlook.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
04/11/ Arrays 1D Arrays Defining, Declaring & Processing.
Count and add list of numbers From user input and from file.
Skill Area Array Random-Number Generator An array is a group of memory locations all containing data items of the same name and type. Array names.
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
31/01/ Selection If selection construct.
Visual Basic 6 Programming Decide how many variables you need by looking at this form. There is one textbox for input and there are 3 labels for output,
1 Dynamic Arrays ListBoxes, Dynamic Arrays, Dynamic Control Arrays ListBoxes are on pp and dynamic arrays are in Chapter 7 of Deitel, Deitel and.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
Using Forms and Form Elements In Visual Basic.NET.
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
Arrays 1.
Visual Basic Fundamental Concepts
Reading & writing to files
Visual Basic..
Other Features – Filter Options
Python I/O.
File Handling Programming Guides.
Department Array in Visual Basic
Don’t Leave Home Without them
Data Structures – 1D Lists
ARRAYS 1 GCSE COMPUTER SCIENCE.
Video list editor BIS1523 – Lecture 24.
CIS 16 Application Development Programming with Visual Basic
Remembering lists of values lists
Just Basic Lessons Mr. Kalmes.
Text / Serial / Sequential Files
Learning Intention I will learn about evaluating a program.
Fonts, TabControl, ListBox
Random Access Files / Direct Access Files
Programming Control Structures with JavaScript Part 2
Training & Development
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Dictionary Builder Part 4 Loading Files.
Learning Intention I will learn how to use an array to store data in a program.
CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009.
Java: Variables, Input and Arrays
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
GCSE Computing:: Iteration (For Loops)
Just Basic Lessons Mr. Kalmes.
Text / Serial / Sequential Files
8 Records 25/07/2019.
4.4 – List vs Array Exercise 4.1: Array Variables
Presentation transcript:

To understand what arrays are and how to use them

Variables Dim MyNumber As Integer MyNumber = 5 Dim MyText As String MyText = “A String is really just text” Dim MyNumber As Integer = 5

Good practice Comments! Meaningful variable names All variables declared at the start of the subroutine Rename controls (textboxes, command buttons etc to have meaningful name) Use some kind of system for consistency, perhaps all text boxes should begin txt For example txtMaxAmount

Arrays An array is a variable that can hold more than one piece of information at a time. Dim MyNumbers(4) As Integer MyNumbers(0) = 1 MyNumbers(1) = 2 MyNumbers(2) = 3 MyNumbers(3) = 4 MyNumbers(4) = 5

An example Index Value Start a new VB project. Add a Button to your Form. Set the Text property of the Button to “Integer Array” Attach the following code to your button Dim MyNumbers(4) As Integer MyNumbers(0) = 10 MyNumbers(1) = 20 MyNumbers(2) = 30 MyNumbers(3) = 40 MyNumbers(4) = 50 MsgBox("First Number is: " & MyNumbers(0) ) MsgBox("Second Number is: " & MyNumbers(1) ) MsgBox("Third Number is: " & MyNumbers(2) ) MsgBox("Fourth Number is: " & MyNumbers(3) ) MsgBox("Fifth Number is: " & MyNumbers(4) ) Index Value

A second example You need a list box for this example Dim MyNumbers(4) As Integer Dim count As Integer MyNumbers(0) = 10 MyNumbers(1) = 20 MyNumbers(2) = 30 MyNumbers(3) = 40 MyNumbers(4) = 50 For count = 0 To 4 ListBox1.Items.Add( MyNumbers(count) ) Next

3rd example Still needs a list box! Dim MyText(4) As String Dim count As Integer MyText(0) = "This" MyText(1) = "is" MyText(2) = "a" MyText(3) = "String" MyText(4) = "Array" For count = 0 To 4 ListBox1.Items.Add( MyText (count) ) Next

Work! Write a shopping list program The program should use an a array of strings to store 5 items in a shopping list A for loop should be used to get the data into the array An input box should be displayed for each item and the user will be expected to type the item needed into the input box Once the user has inputted 5 items they should be displayed in a listbox. The output list should be numbered and displayed using a for loop

Shopping List Extension Add a sort button that will display list in alphabetical order Find out about multidimensional arrays and add an additional “column” to the array to store quality wanted User needs to be able to input this quantity and it should also be displayed Add ability to save/load the list Add a save / load dialog box to allow user to choose file Ability to print the shopping list Ability to email the shopping list

Arrays where Boundaries are not known You can declare an array where you don’t know how many values you want to store: Dim shoppinglist() As String Could then ask user for how many items to go onto shopping list and then make the array big enough ReDim shoppinglist(number_of_items) Do we have to do anything with the number_of_items before ReDimming the array? You can use the number_of_items variable in a for loop to read in and output the list… Update your shopping list program to find out how many items the user wishes to store.