39
Microsoft Visual Basic: Reloaded Chapter One An Introduction to Visual Basic

visual_basic_lecture1.ppt

Embed Size (px)

Citation preview

  • Microsoft Visual Basic: Reloaded Chapter OneAn Introduction to Visual Basic

    2009 Pearson Education, Inc. All rights reserved.

    OverviewWhat Is a Computer?Machine, Assembly and High-Level LanguagesVisual Basic & Other High-Level LanguagesObject TechnologyThe Internet and the World Wide WebIntroduction to Microsoft .NETLanguage and SyntaxVisual Studio IDESolutions and ProjectsCreating a New ProjectExamples*

    2009 Pearson Education, Inc. All rights reserved.

    *What Is a Computer?A computer is a device that can perform calculations and make logical decisions much faster than humans can.Computers process data, using sets of instructions called computer programs. These programs guide computers through orderly sets of actions that are specified by people known as computer programmers.

    2009 Pearson Education, Inc. All rights reserved.

    *What Is a Computer?A computer is composed of various devices known as hardware:keyboardscreenmousehard drivesmemoryDVD drivesprinterprocessing units The programs that run on a computer are referred to as software.

    2009 Pearson Education, Inc. All rights reserved.

    *Computer ComponentsComputers can be thought of as being divided into six units:Input unit: This receiving section of the computer obtains information from input devices.Input can come from devices such as the keyboard and the mouse. Output unit: This shipping section of the computer takes information that the computer has processed and places it on various output devices.Output can be displayed on screens, printed on paper, played on audio/video devices, and transmitted over the Internet.

    2009 Pearson Education, Inc. All rights reserved.

    *Computer ComponentsMemory unit: This warehouse section of the computer stores data while an application is running. Its information is immediately available for processing. To be executed, computer programs must be in memory. The memory unit retains information until it can be sent to output devices. Often, the memory unit is called either memory or primary memory. Random-access memory (RAM) is an example of primary memory. Primary memory is usually volatile, which means that it is erased when the machine is powered off.

    2009 Pearson Education, Inc. All rights reserved.

    *Computer ComponentsCentral processing unit (CPU): The CPU supervises the operation of the other sections.Arithmetic and logic unit (ALU): The ALU (a part of the CPU) performs calculations and makes decisions.Secondary storage unit: This unit is the warehousing section of the computer.Devices such as hard drives, CD-ROM drives, DVD drives, and USB memory sticks are secondary storage units.These normally hold programs or data that other units are not actively being used. The computer can retrieve this information when it is needed later in time. Secondary storage is nonvolatile. Information in secondary storage takes much longer to access than information in primary memory.

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages Programmers write instructions in programming languages. Some of these are directly understandable by computers, and others require intermediate translation steps.Computer languages that are in use today can be divided into three general types:machine languagesassembly languageshigh-level languages

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages A computer can directly understand only its own machine language.As the natural language of a particular computer, machine language is defined by the computers hardware design. Machine languages are machine dependent.Machine languages generally consist of streams of numbers (ultimately reduced to 1s and 0s in the binary number system).

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages The following section of a machine-language program demonstrates the incomprehensibility of machine language to humans:+1300042774 +1400593419 +1200274027

    Machine-language programming proved to be slow and error prone.

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages Programmers began using English-like abbreviations to represent the computers basic operations.These abbreviations formed the basis of assembly languages. LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages Translator programs called assemblers convert assembly-language programs to machine language.Although it is clearer to humans, computers cannot understand assembly-language code until it is translated into machine language. Assembly languages still require many instructions to accomplish even the simplest tasks.

    2009 Pearson Education, Inc. All rights reserved.

    *Machine, Assembly and High-Level Languages To speed up the programming process, high-level languages were developed.Programs called compilers convert high-level-language programs into machine language.High-level languages look almost like everyday English and contain common mathematical notations.grossPay = basePay + overTimePayVisual Basic is one of the worlds most popular high-level programming languages.

    2009 Pearson Education, Inc. All rights reserved.

    *Visual BasicVisual Basic evolved from BASIC (Beginners All-purpose Symbolic Instruction Code), which was developed as a language for writing simple programs quickly and easily.When Bill Gates founded Microsoft Corporation in the 1970s, he implemented BASIC on several early personal computers.

    2009 Pearson Education, Inc. All rights reserved.

    *Visual BasicIn the late 1980s and the early 1990s, Microsoft developed the Microsoft Windows graphical user interface (GUI). Visual Basic was introduced by Microsoft in 1991 to make programming Windows applications easier.

    2009 Pearson Education, Inc. All rights reserved.

    *Visual BasicVisual Basic is a so-called object-oriented, event-driven visual programming language.Programs are created with the use of a software tool called an Integrated Development Environment (IDE). (Visual Studio)The latest versions of Visual Basic are fully object oriented and respond to user-initiated events such as mouse clicks, keystrokes and timers. In Visual Studio, it is convenient to make programs by dragging and dropping predefined objects like buttons and textboxes.

    2009 Pearson Education, Inc. All rights reserved.

    *Visual BasicMicrosoft introduced its .NET strategy in 2000.The .NET platform allows applications to be distributed to a variety of devices.Software components created in different .NET programming languages can communicate with one another.In 2000, Microsoft announced C#. The C# programming language was designed specifically for the .NET platform. Like Visual Basic, C# is object oriented and has access to .NETs library.

    2009 Pearson Education, Inc. All rights reserved.

    *Object TechnologyObject technology is a packaging scheme for creating meaningful software units.Almost any noun can be reasonably represented as a software object.Objects:have properties such as color, size and weightperform actions such as moving, sleeping or drawing A class specifies the general format of its objects, and the properties and actions available to an object depend on its class.

    2009 Pearson Education, Inc. All rights reserved.

    *Object TechnologyProcedural programming languages focused on actions (verbs) rather than objects (nouns).Object-oriented languages more naturally reflects the way in which we perceive the world.This has resulted in significant productivity gains.Properly designed classes can be reused on future projects Using libraries of classes reduces the amount of effort required to implement new systemsThe production of software is more understandable because it is better organized and has fewer maintenance requirements.

    2009 Pearson Education, Inc. All rights reserved.

    *Object TechnologyInstead of worrying about the details of how objects are implemented, you can focus on the behaviors and interactions of objects.Visual Basic is one of the worlds most widely used object-oriented languages.

    2009 Pearson Education, Inc. All rights reserved.

    *The Internet and the World Wide WebIn the late 1960s, ARPA rolled out plans to network the main computer systems of ARPA-funded universities and research institutions.This became known as the ARPAnet, the grandparent of todays Internet.Its main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail).

    2009 Pearson Education, Inc. All rights reserved.

    *The Internet and the World Wide WebThe protocol for communicating over the ARPAnet became known as the Transmission Control Protocol (TCP).TCP ensured that messages, consisting of pieces called packets, were properly routed from sender to receiver, arrived intact and were assembled in the correct order.One challenge was to enable different networks to communicate with each other.ARPA accomplished this by developing the Internet Protocol (IP), which created the current architecture of the Internet.The combined set of protocols is now called TCP/IP.

    2009 Pearson Education, Inc. All rights reserved.

    *The Internet and the World Wide WebThe World Wide Web is a collection of hardware and software associated with the Internet.In 1989, Tim Berners-Lee of CERN began to develop a technology for sharing information via hyperlinked text documents called HyperText Markup Language (HTML).He also wrote communication protocols such as HyperText Transfer Protocol (HTTP).In October 1994, Berners-Lee founded the World Wide Web Consortium, devoted to developing technologies for the World Wide Web.

    2009 Pearson Education, Inc. All rights reserved.

    *The Internet and the World Wide WebThe Internet and the web will surely be listed among the most important creations of humankind.Todays applications can be written to communicate among the worlds computers. This is the focus of Microsofts .NET strategy.The Internet and the World Wide Web:make information instantly and conveniently accessible,and allow individuals and small businesses to achieve worldwide exposure.

    2009 Pearson Education, Inc. All rights reserved.

    *Introduction to Microsoft .NET In June 2000, Microsoft announced its .NET initiative The .NET initiative permits developers to create applications in any .NET-compatible language.Part of the initiative includes Microsofts ASP.NET. The .NET strategy extends the idea of software reuse to the Internet.Visual programming enables .NET programmers to create applications using prepackaged graphical components.

    2009 Pearson Education, Inc. All rights reserved.

    .NET FrameworkThe Microsoft .NET Framework:executes applications and web servicescontains a class library (Framework Class Library)and provides many other programming capabilities. The .NET framework is a platform with which you can develop software applications and libraries called managed applications; it provides you with the compiler and tools you need to build, debug, and execute managed applications.Prior to this approach, unmanaged applications had to manage their own services which sometimes led to security holes and data corruption.

    *

    2009 Pearson Education, Inc. All rights reserved.

    .NET FrameworkCLR: Common LanguageWCF: Windows Communication FoundationWPF: Windows Presentation FoundationWF: Windows Workflow FoundationLINQ: Language Integrated QueryCardspace: Manages online identitiesAJAX: Asynchronous JavaScript and XMLREST: Representational State Transfer

    *

    2009 Pearson Education, Inc. All rights reserved.

    .NET Framework*

    2009 Pearson Education, Inc. All rights reserved.

    Examples of Programming LanguagesC: fast, efficient code Java: platform independence BASIC: ease of use Visual Basic: user interface design using forms Perl: text manipulation

    *

    2009 Pearson Education, Inc. All rights reserved.

    Learning a Programming LanguageSyntaxStructureRulesPunctuationReserved Words (keywords) eg. If, Else

    Visual Basic.NET is NOT case sensitive. MyCase is the same as myCase and MYCASE. Comment lines start with an apostrophe (')

    *

    2009 Pearson Education, Inc. All rights reserved.

    Visual Studio IDEVisual Studio is Microsofts integrated development environment (IDE) for creating, running and debugging applications. The IDE allows you to create applications by dragging and dropping existing building blocks into place.This technique is called visual programming.It is a Rapid Application Development (RAD) tool because it is focused on productivity. *

    2009 Pearson Education, Inc. All rights reserved.

    Visual Studio LanguagesVisual Basic.NET C# (pronounced C-Sharp) J# (pronounced J-Sharp) C++ (pronounced C plus plus) ASP.NET (web page creation)

    *

    2009 Pearson Education, Inc. All rights reserved.

    Some Advantages of Visual Studio IDEGreatly reduces amount of code you must writeAutomatically colors code depending what it isComments are GreenKeywords are BlueOrganizes code in separate filesIntelliSenseCode SnippetsReal-time compiler feedbackBlue squiggle under code indicates an errorGreen squiggle under code indicates a possible error

    *

    2009 Pearson Education, Inc. All rights reserved.

    Solutions and ProjectsVisual Basic organizes applications into solutions and projects.

    Solutions contain one or more projects.

    A project is a group of related files, such as code and images that might make up a program.

    *

    2009 Pearson Education, Inc. All rights reserved.

    Solutions, Projects, and Files

    2009 Pearson Education, Inc. All rights reserved.

    Creating a New ProjectSelect either File > New Project, which creates a new project, or File > Open Project, which opens an existing project. From the Start Page, under the Recent Projects section, click the link Create: Project or Open: Project.

    Click either the New Project Button or the Open File Button. *

    2009 Pearson Education, Inc. All rights reserved.

    Working With a ProjectThe Solution Explorer window displays a list of the files in a project and the projects in a solution.The Properties window displays an objects attributes, such as its size, color and position. The Properties window allows you to set object properties visually without writing code.Using visual programming, you can drag and drop controls onto the Form from the Toolbox.*Properties iconObject Browser iconToolbox icon Solution Explorer icon

    2009 Pearson Education, Inc. All rights reserved.

    Properties Window*Figure 2.22 | Properties window displaying a Forms properties.Objects name (Form1) Objects class (System.Windows.Forms.Form)Down arrow for selecting Form or control objectsItems that have been changed from their default values (by the user or by Visual Studio) are listed in boldProperty values (right column)Properties (left column)Description of selected propertyDesign categorySelected propertyAlphabetical iconCategorized iconComponent object box

    2009 Pearson Education, Inc. All rights reserved.

    Form Controls

    ***************************************