Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
VBA Modules, Functions, Variables, and Constants
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements.
Fundamental Programming Structures in Java: Strings.
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 7: Working with Arrays
VB .NET Programming Fundamentals
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
A First Program Using C#
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CS0004: Introduction to Programming Input and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
Chapter 3: Data Types and Operators JavaScript - Introductory.
JavaScript, Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Chapter 2: Using Data.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Chapter 8: Manipulating Strings
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 7: Characters, Strings, and the StringBuilder.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
CSIT 108 Review Visual Basic.NET Programming: From Problem Analysis to Program Design.
Microsoft Visual Basic 2008: Reloaded Third Edition
Strings, StringBuilder, and Character
Chapter 7: Working with Arrays
Variables and Arithmetic Operations
Chapter 3: Using Methods, Classes, and Objects
String String Builder.
Introduction to Scripting
Object Oriented System Development with VB .NET
Primitive Types Vs. Reference Types, Strings, Enumerations
Lecture 4 Using Classes Richard Gesick.
Variables and Arithmetic Operations
CIS16 Application Development and Programming using Visual Basic.net
Chapter 3 – Introduction to C# Programming
Microsoft Visual Basic 2005: Reloaded Second Edition
JavaScript: Introduction to Scripting
Presentation transcript:

Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes

Object-Oriented Application Development Using VB.NET 2 Objectives In this chapter, you will: Use the namespaces and classes supplied with VB.NET Use the String class Create a String array Use the ArrayList class

Object-Oriented Application Development Using VB.NET 3 Objectives In this chapter, you will: Work with dates Format numeric output Use the MessageBox class Display a Form

Object-Oriented Application Development Using VB.NET 4 Using the Namespaces and Classes Supplied with VB.NET VB.NET is part of Microsoft’s Visual Studio.NET Visual Studio.NET is part of.NET technology Two important pieces of.NET framework: –Common Language Runtime (CLR) –.NET class library CLR supports common services used by Visual Studio.NET languages

Object-Oriented Application Development Using VB.NET 5 Using the Namespaces and Classes Supplied with VB.NET.NET class library: predefined classes and their methods, organized into namespaces Namespace: group of related classes Keyword Imports: gives compiler access to classes contained in specific namespaces

Object-Oriented Application Development Using VB.NET 6 Using the String Class String: collection of characters VB.NET stores string data in instances of String class String class is a member of System namespace Code to declare a string: Dim s1 As String = "Hello Again"

Object-Oriented Application Development Using VB.NET 7 Using the String Class

Object-Oriented Application Development Using VB.NET 8 Using the String Class String values in VB.NET are immutable – they cannot be changed –Methods that appear to change a string value actually create and return a new String instance Index –Each character in a String instance has an index –Index values in VB.NET begin with zero

Object-Oriented Application Development Using VB.NET 9 Using String Methods Copy method returns a second String that is a copy of the String sent as an argument ' create a copy of s1 Dim s2 As String = String.Copy(s1) Console.WriteLine("s2, a copy of s1, contains " & s2)

Object-Oriented Application Development Using VB.NET 10 Using String Methods Chars method returns the character at a specified index Console.WriteLine("char at index 6 of s1 is " & s1.Chars(6))

Object-Oriented Application Development Using VB.NET 11 Using String Methods There are two options to see whether two string values are equal –Equal sign (=) If s1 = s2 Then Console.WriteLine("s1 = s2") –Equals method Console.WriteLine("s1.Equals(s2) returns " & s1.Equals(s2))

Object-Oriented Application Development Using VB.NET 12 Using String Methods SubString method: –Extracts one or more characters from a String instance –Returns a new String instance containing extracted characters Console.WriteLine("s1.Substring(0, 5) returns " & _ s1.Substring(0, 5))

Object-Oriented Application Development Using VB.NET 13 Using String Methods Replace method replaces one or more characters in a string with one or more other characters Console.WriteLine("s1.Replace(Hello, Hi) returns " & _ s1.Replace("Hello", "Hi")) Console.WriteLine("After Replace s1 contains " & s1)

Object-Oriented Application Development Using VB.NET 14 Using String Methods Insert method inserts one or more characters into an existing string beginning at a specified index Console.WriteLine("s1.Insert(6, There ) returns " & _ s1.Insert(6, "There "))

Object-Oriented Application Development Using VB.NET 15 Using String Methods StartsWith method –Compares the string argument with beginning characters of the String instance –Returns True or False depending on whether there is a match Console.WriteLine("s1.StartsWith(Hi) returns " & _ s1.StartsWith("Hi"))

Object-Oriented Application Development Using VB.NET 16 Using String Methods EndsWith method compares the ending characters with the argument Console.WriteLine("s1.EndsWith(Again) returns " & _ s1.EndsWith("Again")) Use ToUpper method to change the case of a string value to uppercase Use ToLower method to change the case of a string value to lowercase

Object-Oriented Application Development Using VB.NET 17 Using String Methods IndexOf method –Searches a String instance for a specific value –Returns index of the beginning of the value –Returns –1 if no matching value was found Console.WriteLine("s1.indexof(Again) returns " & _ s1.IndexOf("Again"))

Object-Oriented Application Development Using VB.NET 18 Using String Methods Use ToString method to convert numeric values to a string ' convert an integer to String Dim i As Integer = 5 Console.WriteLine("value of Convert.ToString(i) is " & _ Convert.ToString(i)) Use methods in Convert class to convert String values containing numeric data to primitive data types

Object-Oriented Application Development Using VB.NET 19 Creating a String Array Code to create a String array: ' declare a String array with 4 elements Dim stringArray(3) As String Elements of stringArray are reference variables of data type String

Object-Oriented Application Development Using VB.NET 20 Creating a String Array Code to create four String instances and populate the array elements stringArray(0) = "Hello" stringArray(1) = "World" stringArray(2) = "Wide" stringArray(3) = "Web" A specific element can be accessed using the index of that element String methods can be invoked for String instances referenced by array elements

Object-Oriented Application Development Using VB.NET 21 Creating a String Array

Object-Oriented Application Development Using VB.NET 22 Using the ArrayList Class Major limitation of arrays: fixed size ArrayList class –Member of System.Collections namespace –Creates dynamically resizable array – the number of elements can change during runtime

Object-Oriented Application Development Using VB.NET 23 Using the ArrayList Class Code to create an instance of ArrayList class: ' create an ArrayList instance with 3 elements Dim anArrayList As ArrayList = New ArrayList(3)

Object-Oriented Application Development Using VB.NET 24 Using the ArrayList Class Code to create four instances of String class: ' create String instances Dim s1 As String = New String("Hello") Dim s2 As String = New String("World") Dim s3 As String = New String("Wide") Dim s4 As String = New String("Web")

Object-Oriented Application Development Using VB.NET 25 Using the ArrayList Class Add method is used to populate the elements When a fourth element is added, the number of elements increases automatically anArrayList.Add(s1) anArrayList.Add(s2) anArrayList.Add(s3) anArrayList.Add(s4)

Object-Oriented Application Development Using VB.NET 26 Working with Dates System namespace contains DateTime class and TimeSpan class –Instance of DateTime class contains a date value –Instance of TimeSpan class contains the difference between two dates

Object-Oriented Application Development Using VB.NET 27 Working with Dates DateTime properties –Today property gets system date and returns a DateTime instance –Now property captures the current time DateTime methods to perform arithmetic on a date value –AddMonths adds a value to the month –AddDays adds a value to the day –AddYears adds a value to the year

Object-Oriented Application Development Using VB.NET 28 Working with Dates To format a date: –Invoke its ToString method –Pass arguments that describe the desired format –For example: Code to displayed a date in the format February 15, 2003: Console.WriteLine("(MMMM dd, yyyy) is " & _ today.ToString("MMMM dd,yyyy"))

Object-Oriented Application Development Using VB.NET 29 Working with Dates Subtract method –Computes the number of days between two DateTime instances –Returns an instance of the TimeSpan class Compare method –Compares two DateTime instances –Returns –1, 0, or +1, depending on whether the first DateTime instance is less than, equal to, or greater than the second

Object-Oriented Application Development Using VB.NET 30 Formatting Numerical Output Formatting means inserting commas, decimal places, dollar signs, percent symbols, parentheses, hyphens, etc. Each primitive data type is represented by a structure, which has methods When a primitive variable is declared, certain methods associated with that variable can be invoked –For example: ToString method

Object-Oriented Application Development Using VB.NET 31 Formatting Numerical Output ToString method is used to format numeric data Format mask –A series of characters that describes the format to be used –Passed to ToString method to carry out formatting For example: s = i.ToString("$#,##0.00") Console.WriteLine("Integer 1234 with $#,##0.00 format is " & s)

Object-Oriented Application Development Using VB.NET 32 Formatting Numerical Output Using ToString method, a number can be formatted –As currency –With or without a dollar sign –With or without commas –As a percentage –As a telephone number –As a Social Security number

Object-Oriented Application Development Using VB.NET 33 Using the MessageBox Class A message box can be used to display a message and to get a response MessageBox class –Member of System.Windows.Forms namespace –Has a single method named Show Show method –Creates an instance of MessageBox class –Makes a message box appear

Object-Oriented Application Development Using VB.NET 34 Using the MessageBox Class Show method can receive up to four arguments –First argument – Message to be displayed

Object-Oriented Application Development Using VB.NET 35 Using the MessageBox Class Show method can receive up to four arguments –Second argument – Caption to be displayed

Object-Oriented Application Development Using VB.NET 36 Using the MessageBox Class Show method can receive up to four arguments –Third argument – Specifies the buttons to be displayed

Object-Oriented Application Development Using VB.NET 37 Using the MessageBox Class Show method can receive up to four arguments –Fourth argument – Specifies the type of icon displayed

Object-Oriented Application Development Using VB.NET 38 Using the MessageBox Class Return value obtained from Show method –Indicates which button was clicked by user –Is of data type DialogResult –Can be compared to specific values using an If statement

Object-Oriented Application Development Using VB.NET 39 Displaying a Form Form –A class in System.Windows.Forms namespace GuiModule.vb module contains instructions to –Instantiate GuiForm.vb Form –Make it visible and invisible GuiForm.vb –A subclass of Form –Inherits Form attributes and methods

Object-Oriented Application Development Using VB.NET 40 Summary A VB.NET namespace is a library of related classes VB.NET string data is contained in an instance of String class String class contains useful methods to manipulate string data String values are immutable ArrayList class can be used to create an array that is dynamically resizable

Object-Oriented Application Development Using VB.NET 41 Summary A DateTime instance contains a date value A TimeSpan instance contains the difference between two dates ToString method is used to format numeric data A format mask is a series of characters that describes the format to be used A message box is used to display a message and, optionally, get a response Form is a class in System.Windows.Forms namespace