Classes and Class Libraries Examples and Hints November 9, 2010 1.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
XP 1 Developing a Basic Web Site Tutorial 2: Web Site Structures & Links.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
1 Chapter 12 Working With Access 2000 on the Internet.
XP Adding Hypertext Links to a Web Page. XP Objectives Create hypertext links between elements within a Web page Create hypertext links between Web pages.
Inheritance, Shared. Projectiles Program Demonstrates – Inheritance – MustInherit – Shared vs. Non-shared methods A variation on the Multiball example.
Graphics Procedure (IDrawable) 1. Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw.
VBDB Connecting VB Programs to a Database. Writing VB Code for INSERT INTO Creating user-friendly data-entry forms is easy in VB. A typical data-entry.
ASP.NET Programming with C# and SQL Server First Edition
VB Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
Create a Web Site with Frames
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Creating Web Page Forms
XP New Perspectives on Microsoft Access 2002 Tutorial 71 Microsoft Access 2002 Tutorial 7 – Integrating Access With the Web and With Other Programs.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
PubMed/How to Search, Display, Download & (module 4.1)
1 Working with MS SQL Server II. 2 The sqlcmd Utility Command line utility for MS SQL Server databases. Previous version called osql Available on classroom.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Tutorial 11 Using and Writing Visual Basic for Applications Code
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
IE 411/511: Visual Programming for Industrial Applications
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
PHP meets MySQL.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
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.
1 Working with MS SQL Server Textbook Chapter 14.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
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.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Microsoft Visual C++.NET Chapter 51 Introduction to Classes.
Robin Mullinix Systems Analyst GeorgiaFIRST Financials PeopleSoft Query: The Next Step.
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
Database Handling, Sessions, and AJAX. Post Back ASP.NET Functionality The IsPostBack method in ASP.NET is similar to the BlackBerry.refresh method –IsPostBack.
Chapter 4: Working with ASP.NET Server Controls OUTLINE  What ASP.NET Server Controls are  How the ASP.NET run time processes the server controls on.
XP 1 HTML Tutorial 2: Developing a Basic Web Site.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Chapter 1 Getting Started With Dreamweaver. Exploring the Dreamweaver Workspace The Dreamweaver workspace is where you can find all the tools to create.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Implementing and Using the SIRWEB Interface Setup of the CGI script and web procfile Connecting to your database using HTML Retrieving data using the CGI.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
The World Wide Web. What is the worldwide web? The content of the worldwide web is held on individual pages which are gathered together to form websites.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
VB.NET and Databases. ADO.NET VB.Net allows you many ways to connect to a database. The technology used to interact with a database or data source is.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Computing and Information Technology Building a Web Browser
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
More Selections BIS1523 – Lecture 9.
Building Web Applications
Tonga Institute of Higher Education
CMPE212 – Reminders Assignment 2 due next Friday.
Presentation transcript:

Classes and Class Libraries Examples and Hints November 9,

Complex Number Class A CLASSic example of a Class. Demonstrates a good use of ToString. Demonstrates operator overloading. 2

Operator overloading Allows you to define common operators for your custom classes. – What does it mean for two objects of your class to be equal? – How do you add two objects? Multiply? – How do you convert an object of your class to another type? 3

Show the Program 4

Class Complex: The Basics 5 I got this code from the Stevens book. Note that Stevens cheats—he uses Public variables instead of properties for Re and Im. Public variables work just like our standard Public properties, but they do not allow for adding validation code. If you anticipate ever adding on to your class, you should use Public properties with with Private variables, like you did in assignment 3.

ToString Complex numbers are generally written as a + bi where a is the real part and b the imaginary part. The Complex class incorporates this format into its ToString function: 6

Operator Overloads You can add operator functions to your classes, such as Equals, Plus, Minus, Times, etc. However, VB allows you to define what the standard operator symbols (=, +, -, *, etc.) mean for your class. This makes your code easier to read AND write. 7

Equals Being able to test equality is frequently important. In your custom classes, you can define what “=“ means. Note that if you define “=“, you must also define “<>”. Note also that “>” and “<“ are not defined, since they are not well defined for complex numbers. All operator overloads must be declared Public Shared. “Shared” means that the operator belongs to the class as a whole, not to individual objects. The equals that is being overloaded here is the comparison equals, the one that comes after “If”, not the assignment equals. Remember that for objects, the assignment equals works on references (addresses), not the objects themselves. 8

Do the Math 9

Conversions VB allows you to define conversions from your class by overloading CType. The code below effectively defines CDbl for the Complex class as being the absolute value: 10

Absolute Value as ReadOnly Property Personally, I would rather see absolute value implemented as a property, not a conversion. The property is ReadOnly since it is not something that you could assign directly; it depends on the real and imaginary parts of the number. For example, the complex numbers 1, i, -1, and –i all have the same absolute value. 11

Building on the Complex class Can you think of other properties, functions, operators, constructors, conversions, etc. that could be added to the Complex class? Some classes that might be similar to Complex? – Vector – Matrix – Field (electric, gravitational) 12

Wrapper Classes VB’s.NET framework contains lots of wrapper classes. A wrapper class encapsulates some difficult or tedious code which performs something useful into a simple interface. For example, it would take a lot of code to write your own web browser into your program. Fortunately, Microsoft has provided the WebBrowser control (in the ToolBox). With the WebBrowser control (a class, of course), you get pretty much all of Internet Explorer’s functionality with just a few lines of code. 13

WebBrowser Control The VB Toolbox offers a WebBrowser control. This is basically a customizable version of Internet Explorer that you can build into your programs. Possible uses: – Display pictures from the web (as an alternative to the PictureBox control) – Display help files – Allow users of your program to link to specific web pages, while preventing access to other pages (or general browsing) 14

WebBrowser Demo Open the “HTML Lecture” VB project. Click on WebBrowser Demo. This form will appear: 15

The WebBrowser Form frmBrowser contains a SplitContainer control. In the top half is a WebBrowser control. In the bottom is a TextBox. When the WebBrowser navigates to a new web page, the TextBox displays the HTML code for that page. 16

Open New Browser Code 17

Go To Google Code 18

Navigation Code The WebBrowser control’s “AllowNavigation” property determines if the user can use the browser as a true web browser or not. If set to False, they will not be able to connect to linked pages by clicking on hyperlinks. Set AllowNavigation to False if you want to restrict the user to web pages related to your program. 19

Getting the HTML source code If you want to retrieve the source code (usually HTML or XML) from a web page, use the WebBrowser’s DocumentText property. The above code demonstrates this. The code is placed in the WebBrowser’s Navigated event; that is, it waits until the new page is completely loaded. Once you have retrieved the DocumentText, you can search for keywords or values, such as a stock price or sports score, using the various String functions. 20

DbConn: Another Wrapper Class Most VB textbooks show you how to connect to a database and retrieve data, typically using code like this: 21

DbConn This code is tedious, difficult to understand or remember. As written, it works only with Access 2007 databases (Microsoft.ACE.OLEDB.12.0). The function encapsulates the code to some degree, but we can get greater functionality and flexibility by incorporating it into a class. I did this about three years ago, both for my work at UMTRI and for this course. 22

DbConn: Public Interface Public Sub New(ByVal FileName As String) Public Sub New(ByVal ServerName As String, ByVal DatabaseName As String) – These two constructors identify the database to be connected to, and test the connection. If the database cannot be located or it can’t be open, the constructor raises an exception. – The first constructor (one parameter) is for Access databases; – The second (overloaded) constructor (two parameters) is for SQL Server databases. 23

OpenDatabaseConnection, CloseDatabaseConnection Public Sub OpenDatabaseConnection() Public Sub CloseDatabaseConnection() – There are time and availability costs to opening a database and leaving it open. – In general, if you need to run a lot of queries in a row, you should open the connection once, run all the queries, and then close the connection. – I didn’t show you these subs for assignment 2, but you may want to use them if you find your data-connected program running slowly. – Both GetDataTable and ExecuteSQL leave the connection in the condition that they found it (which defaults to closed). 24

Running the Queries – You know how to use the remaining parts of DbConn’s user interface: Public Function GetDataTable(ByVal sql As String) As DataTable Public Sub ExecuteSQL(ByVal sql As String) 25

Connection Encapsulated Together, the public interface of DbConn encapsulates all of the complex code we saw earlier. That interface is,again: – Public Sub New(ByVal FileName As String) – Public Sub New(ByVal ServerName As String, ByVal FileName As String) – Public Sub OpenDatabaseConnection() – Public Sub CloseDatabaseConnection() – Public Function GetDataTable(ByVal sql As String) As DataTable – Public Sub ExecuteSQL(ByVal sql As String) 26