By Dr. HANY ELSALAMONY 1by Dr. HANY ELSALAMONY. Microsoft released Visual Basic in 1987. It was the first visual development tool from Microsoft, and.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

Chapter 1: An Introduction to Visual Basic 2012
Using Macros and Visual Basic for Applications (VBA) with Excel
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Automating Tasks With Macros
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Using the Visual Basic Editor Visual Basic for Applications 1.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
By Dr. HANY ELSALAMONY. Microsoft released Visual Basic in It was the first visual development tool from Microsoft, and it was to compete with C,
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Introduction to VB.NET Tonga Institute of Higher Education.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Microsoft Visual Basic 2005: Reloaded Second Edition
1 CA201 Word Application Increasing Efficiency Week # 13 By Tariq Ibn Aziz Dammam Community college.
CHAPTER 9 Introducing Microsoft Office Learning Objectives Start Office programs and explore common elements Use the Ribbon Work with files Use.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CHAPTER 9 Introducing Microsoft Office Learning Objectives Start Office programs and explore common elements Use the Ribbon Work with files Use.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Fall 2003Sylnovie Merchant, Ph.D. ACCESS Tutorial Note: The purpose of this tutorial is to provide an introduction to some of the functions of ACCESS in.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Dive Into® Visual Basic 2010 Express
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Chapter 7 Advanced Form Techniques
Chapter 2 – Introduction to the Visual Studio .NET IDE
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development Programming with Visual Basic
Building an Application in the Visual Basic .NET Environment
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

By Dr. HANY ELSALAMONY 1by Dr. HANY ELSALAMONY

Microsoft released Visual Basic in It was the first visual development tool from Microsoft, and it was to compete with C, C++, Pascal and other well-known programming languages. From the start, Visual Basic wasn't a hit. It wasn't until release 2.0 in 1991 that people really discovered the potential of the language, and with release 3.0 it had become the fastest-growing programming language on the market. 2by Dr. HANY ELSALAMONY

Programmers have undergone a major change in many years of programming various machines. For example what could be created in minutes with Visual Basic could take days in other languages such: as "C" or "Pascal". Visual Basic provides many interesting sets of tools to aid you in building exciting applications. Visual Basic provides these tools to make your life far more easier because all the real hard code is already written for you. 3by Dr. HANY ELSALAMONY

With controls like these you can create many applications which use certain parts of windows. For example, one of the controls could be a button, which we have demonstrated in the "Hello World" program below. First create the control on the screen, then write the code which would be executed once the control button is pressed. With this sort of operation in mind, simple programs would take very little code. Why do it like the poor old "C" programmer who would have to write code to even display a window on the screen, when Visual Basic already has this part written for you. 4by Dr. HANY ELSALAMONY

Even though people tend to say Visual Basic's compiler is far behind the compilers of Pascal and C, it has earned itself the status of a professional programming language, and has almost freed BASIC of the reputation of a children's language. Overall you would class Visual Basic as a Graphics User Interface(GUI). Because as you draw, you write for the program. This must always be remembered in any kind of creation of a Visual Basic program. All in all, VB is the preferred language of many future program means. If you want to start programming Windows, and don't know how to start, give Visual Basic a shot. 5by Dr. HANY ELSALAMONY

 A programming language is a set of commands and command options, called arguments, that you use to give instructions to the computer. Computers cannot (yet) understand human languages because people deal well with ambiguous commands, and a computer cannot understand such ambiguity. A programming language must be more precise than a spoken language. Visual Basic is not only a programming language, but also a complete graphical development environment. This environment allows users with little programming experience to quickly develop useful Microsoft Windows applications which have the ability to use OLE ( Object Linking and Embedding ) objects, such as an Excel spreadsheet. 6by Dr. HANY ELSALAMONY

 Visual Basic also has the ability to develop programs that can be used as a front end application to a database system, serving as the user interface which collects user input and displays formatted output in a more appealing and useful form than many SQL versions are capable of.  Programs are often comprised of several files that interact with one another, so you’ll often see the term application used as a synonym for all of a program’s files. The program, or application written in a programming language, is a set of instructions that directs the computer. 7by Dr. HANY ELSALAMONY

Visual Basic's main selling point is the ease with which it allows the user to create nice looking, graphical programs with little coding by the programmer, unlike many other languages that may take hundreds of lines of programmer keyed code. As the programmer works in the graphical environment, much of the program code is automatically generated by the Visual Basic program. In order to understand how this happens it is necessary to understand the major concepts, objects and tools used by Visual Basic. 8by Dr. HANY ELSALAMONY

 Listing 1.1. Early BASIC programs had line numbers and were somewhat cryptic.  10 REM This program computes and prints the first ten squares  20 CLS  30 PRINT “Squares from 1 to 10”  40 PRINT “Value”, “Squared”  50 FOR N = 1 TO 10  60 PRINT N, (N*N)  70 NEXT N  80 PRINT  90 END 9by Dr. HANY ELSALAMONY

 Squares from 1 to 10 Value Squared  1 1  2 4  3 9  4 16  5 25  6 36  7 49  8 64  9 81  by Dr. HANY ELSALAMONY

 An interpreted language, such as BASIC, lets you run programs as you write them. Interpreted languages make good learning platforms because of their quick feedback. A compiled language requires extra steps, called compilation and linking, before the programmer can run the program. The compiled program resides in the computer’s own native language and not in the programming language that the programmer originally used. 11by Dr. HANY ELSALAMONY

 The term " Personal Programming " refers to the idea that, wherever you work, whatever you do, you can expand your computer's usefulness by writing applications to use in your own job. Personal Programming is what Visual Basic is all about.  Using Visual Basic's tools, you quickly translate an abstract idea into a program design you can actually see on the screen. VB encourages you to experiment, revise, correct, and network your design until the new project meets your requirements. However, most of all, it inspires your imagination and creativity. 12by Dr. HANY ELSALAMONY

 Over time you’ll find your own way of writing programs that works best for you. Nevertheless, you’ll generally follow these standard set of steps when creating your Visual Basic programs:  1. Decide what your application is to do by creating an overall design.  2. Create the visual portion of your application (the screens and menus that your users will interact with). 13by Dr. HANY ELSALAMONY

 3. Add Visual Basic programming language code to tie the visual elements together and to automate the program.  4. Test your application to locate and remove any bugs you find.  5. Compile your tested application and distribute the compiled application to your users. 14by Dr. HANY ELSALAMONY

Visual Basic can and is used in a number of different areas, for example:  Education  Research  Medicine  Business  Commerce  Marketing and Sales  Accounting  Consulting  Law  Science 15by Dr. HANY ELSALAMONY

16by Dr. HANY ELSALAMONY

17by Dr. HANY ELSALAMONY

 Changing the form’s BackColor property by Dr. HANY ELSALAMONY18

19by Dr. HANY ELSALAMONY

20by Dr. HANY ELSALAMONY

21by Dr. HANY ELSALAMONY

Once all your objects are created, you can combine them to form a single executable program that can be run outside of the Visual Basic environment, in Microsoft Windows. 22by Dr. HANY ELSALAMONY

 First thing to do is to create a Directory where you will store all your VB Projects. Call it VB Apps, for example. Then start VB.  The first screen will ask whether you want to open a new project or an existing one - it's obviously a new one and it will be a Standard EXE. Then, maximize all the windows  Now, save your project. It will first ask you to save the form - call it Score.frm - and then the Project - call it Scorebrd.vbp. From now on, do File-->Save Project very, very frequently. 23by Dr. HANY ELSALAMONY

24by Dr. HANY ELSALAMONY

 Visual Basic Express Edition enables you to create several types of applications. This includes Windows Forms applications, Windows Presentation Foundation applications, console applications, and class libraries. Each application that you create is contained in its own project, and project templates are provided to help you get started.  When you create a new project, icons in the New Project dialog box and Add Project dialog box represent the available project types and their templates. by Dr. HANY ELSALAMONY25

 The following project templates are available when you open a new project in Visual Basic Express Edition.  Although there is no project template for Windows control libraries, you can still create your own controls by using the Class Library template. by Dr. HANY ELSALAMONY26

Project TemplateUsed to create Windows Application Template Used to create Windows-based applications that run locally on users' computers. You can build anything from a simple single-window tool like Windows Calculator to a complete application that has multiple windows and advanced capabilities. Class Library Template Used to create reusable classes or components that can be shared with multiple projects. Console Application Template Used to create command-line applications, programs that run from a Windows command prompt and have no visual interface. WPF ApplicationUsed to create stand-alone Windows Presentation Foundation applications. WPF Browser Application Used to create browser-hosted Windows Presentation Foundation applications. by Dr. HANY ELSALAMONY27

28by Dr. HANY ELSALAMONY

 Before you start to build-up the form, it will make it easier if you change the color of the form.  Otherwise you will be working with grey controls on a grey background. To change the color, just click anywhere on the form, go to the properties window, find the property called BackColor and change it to the standard Window background (teal) or to any color you want in the palette. 29by Dr. HANY ELSALAMONY

 In our first example we will need 6 labels and 2 command buttons. Each one of these objects that you put on a Form is called a control. To get a control you go to the Toolbox, click on the control you want, come back to the Form and click and drag the control to the size and position you want. Position the controls somewhat like in the diagram below. 30by Dr. HANY ELSALAMONY

31by Dr. HANY ELSALAMONY

 Now that we have a bunch of controls on the form, we have to jazz them up a bit. We do this by changing the Properties of the controls in the Properties window. Each control has a whole series of properties, most of which we won't need right now. The ones we do need are:  Alignment = how text aligns in the control  BackColor = choose the color of the background  Caption = the text that will appear in the control  Font = choose the font type and size  ForeColor = choose the color of the text (foreground) 32by Dr. HANY ELSALAMONY

 As with all Windows applications, you can select multiple controls with (Ctrl)+(Click) and change a property for all of them at once. For example, if all backgrounds are white, select all controls, change ForeColor to white and all of them are modified.  Change your form to look like the one below. Note that you do not have to change the Caption for Label4, Label5 and Label6 and that you can't change the color of the buttons. They insist on being what was called in the old days "IBM grey". Don't forget to save your project often as you go along! 33by Dr. HANY ELSALAMONY

34by Dr. HANY ELSALAMONY

35by Dr. HANY ELSALAMONY

 If you Run the application at this point, you should see your Form appear, just the way you created it. However if you click on any of the controls, absolutely nothing happens! There are events that occur; the form opens, a button is clicked, etc.  But, there is nothing that tells the form what to do when it sees an event. That is why we have to write code, also called script. 36by Dr. HANY ELSALAMONY

37by Dr. HANY ELSALAMONY

 To switch between the Code window and the Form window, use the buttons just over the Project Explorer window (diagram on the left). Once in the Code window, you have the option of seeing all the code for the Project or the code for one event at a time. Use the buttons in the lower left-hand corner (diagram on the right). To select the object and the event you wish to code, use the two Listboxes at the top of the Code window. The one on the left for the object and the one on the right for the event. Start with General... Declarations and then Form... Load, etc. 38by Dr. HANY ELSALAMONY

 At this point you might want to download the sample program and study it. In the following lessons we'll add functionality to the exercice and we'll explain what the code means. But for the moment, a good exercice would be to write part of the code and then try to figure out how to improve certain aspects of the program. 39by Dr. HANY ELSALAMONY

40by Dr. HANY ELSALAMONY

41by Dr. HANY ELSALAMONY

 Now we can Run it and see something happen. When the Form loads, it will initialize the fields that we specified in the code. Now code the Command1 button and Run it to see the result. 42by Dr. HANY ELSALAMONY

 The language you write and speak has structure: for example, a book has chapters with paragraphs that contain sentences consisting of words.  Programs written in Visual Basic also have a structure: modules are like chapters, procedures are like paragraphs, and lines of code are like sentences. by Dr. HANY ELSALAMONY43

 When you speak or write, you use different categories of words, such as nouns or verbs. Each category is used according to a defined set of rules.  In many ways, Visual Basic is much like the language that you use every day. Visual Basic also has rules that define how categories of words, known as programming elements, are used to write programs. by Dr. HANY ELSALAMONY44

 Programming elements in Visual Basic include statements, declarations, methods, operators, and keywords.  As you complete the following lessons, you will learn more about these elements and how to use them.  Written and spoken language also has rules, or syntax, that defines the order of words in a sentence. by Dr. HANY ELSALAMONY45

 Visual Basic also has syntax—at first it may look strange, but it is actually very simple.  For example, to state "The maximum speed of my car is 55", you would write:  Car.Speed.Maximum = 55  You will learn more about syntax later, and tools in Visual Basic such as IntelliSense provide you with guidance in using the correct syntax when you write programs. by Dr. HANY ELSALAMONY46

Hello World! Example Program Description  This program demonstrates the text output and button control functions of the Visual Basic programming language. By clicking on the button "Hello World", the message "Hello world" is displayed in the upper left hand corner. 47by Dr. HANY ELSALAMONY

48by Dr. HANY ELSALAMONY

 The first program that students traditionally write when they learn a new language is a program that simply writes a message to the computer screen which reads “Hello, world!” You can create a ‘Hello World’ program by following these instructions:  Open Visual Basic Express Edition – on the Start menu, point to All Programs, and then click Microsoft Visual Basic 2005 Express Edition.  On the File menu, click New Project. In the Visual Studio installed templates list, click Console Application, enter My First Application in the Name box, and then click OK.  Visual Basic will create an outline program for you, and display the code for that program in the code window.  Insert the following line of code (underlined below) into the outline program in the code window: 49by Dr. HANY ELSALAMONY

 Module Module1   Sub Main()  Console.WriteLine("Hello, world!")  End Sub   End Module 50by Dr. HANY ELSALAMONY

Before you run the program, you should customize the Visual Basic 2005 Express Edition menu so that the option that we use will be available. Take the following steps to customize the menu:  On the Tools menu, click Customize.  Click to show the Commands tab.  In the Categories list, click Debug, then scroll the Commands list until you can see the Start Without Debugging command.  Drag the Start Without Debugging command over the Debug menu, move the insertion point below the Start / Continue command (as shown below), and then release. 51by Dr. HANY ELSALAMONY

52by Dr. HANY ELSALAMONY

 Click the Close button to dismiss the Customize dialog.   On the Debug menu, click Start Without Debugging (or just press Ctrl-F5 ). A command prompt window appears that looks like this: 53by Dr. HANY ELSALAMONY

Note The reason that you should use Start Without Debugging is so that the Press any key to continue message is displayed after your program has finished running. You can also use the Start Debugging menu option (or press F5 ) – as shown on the video that accompanies this article – but then the console window is closed as soon as your program has finished running, and you don’t get the chance to read what’s displayed on the console. 54by Dr. HANY ELSALAMONY

 Visual Studio detected that it needed to ‘build’ the program, because this is the first time the program has been run.  To build the program, Visual Studio invoked a special kind of program called a compiler, which understands the Visual Basic language and knows how to convert it into machine code.  The compiler converted the ‘source code’ for your program (which is just a plain text file containing the Visual Basic code you wrote) into machine code which the computer can understand. 55by Dr. HANY ELSALAMONY

 Once the compiler finished, Visual Studio took the compiler’s output – which is your program – and ran that program. Because your program is a console application, Visual Studio actually launched a console window and ran the program inside that window.  Once your program had written “Hello, world!” on the screen and finished, Visual Studio displayed the “Press any key” message so that you could see what your program had displayed before the window closed. You could do all these steps yourself, of course, but it’s much easier to use the Visual Studio Integrated Development Environment (IDE) to do them on your behalf. However, it’s important that you understand what’s going on behind the scenes. 56by Dr. HANY ELSALAMONY

 All the code in the file is contained within two statements (shown below) that indicate that we are creating a code module. A module is a general term for a file containing code or information that you add to your project. Usually, a module contains program code which you write. Along with classes (which you will learn more about shortly), modules are the basic units of code in a Visual Basic program. 57by Dr. HANY ELSALAMONY

Modules and classes are containers for your code. You must have at least one module or class in a program, but most programs have several. In the example below, everything between the two statements is inside a module called Module1.  Module Module1 ...  End Module 58by Dr. HANY ELSALAMONY

Inside the module there is a block of code called a subroutine. Modules and classes can contain subroutines, but subroutines are the blocks of code that do much of the actual work in a program. You use the Sub keyword to start a subroutine, and the End Sub keyword to end it. Everything in between is part of the subroutine. 59by Dr. HANY ELSALAMONY

 Sub Main() ...  End Sub In this case, the program declares a subroutine called Main. We’ll take a deeper look at subroutines later, but for now you need to know that the Main subroutine has a special place in a program, because it’s usually where the program starts running. You can write your subroutines in any order in the source code, but the Main method will be where your program starts. 60by Dr. HANY ELSALAMONY

Inside the Main subroutine, we have the code which actually writes the message to the screen:  Console.WriteLine("Hello, world!") In this case, we use a class called System.Console, which is part of the.NET Framework. Inside the System.Console class there is a subroutine called WriteLine, which writes a message to the console screen (“Write”) and skips to the next line (“Line”). 61by Dr. HANY ELSALAMONY

 we create a program that displays the text “ Welcome to Visual Basic!”  The program consists of a single form that uses a label control (i.e., a control that displays text which the user cannot modify) and a picture box to display the image. 62by Dr. HANY ELSALAMONY

63

by Dr. HANY ELSALAMONY64

by Dr. HANY ELSALAMONY65

 Setting the form’s Text property by Dr. HANY ELSALAMONY66

by Dr. HANY ELSALAMONY67 Adding a label to the form

by Dr. HANY ELSALAMONY68 GUI after the form and label have been customized

by Dr. HANY ELSALAMONY69 Properties window displaying the label’s properties

by Dr. HANY ELSALAMONY70 Font dialog for selecting fonts, styles and sizes.

by Dr. HANY ELSALAMONY71 Centering the label’s text.

 Add a picture box to the form. by Dr. HANY ELSALAMONY72 Inserting and aligning the picture box.

by Dr. HANY ELSALAMONY73 Image property of the picture box

by Dr. HANY ELSALAMONY74 Selecting an image for the picture box.

by Dr. HANY ELSALAMONY75 Picture box displaying an image

by Dr. HANY ELSALAMONY76

As an aside – how is it that the class is called System.Console but we just call it Console in our program? Well, Visual Basic enables you to use abbreviations if you use certain classes regularly. In this case, the Console class is part of a group of classes in a namespace called System. A namespace is a way of grouping several classes or modules together. 77by Dr. HANY ELSALAMONY

The diagram shows the structure of the System namespace, and how it contains many classes. Because the System namespace contains commonly used classes, Visual Basic automatically creates the abbreviation for you, so that you only need to type the name of the class and not the full name including the namespace. 78by Dr. HANY ELSALAMONY