Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic 2010 How to Program.  Welcome to Visual Basic 2010.  Computers process data, using sets of instructions called computer programs. 

Similar presentations


Presentation on theme: "Visual Basic 2010 How to Program.  Welcome to Visual Basic 2010.  Computers process data, using sets of instructions called computer programs. "— Presentation transcript:

1 Visual Basic 2010 How to Program

2

3

4  Welcome to Visual Basic 2010.  Computers process data, using sets of instructions called computer programs.  These programs guide computers through orderly sets of calculations and other actions that are specified by people known as computer programmers.  Today’s personal computers can perform billions of these calculations and actions per second. A person operating a desk calculator might require a lifetime to complete the same amount of work!  Today’s fastest supercomputers work so quickly that they can perform the equivalent of 150,000 actions and calculations per second for every person on the planet!

5  A computer consists of various devices referred to as hardware (for example, the keyboard, screen, mouse, hard drive, memory, DVDs and processing units).  The programs that run on a computer are referred to as software (for example, applications such as word processors, payroll systems, spreadsheets, e-mail systems, games, etc.).  Object-oriented programming (which models real-world objects with software counterparts), can greatly enhance your productivity.  The core of this book emphasizes achieving program clarity through the proven techniques of object-oriented programming (OOP) and event-driven programming.

6  Regardless of differences in physical appearance, virtually every computer may be envisioned as divided into various logical units or sections:

7 ◦ Input unit. This “receiving” section obtains information (data and computer programs) from input devices and places it at the disposal of the other units so that it can be processed. Most information is entered into computers through keyboards and mouse devices. Information also can be entered in many other ways, including by speaking to your computer, scanning images and barcodes, reading from secondary storage devices (like hard drives, CD drives, DVD drives and USB drives— also called “thumb drives”) and having your computer receive information from the Internet (such as when you download videos from YouTube™, e-books from Amazon, and the like).

8 ◦ Output unit. This “shipping” section takes information that the computer has processed and places it on various output devices to make it available for use outside the computer. Most information that is output from computers today is displayed on screens, printed on paper, played on audio players (such as Apple’s popular iPods), or used to control other devices. Computers also can output their information to networks, such as the Internet.

9 ◦ Memory unit. This rapid-access, relatively low-capacity “warehouse” section retains information that has been entered through the input unit, making it immediately available for processing when needed. The memory unit also retains processed information until it can be placed on output devices by the output unit. Information in the memory unit is volatile— it’s typically lost when the computer’s power is turned off. The memory unit is often called either memory or primary memory.

10 ◦ Arithmetic and logic unit (ALU). This “manufacturing” section performs calculations, such as addition, subtraction, multiplication and division. It also contains the decision mechanisms that allow the computer, for example, to compare two items from the memory unit to determine whether they’re equal. In today’s systems, the ALU is usually implemented as part of the next logical unit, the CPU.

11 ◦ Central processing unit (CPU). This “administrative” section coordinates and supervises the operation of the other sections. The CPU tells the input unit when information should be read into the memory unit, tells the ALU when information from the memory unit should be used in calculations and tells the output unit when to send information from the memory unit to certain output devices. Many of today’s computers have multiple CPUs and, hence, can perform many operations simultaneously—such computers are called multiprocessors. A multi-core processor implements multiprocessing on a single integrated circuit chip—for example a dual-core processor has two CPUs and a quad-core processor has four CPUs.

12 ◦ Secondary storage unit. This is the long-term, high-capacity “warehousing” section. Programs or data not actively being used by the other units normally are placed on secondary storage devices (for example, your hard drive) until they’re needed again, possibly hours, days, months or even years later. Therefore, information on secondary storage devices is said to be persistent—it is preserved even when the computer’s power is turned off. Secondary storage information takes much longer to access than information in primary memory, but the cost per unit of secondary storage is much less than that of primary memory. Examples of secondary storage devices include CDs, DVDs and flash drives (sometimes called memory sticks), which can hold hundreds of millions to billions of characters.

13  In 1977, Apple Computer—creator of today’s popular Mac personal computers, iPod digital music players, iPhones and iPads —popularized personal computing.  In 1981, IBM, the world’s largest computer vendor, introduced the IBM Personal Computer, legitimizing personal computing in business, industry and government.  These computers were “stand-alone” units—people transported disks back and forth between computers to share information (creating a “sneakernet”).  These machines could be linked together in computer networks, sometimes over telephone lines and sometimes in local area networks (LANs) within an organization.

14  This led to distributed computing, in which an organization’s computing is distributed over networks to the sites where the organization’s work is performed.  Information is shared across computer networks, where computers called servers offer a common data store and services that may be used by client computers throughout the network, hence the term client/server computing.  In Chapter 13, we’ll build Internet-based applications; we’ll talk about web servers (computers that distribute content over the web) and web clients (computers that request and receive the content offered up by web servers).

15  Every year or two, the computing power of computers has approximately doubled without any increase in price.  This often is called Moore’s Law, named after the person who first identified and explained the trend, Gordon Moore, co-founder of Intel—the company that manufactures the vast majority of the processors in today’s personal computers.  Moore’s Law is especially true in relation to the amount of memory that computers have for programs and data, the amount of secondary storage (such as disk storage) they have, and their processor speeds—the speeds at which computers execute their programs (that is, do their work).

16  In the mid-1980s, Microsoft developed the Windows operating system, consisting of a graphical user interface built on top of DOS (a personal computer operating system that users interacted with by typing commands).  The Windows operating system became incredibly popular after the 1993 release of Windows 3.1, whose successors, Windows 95 and Windows 98, virtually cornered the desktop operating systems market by the late 1990s.  These operating systems, which borrowed from many concepts (such as icons, menus and windows) popularized by early Apple Macintosh operating systems, enabled users to navigate multiple applications simultaneously.

17  Microsoft entered the corporate operating systems market with the 1993 release of Windows NT.  Windows XP, was released in 2001 and combined Microsoft’s corporate and consumer operating system lines.  Windows Vista, released in 2007, offered the attractive Aero user interface, many enhancements and new applications.  A key focus of Windows Vista was enhanced security.

18  Windows 7 is Microsoft’s latest operating system—its features include enhancements to the Aero user interface, faster startup times, further refinement of Vista’s security features, touch screen and multi-touch support, and more.  This book is intended for Windows XP, Windows Vista and Windows 7 users.  Windows is the world’s most widely used operating system.

19  Although hundreds of computer languages are in use today, they can be divided into three general types: ◦ Machine languages ◦ Assembly languages ◦ High-level languages

20  Machine Languages ◦ A computer can directly understand only its own machine language, which is defined by the computer’s hardware design. ◦ Machine languages generally consist of streams of numbers (ultimately reduced to 1s and 0s) that instruct computers how to perform their most elementary operations. ◦ Only 1s and 0s are used in the binary number system. ◦ Machine-language programs are called binaries. ◦ Machine languages are machine dependent—a particular machine language can be used on only one type of computer.

21  The following section of an early machine-language program, which adds overtime pay to base pay and stores the result in gross pay, demonstrates the incomprehensibility of machine language to humans:  +1300042774 +1400593419 +1200274027

22  Assembly Languages ◦ As the popularity of computers increased, machine-language programming proved to be slow and error prone. ◦ Instead of using the strings of numbers that computers could directly understand, programmers began using English-like abbreviations (called mnemonics) to represent the computer’s basic operations. ◦ These abbreviations formed the basis of assembly languages. ◦ Translator programs called assemblers convert assembly- language programs to machine language at computer speeds.

23  The following section of an assembly-language program also adds overtime pay to base pay and stores the result in gross pay, but the steps are clearer to humans than in the machine-language example:  LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

24  High-Level Languages ◦ The speed at which programmers could write programs increased rapidly with the creation of assembly languages, but these languages still require many instructions to accomplish even simple tasks. ◦ To speed up the programming process, high-level languages (in which single program statements accomplish more substantial tasks) were developed. ◦ Translator programs called compilers convert high-level- language programs into machine language.

25  High-level languages enable you to write instructions that look almost like everyday English and contain common mathematical notations.  For example, a payroll application written in a high- level language might contain a statement such as  grossPay = basePay + overTimePay  Visual Basic is one of the world’s most popular high- level programming languages.

26  Visual Basic evolved from BASIC (Beginner’s All-purpose Symbolic Instruction Code), developed in the mid-1960s at Dartmouth College as a language for introducing novices to fundamental programming techniques.  When Bill Gates founded Microsoft Corporation in the 1970s, he implemented BASIC on several early personal computers.  In the late 1980s and the early 1990s, Microsoft developed its Windows graphical user interface (GUI)—the visual part of the operating system with which users interact.

27  With the creation of the Windows GUI, the natural evolution of BASIC was to Visual Basic, introduced by Microsoft in 1991 to make programming Windows applications easier.  Until Visual Basic appeared, developing Microsoft Windows-based applications was a difficult process.  Visual Basic programs are created with the use of a collection of software tools called an Integrated Development Environment (IDE).  With Microsoft’s Visual Studio 2010 IDE, you can write, run, test and debug Visual Basic programs quickly.

28  The latest versions of Visual Basic are fully object oriented.  Visual Basic is event driven —you’ll write programs that respond to user-initiated events such as mouse clicks, keystrokes and timer expirations.  It’s a visual programming language—in addition to writing program statements to build portions of your applications, you’ll also use Visual Studio’s graphical user interface to conveniently drag and drop predefined objects like buttons and textboxes into place on your screen, and label and resize them.  Visual Studio will write much of the GUI code for you.

29  The C programming language was developed in the early 1970s.  C first gained widespread recognition as the development language of the UNIX operating system.  C is a hardware-independent language, and, with careful design, it is possible to write C programs that are portable to most computers.

30  C++, developed in the early 1980s, provides several features that “spruce up” the C language, and, more importantly, capabilities for object-oriented programming (OOP).  Objects are reusable software components that model items in the real world.  A modular, object-oriented approach to design and implementation can make software development groups much more productive.

31  The Objective-C programming language, also developed in the early 1980s, added capabilities for object-oriented programming (OOP) to the C programming language.  It eventually became the software development language for Apple’s Macintosh.  Its use has exploded as the app development language for Apple’s wildly popular iPod, iPhone and iPad consumer devices.  Objective-C has access to the Cocoa frameworks (powerful libraries of prebuilt components), enabling you to develop apps quickly.

32  Microprocessors are having a profound impact in intelligent consumer electronic devices.  Recognizing this, Sun Microsystems in 1991 funded an internal corporate research project that resulted in the development of a C++-based language, which Sun eventually called Java.  As the World Wide Web exploded in popularity in 1993, Sun saw the possibility of using Java to add dynamic content (for example, interactivity, animations and the like) to web pages.  Sun announced the language in 1995.  This generated immediate interest in the business community because of the commercial potential of the web.

33  Java is now used to develop large-scale enterprise applications, to enhance the functionality of web servers (the computers that provide the content we see in our web browsers), to provide applications for consumer devices (such as cell phones, pagers and personal digital assistants) and for many other purposes.  Visual Basic 2010 is similar in capability to Java.  In 2000, Microsoft announced the C# (pronounced “C- Sharp”) programming language—created specifically for the.NET platform.

34  C# has roots in C, C++ and Java.  Like Visual Basic, C# is object oriented and has access to a powerful class library of prebuilt components, enabling you to develop applications quickly  Visual Basic and C# share the.NET Framework Class Library.  Both languages have similar capabilities to Java and are appropriate for the most demanding application development tasks, especially for building today’s enterprise applications, and web-based and mobile applications.

35  In the late 1960s, ARPA—the Advanced Research Projects Agency of the Department of Defense—rolled out plans to network the main computer systems of some universities and research institutions.  ARPA implemented what quickly became known as the ARPAnet, the grandparent of today’s Internet.  Its main benefit proved to be the capability for quick and easy communication via e-mail.  This is true even on today’s Internet, with e-mail, instant messaging and file transfer allowing billions of people worldwide to communicate with each other.

36  Businesses rapidly realized that by using the Internet, they could improve their operations and offer new and better services to their clients.  This generated fierce competition among communications carriers and hardware and software suppliers to meet the increased infrastructure demand.  As a result, bandwidth—the information-carrying capacity of communications lines—on the Internet has increased tremendously, while hardware costs have plummeted.

37  The World Wide Web is a collection of hardware and software associated with the Internet that allows computer users to locate and view multimedia-based documents (documents with various combinations of text, graphics, animations, audios and videos) on almost any subject.

38  In 1989, Tim Berners-Lee of CERN (the European Organization for Nuclear Research) began to develop a technology for sharing information over the Internet via “hyperlinked” text documents.  Berners-Lee called his invention the HyperText Markup Language (HTML).  He also wrote communication protocols such as HyperText Transfer Protocol (HTTP) to form the backbone of his new hypertext information system, which he referred to as the World Wide Web.

39  In 1994, Berners-Lee founded the World Wide Web Consortium to develop technologies for the web.  One of the W3C’s goals is to make the web accessible to everyone regardless of disabilities, language or culture.  In the past, most computer applications ran on computers that were not connected to one another.  Today’s applications can be written to communicate among the world’s computers via the Internet and the web.  This is the focus of Microsoft’s.NET strategy.  We’ll discuss how to build web applications with Visual Basic.

40  HTML’s lack of extensibility (the ability to change or add features) frustrated developers, and its ambiguous definition allowed erroneous HTML to proliferate.  The need for a standardized, fully extensible and structurally strict language was apparent.  As a result, XML was developed by the W3C.  Data independence, the separation of content from its presentation, is the essential characteristic of XML.

41  Because XML documents describe data, any application conceivably can process them.  Software developers are integrating XML into their applications to improve web functionality and interoperability.  For example, it is increasingly being employed in databases—the structure of an XML document enables it to be integrated easily with database applications.

42  It’s likely that XML will become the universal technology for data representation.  All applications employing XML would be able to communicate with one another, provided that they could understand their respective XML markup schemes, or vocabularies.  Microsoft’s.NET technologies use XML to mark up and transfer data over the Internet, and to enable software components to interoperate.

43  In 2000, Microsoft announced its.NET initiative, a broad new vision for using the Internet and the web in the development, engineering, distribution and use of software. .NET permits developers to create applications in any.NET-compatible language (such as Visual Basic, C# and others).  Part of the initiative includes Microsoft’s ASP.NET technology, which allows you to create web applications.  The.NET strategy extends the idea of software reuse to the Internet by allowing programmers to concentrate on their specialties without having to implement every component of every application.

44  Visual programming (which you’ll learn throughout this book) has become popular because it enables you to create Windows and web applications easily, using such prepackaged controls as buttons, textboxes and scrollbars.  The Microsoft.NET Framework executes applications, contains a class library (called the.NET Framework Class Library) and provides many other programming capabilities that you’ll use to build Visual Basic applications.

45  The details of the.NET Framework are found in the Common Language Infrastructure (CLI), which contains information about the storage of data types (that is, data that has predefined characteristics such as a date, percentage or currency amount), objects and so on.  The CLI has been standardized, making it easier to create the.NET Framework for other platforms.  This is like publishing the blueprints of the framework—anyone can build it by following the specifications.

46  The Common Language Runtime (CLR) is another central part of the.NET Framework—it executes.NET programs.  Programs are compiled into machine-specific instructions in two steps.

47  First, the program is compiled into Microsoft Intermediate Language (MSIL), which defines instructions for the CLR.  Code converted into MSIL from other languages and sources can be woven together by the CLR.  The MSIL for an application’s components is placed into the application’s executable file.  When the application executes, another compiler (known as the just-in-time compiler or JIT compiler) in the CLR translates the MSIL in the executable file into machine- language code (for a particular platform), then the machine- language code executes on that platform.

48  If the.NET Framework exists (and is installed) for a platform, that platform can run any.NET program.  The ability of a program to run (without modification) across multiple platforms is known as platform independence.  Code written once can be used on another type of computer without modification, saving time and money.  In addition, software can target a wider audience— previously, companies had to decide whether converting their programs to different platforms (sometimes called porting) was worth the cost.  With.NET, porting programs is no longer an issue (at least once.NET itself has been made available on the platforms).

49  The.NET Framework also provides a high level of language interoperability.  Programs written in different languages (for example, Visual Basic and C#) are all compiled into MSIL—the different parts can be combined to create a single unified program.  MSIL allows the.NET Framework to be language independent, because.NET programs are not tied to a particular programming language.

50  The.NET Framework Class Library can be used by any.NET language.  The library contains a variety of reusable components, saving you the trouble of creating new components.  This book explains how to develop.NET software with Visual Basic.

51  The Advanced Painter application allows you to draw on the screen with different brush sizes and colors.  The elements and functionality you see in this application are typical of what you’ll learn to program in this text.

52  The following steps show you how to test-drive the application. ◦ Checking your setup. Confirm that you’ve set up your computer properly by reading the Before You Begin section located after the Preface. ◦ Locating the application directory. Open a Windows Explorer window and navigate to the C:\Examples\ch01 directory (Fig. 1.1)—we assume you placed the examples in the C:\Examples folder.

53

54  Running the Advanced Painter application. Now that you’re in the proper directory, double click the file name AdvancedPainter.exe (Fig. 1.1) to run the application (Fig. 1.2). ◦ [Note: Depending on your system configuration, Windows Explorer might not display file name extensions. To display file name extensions (like.exe in Fig. 1.1), type Alt + T in Windows Explorer to open the Tools menu, then select Folder options…. In the Folder Options window, select the View tab, uncheck Hide extensions for known file types and click OK.]  Figure 1.2 labels several graphical elements—called controls.

55

56  These include GroupBox es, RadioButton s, a Panel and Button s (these controls and many others are discussed in depth throughout the text).  The application allows you to draw with a red, blue, green or black brush of small, medium or large size.  You can also undo your previous operation or clear the drawing to start from scratch.  By using existing controls—which are objects—you can create applications faster than if you had to write all the code.  The brush’s properties, selected in the RadioButton s labeled Black and Medium, are default settings—the initial settings you see when you first run the application.

57  Now you’ll choose your own settings as a user of this application. ◦ Changing the brush color and size. Click the RadioButton s labeled Red to change the color of the brush and Small to change the size of the brush. Position the mouse over the white Panel, then press and hold down the left mouse button to draw with the brush. Draw flower petals, as shown in Fig. 1.3. Then click the RadioButton labeled Green to change the color of the brush again.

58

59 ◦ Changing the brush size. Click the RadioButton labeled Large to change the size of the brush. Draw grass and a flower stem, as shown in Fig. 1.4.

60

61 ◦ Finishing the drawing. Click the Blue and Medium RadioButton s. Draw raindrops, as shown in Fig. 1.5, to complete the drawing. ◦ Closing the application. Close your running application by clicking its close box, (Fig. 1.5).

62

63  Object-oriented programming dramatically improved the software development process.  Object technology is a packaging scheme for creating meaningful software units.  There are date objects, time objects, paycheck objects, invoice objects, automobile objects, people objects, audio objects, video objects, file objects, record objects and so on.  On your computer screen, there are button objects, textbox objects, menu objects and many more.  Almost any noun can be represented as a software object.  Objects have attributes (also called properties), such as color, size and speed; and perform actions (also called methods or behaviors), such as moving, sleeping or drawing.

64  Classes are types of related objects.  For example, all cars belong to the “car” class, even though individual cars vary in make, model, color and options.  A class specifies the general format of its objects, and the attributes and actions of an object depend on its class.  An object is related to its class in much the same way as a building is related to its blueprint.  Contractors can build many buildings from the same blueprint. Programmers can instantiate many objects from one class.  With object technology, properly designed classes can be reused on future projects.

65  Some organizations report that another key benefit they get from object-oriented programming is the production of software that’s better organized and has fewer maintenance requirements than software produced with earlier technologies.  Object orientation allows you to focus on the “big picture.” Instead of worrying about the minute details of how reusable objects are implemented, you can focus on the behaviors and interactions of objects.

66  A road map that showed every tree, house and driveway would be difficult, if not impossible, to read.  When such details are removed and only the essential information (roads) remains, the map becomes easier to understand.  In the same way, an application that is divided into objects is easy to understand, modify and update because it hides much of the detail.  Visual Basic is one of the world’s most widely used object-oriented languages.

67  Basic Object-Technology Concepts ◦ Object-oriented design (OOD) models software in terms similar to those that people use to describe real-world objects. ◦ It takes advantage of class relationships, where objects of a certain class, such as a class of vehicles, have the same characteristics—cars, trucks, little red wagons and roller skates have much in common. ◦ OOD employs inheritance relationships, where new classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. ◦ An object of class “convertible” certainly has the characteristics of the more general class “automobile,” but more specifically, the roof goes up and down.

68  Object-oriented design provides a natural and intuitive way to view the software design process—namely, modeling objects by their attributes, behaviors and interrelationships, just as we describe real-world objects.  Objects communicate via messages.  A bank-account object may receive a message to decrease its balance by a certain amount because the customer is withdrawing that amount of money.  OOD encapsulates (that is, wraps) attributes and operations (behaviors) into objects—an object’s attributes and operations are intimately tied together.

69  Objects have the property of information hiding.  This means that objects may know how to communicate with one another across well-defined interfaces, but they’re not allowed to know how other objects are implemented— implementation details are hidden in the objects.  You can drive a car, for example, without knowing how engines, transmissions, brakes and exhaust systems work internally—as long as you know how to use the accelerator pedal, the brake pedal, the steering wheel and so on.  Information hiding is crucial to good software engineering.

70  Classes, Fields and Methods ◦ As a Visual Basic programmer, you’ll create your own classes. ◦ Each class contains data as well as the set of methods that manipulate that data and provide services to clients (that is, other classes that use the class). ◦ The data components of a class are called attributes or fields. ◦ For example, a bank account class might include an account number and a balance. ◦ The operation components of a class are called methods. ◦ A bank-account class might include methods to make a deposit (increase the balance), make a withdrawal (decrease the balance) and inquire what the current balance is.

71  Classes are to objects as blueprints are to houses—a class is a “plan” for building objects of the class.  Just as we can build many houses from one blueprint, we can instantiate (create) many objects from one class.  You cannot cook meals in the kitchen of a blueprint, but you can cook meals in the kitchen of a house.  Packaging software as classes makes it possible for future software systems to reuse the classes.

72

73  You won’t build your own classes until Chapter 9, but you will be using existing classes and making objects of those classes throughout the entire book, including the early chapters.  With object technology, you can build much of the new software you’ll need by combining existing classes, just as automobile manufacturers combine standardized interchangeable parts.  Each class you create will have the potential to become a valuable software asset that you and other programmers can reuse to speed future software development efforts.

74  Introduction to Object-Oriented Analysis and Design (OOAD) ◦ How will you create the code for your programs? Perhaps, like many beginning programmers, you’ll simply turn on your computer and start typing. ◦ This approach may work for small programs (like the ones we pre-sent in the early chapters of the book), but what if you were asked to create a software system to control thousands of automated teller machines for a major bank? ◦ Or what if you were asked to work with thousands of software developers building the next generation of the U.S.air traffic control system? For projects so large and complex, you could not simply sit down and start writing programs.

75  To create the best solutions, you should follow a detailed process for determining your project’s requirements (what your system is supposed to do) and developing a design that satisfies them (deciding how your system should do it).  Ideally, you would go through this process and carefully review the design (and have your design reviewed by other software professionals) before writing any code.  If this process involves analyzing and designing your system from an object-oriented point of view, it’s called object-oriented analysis and design (OOAD).

76  Proper analysis and design can help avoid an ill- planned system development approach that has to be abandoned partway through its implementation, possibly wasting considerable time, money and effort.  Although many different OOAD processes exist, a single graphical language known as the UML (Unified Modeling Language) for communicating the results of any OOAD process has come into wide use.  We introduce simple UML diagrams in the early chapters and a richer treatment in the optional ATM OOD case study.


Download ppt "Visual Basic 2010 How to Program.  Welcome to Visual Basic 2010.  Computers process data, using sets of instructions called computer programs. "

Similar presentations


Ads by Google