Programming with Microsoft Visual Basic.NET. Array. What have we learnt in last lesson? What is Array?

Similar documents
UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

7. Apply a Range of Table Features

Copyright 2014 Pearson Education, Inc. Chapter 7. Multiple Forms, Modules, and Menus. Copyright 2014 Pearson Education, Inc.

Chapter 7: Arrays. David I. Schneider, An Introduction to Programming using Visual Basic.NET, 5th Edition, Prentice Hall, 2002.

END-TERM EXAMINATION

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Word 2007: Flowcharts Learning guide

C# Continued. Learning Objectives:

Paint Tutorial (Project #14a)

Chapter 14: Files and Streams

Chapter 11. Data Files The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Part 1: Basics. Page Sorter:

05/31/2009. Data Files

Lesson 6 Adding Graphics

You will have mastered the material in this chapter when you can:

In this lesson, you ll learn how to:

ScreenBeam Touch90 Interactive Whiteboard

(0,0) (600, 400) CS109. PictureBox and Timer Controls

Chapter 6: Using Arrays

UNIT V - ADO.NET Database Programming with ADO.NET- Data Presentation Using the DataGridView Control- DataGridView- Updating the Original Database.

KINGS COLLEGE OF ENGINEERING PUNALKULAM DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK UNIT - I WINDOWS PROGRAMMING PART A (2 MARKS)

Drawing Graphics in C Sharp

C# Continued. Learning Objectives:

Microsoft Visual Basic 2005: Reloaded

DEPARTMENT OF INFORMATION TECHNOLOGY ACADEMIC YEAR EVEN SEMESTER QUESTION BANK. UNIT I WINDOWS PROGRAMMING Part-A (2-MARKS)

Adobe Flash CS4 Part 1: Introduction to Flash

9 Using Appearance Attributes, Styles, and Effects

PowerPoint Slide Basics. Introduction

LESSON 4 PAGE LAYOUT STRUCTURE 4.0 OBJECTIVES 4.1 INTRODUCTION 4.2 PAGE LAYOUT 4.3 LABEL SETUP 4.4 SETTING PAGE BACKGROUND 4.

Efficiency of Bubble and Shell Sorts

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

How to create interactive documents

PowerPoint Introduction. Video: Slide Basics. Understanding slides and slide layouts. Slide Basics

MS Publisher 2007: Graphics. Lesson Notes Author: Pamela Schmidt

Libraries. Multi-Touch. Aero Peek. Sema Foundation 10 Classes 2 nd Exam Review ICT Department 5/22/ Lesson - 15

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Intermediate Microsoft Word 2010

Guess Paper Class XII Subject Informatics Practices TIME : 1½ HRS. M.M. : 50

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Microsoft Visual Basic 2005 CHAPTER 6. Loop Structures

Object Oriented Programming. Java-Lecture 6 - Arrays

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

General Instructions. You can use QtSpim simulator to work on these assignments.

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Adding Objects Creating Shapes Adding. Text Printing and Exporting Getting Started Creating a. Creating Shapes Adding Text Printing and Exporting

Using Microsoft Word. Tables

Design Of Human Computer Interfaces Assignment 1- Hello World. Compliance Report

THE PAINT WINDOW. At the very top is the Title Bar, just as in all programs, below it is a very simple Menu Bar and below that is the Ribbon.

Using SymPrint to Make Overlays, Templates & More...

Sending image(s) to report Click Send Snapshot on any screen in Dolphin3D and choose the Send to Report option

Module 8: Building a Windows Forms User Interface

Adobe Photoshop Sh S.K. Sublania and Sh. Naresh Chand

Guide to WB Annotations

Programme. Introduction to Animation Shop

Microsoft Office Training Skills 2010

Workshop on Census Data Processing. TELEform Designer User Manual

How to declare an array in C?

CHAPTER 1: INTRODUCTION TO THE IDE 3

Adobe Illustrator CS Design Professional GETTING STARTED WITH ILLUSTRATOR

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

MS Word 2007: Graphics. Lesson Notes Author: Pamela Schmidt. The Drawing Tools Format Ribbon appears when the object is selected.

Introduction To Programming. Chapter 5: Arrays and More

Microsoft Windows 7 - Illustrated Unit A: Introducing Windows 7

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

SmartBoard & Smart Notebook Software

blur (.blr) Project Proposal Dexter Callender dec2148 Tim Goodwin tlg2132 Daniel Hong sh3266 Melissa Kaufman-Gomez mhk2149

Location of menu elements

1. Multimedia authoring is the process of creating a multimedia production:

Web-Friendly Sites. Planning & Design 1

ENGR/CS 101 CS Session Lecture 13

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

Lesson 09 Working with. SDI and MDI. MIT 31043: Rapid Application Development By: S. Sabraz Nawaz Senior Lecturer in MIT Dept. of MIT, FMC, SEUSL

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

The MimioTeach package contains the following items: 1 MimioTeach bar 5 Mounting plates. 2 USB power adapter 6 MimioStudio DVD

Unit 11.Introduction to Form and Report

Contents. More Controls 51. Visual Basic 1. Introduction to. xiii. Modify the Project 30. Print the Project Documentation 35

Appendix A ACE exam objectives map

Eyes of the Dragon - XNA Part 37 Map Editor Revisited

File: SiteExecutive 2013 Core Modules User Guide.docx Printed September 30, 2013

Using Microsoft Word. Working With Objects

LAB 1: INTRODUCTION TO DATA STUDIO AND ONE-DIMENSIONAL MOTION

Paint/Draw Tools. Foreground color. Free-form select. Select. Eraser/Color Eraser. Fill Color. Color Picker. Magnify. Pencil. Brush.

Creating a Flyer. Open Microsoft Publisher. You will see the list of Popular Publication Types. Click the Blank Page Sizes.

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Visual Basic.NET. 1. Which language is not a true object-oriented programming language?

The Warhol Language Reference Manual

1.1 Considering for Choosing Layout in SmartArt Graphics

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

VISUAL BASIC 6.0 OVERVIEW

Ai Adobe. Illustrator. Creative Cloud Beginner

Pen Tool, Fill Layers, Color Range, Levels Adjustments, Magic Wand tool, and shadowing techniques

Toon Boom Harmony 11.1 Preferences Guide (Paint)

Basics of Spreadsheet

TRAINING GUIDE FOR OPC SYSTEMS.NET. Simple steps to successful development and deployment. Step by Step Guide

Mathematics. Computer Applications. New Jersey Quality Single Accountability Continuum (NJQSAC) Department: Course Title.

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3 5 CHAPTER 4. Algorithm Design & Problem Solving. Data Representation.

Give one example where you might wish to use a three dimensional array

Curriculum Map Grade(s): Subject: AP Computer Science

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

Transcription:

What have we learnt in last lesson? Programming with Microsoft Visual Basic.NET Using Toolbar in Windows Form. Using Tab Control to separate information into different tab page Storage hierarchy information into Tree view Development of subroutine by using Function and Procedure Lesson 5 I135-1-A A @ Peter Lo 2009 1 I135-1-A A @ Peter Lo 2009 2 What is Array? Array Declare and Assign Array An array is a collection of data of the same type. It is implemented in Visual Basic as an object. Each individual item in array that contains a value is called an element Arrays provide access to data by using a numeric index, or subscript, to identify each element in the array Data Type Default Value Any Numeric Data Type 0 Reference Data Type Null I135-1-A A @ Peter Lo 2009 3 Boolean Data Type False I135-1-A A @ Peter Lo 2009 4

Why use Array? Suppose that you want to evaluate the exam grades for 30 students and to display the names of the students whose marks. Dim student1 As String, mark1 As Integer Dim student2 As String, mark2 As Integer Dim student3 As String, mark3 As Integer Array Name Upper bound of subscripts in the array Dim student(30) As String Dim mark(30) As Integer Data Type I135-1-A A @ Peter Lo 2009 5 Array Terminology Syntax for Array Declaration: Dim arrayname(n)asdatatype 0 is the Lower Bound of the array n is the Upper Bound of the array the last available subscript in this array The number of elements is the size of the array Syntax for assigning values into an array arrayname(arrayindex) = Value Arrays may be initialized when they are created: Dim arrayname( ) As vartype = {value0, value1, _ value2,..., valuen} I135-1-A A @ Peter Lo 2009 6 Creating a Two-Dimensional Array A two-dimensional array holds data that is arranged in rows and columns A two-dimensional array can also be described as an array of arrays. ReDim Statement The size of an array may be changed after it is created where arrayname is the name of the already declared array and m is an Integer literal,variable, or expression.: ReDim arrayname(m) To keep any data that has already been stored in the array when resizing it, use ReDim Preserve arrayname(m) I135-1-A A @ Peter Lo 2009 7 I135-1-A A @ Peter Lo 2009 8

Copying Arrays If arrayone() and arraytwo() have been declared with the same data type, then the statement arrayone = arraytwo makes arrayone() an exact duplicate of arraytwo(). It will have the same size and contain the same information. Using the Length Property The Length property of an array contains the number of elements in an array (1 less than upper bound) I135-1-A A @ Peter Lo 2009 9 I135-1-A A @ Peter Lo 2009 10 The For Each Loop Searching an Array Searching each element in an array is called a sequential search The BinarySearch method searches a sorted array for a value using a binary search algorithm The binary search algorithm searches an array by repeatedly dividing the search interval in half I135-1-A A @ Peter Lo 2009 11 I135-1-A A @ Peter Lo 2009 12

Sorting an Array Passing an Array by Reference An array can be passed as an argument to a Sub procedure or a Function procedure I135-1-A A @ Peter Lo 2009 13 I135-1-A A @ Peter Lo 2009 14 MenuStrip Object Menu A menu bar is a strip across the top of a window that contains one or more menu names A menu is a group of commands, or items, presented in a list Creating a Menu Bar I135-1-A A @ Peter Lo 2009 15 I135-1-A A @ Peter Lo 2009 16

Standard Items for a Menu Visual Basic 2008 contains an Action Tag that allows you to create a full standard menu bar commonly provided in Windows programs Action tags provide a way for you to specify a set of actions, called smart actions, for an object as you design a form Drag the MenuStrip component onto the Windows Form object. Click the Action Tag on the MenuStrip object Click Insert Standard Items on the MenuStrip Tasks menu Click File on the menu bar to view the individual menu items and their associated icons on the File menu File Handling Read and Write Text File I135-1-A A @ Peter Lo 2009 17 I135-1-A A @ Peter Lo 2009 18 File Handling To process data more efficiently, many developers use text files (or binary files) to store and access information for use within an application Text files have an extension that ends in.txt A simple text file is called a sequential file (actually it is usually called an ASCII text file) Read Text File Stream Reader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. Use StreamReader for reading lines of information from a standard text file. StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system. I135-1-A A @ Peter Lo 2009 19 I135-1-A A @ Peter Lo 2009 20

Handling End of File Save Text File ReadToEnd works best when you need to read all the input from the current position to the end of the stream. If more control is needed over how many characters are read from the stream, use Read(Char[], Int32, Int32), which generally results in better performance. ReadToEnd assumes that the stream knows when it has reached an end. For interactive protocols, in which the server sends data only when you ask for it and does not close the connection, ReadToEnd might block indefinitely and should be avoided. Note than when using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream. If the size of the buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes). To add the ability to write to a file via the application, use the Stream Writer class. Stream Writer is designed for character output in a particular encoding, whereas the Stream class is designed for byte input and output. Use Stream Writer for writing lines of information to a standard text file. I135-1-A A @ Peter Lo 2009 21 I135-1-A A @ Peter Lo 2009 22 Opening a Text File To open a text file, you need an object available in the System.IO namespace called a StreamReader Dim objreader as IO.StreamReader If IO.File.Exists( e:\file.txt ) Then objreader = IO.File.OpenText( e:\file.txt ) Else MsgBox( Error! File not Exist. ) Me.close() End If Reading a Text File To determine whether the end of the file has been reached, use the Peek procedure of the StreamReader object Stream Reader should be close at the end I135-1-A A @ Peter Lo 2009 23 I135-1-A A @ Peter Lo 2009 24

Writing to a Text File Writing to a text file is similar to reading a text file. The System.IO namespace also includes the StreamWriter class which is used to write a stream of text to a file Multiple Forms Multiple-Document Interface (MDI) I135-1-A A @ Peter Lo 2009 25 I135-1-A A @ Peter Lo 2009 26 Multiple-Document Interface (MDI) Multiple-document interface (MDI) applications allow you to display multiple documents at the same time, with each document displayed in its own window. MDI applications often have a Window menu item with submenus for switching between windows or documents. Creating an Instance of a Windows Form Object To display a second or subsequent form, the initial step in displaying the form is to create an instance of the Windows Form object When creating multiple Windows Form objects, Visual Basic allows you to generate two types of forms: A Modal Form retains the input focus while open ShowDialog( ) A Modeless Form allows you to switch the input focus to another window Show( ) I135-1-A A @ Peter Lo 2009 27 I135-1-A A @ Peter Lo 2009 28

Startup Objects Every application begins executing a project by displaying the object designated as the Startup object Application Class If you have an application with multiple forms (windows), you can exit the application and close all the open forms (windows) by using the Exit method of the Application Class. Application.Exit( ) I135-1-A A @ Peter Lo 2009 29 I135-1-A A @ Peter Lo 2009 30 The FormClosing Event Example of Form Closing Event Form Closing event: Occurs when a form is about to be closed by the program code or by the user Allows you to trap the closing action and take any necessary actions such as saving data Can be used to cancel the close action Set e.cancel = True to cancel the closing action Form may be closed by Me.Close() statement or by user clicking the Close button on title bar I135-1-A A @ Peter Lo 2009 31 I135-1-A A @ Peter Lo 2009 32

The MessageBox.Show Method Message box Interactive Dialog Box MessageBox.Show method: Displays a message box with text, one or more buttons, and an icon When a message box is displayed, the program waits until the user selects a button MessageBox.Show returns an integer value indicating which button the user selected DialogResult values include: Windows.Forms.DialogResult.Yes Windows.Forms.DialogResult.No I135-1-A A @ Peter Lo 2009 33 I135-1-A A @ Peter Lo 2009 34 How to use MessageBox.Show Style for Message Dialog I135-1-A A @ Peter Lo 2009 35 I135-1-A A @ Peter Lo 2009 36

Graphic Object Drawing Bitmap, Graphic & Pen The Graphics object provides methods for drawing a variety of lines and shapes. Simple or complex shapes can be rendered in solid or transparent colors, or using user-defined gradient or image textures. Lines, open curves, and outline shapes are created using a Pen object. To fill in an area, such as a rectangle or a closed curve, a Brush object is required. I135-1-A A @ Peter Lo 2009 37 I135-1-A A @ Peter Lo 2009 38 Pen and Brush Object You use pen and brush objects to render graphics, text, and images with GDI+. A pen is an instance of the Pen class, and is used to draw lines and outlined shapes. A brush is an instance of any class that derives from the MustInherit (abstract) Brush class, and can be used to fill shapes or paint text. Color objects are instances of classes that represent a particular color, and can be used by pens and brushes to indicate the color of rendered graphics. A Pen object draws a line of specified width and style. Use the DashStyle property to draw several varieties of dashed lines. The line drawn by a Pen object can be filled in a variety of fill styles, including solid colors and textures. The fill style depends on brush or texture that is used as the fill object. Exception Handling Error Capture and Handling I135-1-A A @ Peter Lo 2009 39 I135-1-A A @ Peter Lo 2009 40

Exception Handling Exception Type The Try-Catch set of statements detects exceptions and takes corrective action I135-1-A A @ Peter Lo 2009 41 I135-1-A A @ Peter Lo 2009 42 Exception Handling Example I135-1-A A @ Peter Lo 2009 43