DDC 3363 – Programming III Main Reference

Slides:



Advertisements
Similar presentations
1-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
1-1 Chapter 1 Introduction to Visual Basic 2010 Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 1 Introduction to Visual Basic.NET Programming In Visual Basic.NET © 2001 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 1 Introduction to Visual Basic 2010 Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
 Visual Basic is an object-oriented language used to write application programs that run in Windows or on the Internet using a graphical user interface.
Introduction to Programming and Visual Basic
Chapter 1 Introduction to Programming and C# Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Lecture 2 Introduction to Visual Basic.NET Programming Appreciation.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 1 P. 1 Writing Windows applications with Visual Basic Figure 1.1 The first program works as follows: (These operations can be performed in any.
An Introduction to Visual Basic
IE 411/511: Visual Programming for Industrial Applications
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
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.
Introduction to Visual Basic.NET Programming In Visual Basic.NET.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter Two Creating a First Project in Visual Basic.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Introduction to Visual Basic.NET 2008 Chapter 1.
Chapter 2 – Introduction to the Visual Studio .NET IDE
 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.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Chapter 1 Introduction to Visual Basic.NET Programming In Visual Basic.NET © 2001 by The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Introduction to Visual Basic 2008 Chapter 1.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introduction to Programming and Visual C# 2008
Dive Into® Visual Basic 2010 Express
Chapter 1: An Introduction to Visual Basic .NET
DDC 3363 Programming III Main Reference
Visual Basic.NET Windows Programming
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Introduction to Computer CC111
Chapter 2 – Introduction to the Visual Studio .NET IDE
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Introduction to the Visual C# 2005 Express Edition IDE
An Introduction to Computers and Visual Basic
Using Procedures and Exception Handling
Chapter 2 Visual Basic Interface
Variables and Arithmetic Operations
Visual Basic.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development Programming with Visual Basic
Windows xp PART 1 DR.WAFAA SHRIEF.
Building an Application in the Visual Basic .NET Environment
Visual Studio.
An Introduction to Computers and Visual Basic
Presentation transcript:

DDC 3363 – Programming III Main Reference REV 01 DDC 3363 – Programming III Main Reference Bradley, Julia Case and Millspaugh, Anita C. (2009), Programming in Visual Basic 2008, Mc Graw Hill DDC 3363 Programming III

Chapter 1: Introduction to Visual Basic .NET 2008 REV 01 Objectives Describe the process of visual program design and development. Explain the term object-oriented programming. Explain the concepts of classes, objects, properties, methods, and events. List and describe the 3 steps for writing a Visual Basic project. Describe the various files that make up a Visual Basic project. Identify the elements in the Visual Studio environment. Define design time, run time, and debug time. Write, run, save, print, and modify your first Visual Basic project. Identify syntax errors, run-time errors, and logic errors. Use Auto Correct to correct syntax errors. Look up Visual Basic topics in Help. DDC 3363 Programming III 2

Chapter 1: Writing Windows Applications with VB REV 01 Windows Graphical User (GUI) Interface Defines how elements look and function Text boxes Defines user interfaces for application programs Check box Radio buttons Message box Buttons Picture box Label DDC 3363 Programming III 3

Chapter 1: Writing Windows Applications with VB REV 01 Windows are called forms. Elements are called controls and are added using a toolbox. DDC 3363 Programming III 4

Procedural—Cobol, Fortran, Basic Chapter 1: Programming Languages -Procedural, Event Driven, and Object Oriented REV 01 Procedural—Cobol, Fortran, Basic Program specifies exact sequence of all operations. Event-Driven Programming(VB 6.0 and previous) Contain some elements of object-oriented programming, but not all Object-Oriented Programming (OOP) (VB .NET) User controls sequence Click event Double Click event Change event Languages, such as BASIC, C, COBOL, FORTRAN are procedural languages. That is, the program specifies the exact sequence of all operations. Program logic determines the next instruction to execute based on conditions. VB 6 and previous versions were referred as event-driven programming language rather than an object-oriented language. Visual Studio, which includes VB, C#, J#, and F#, are OOP. C++ contains elements of OOP and of procedural programming. F#, applies the object-oriented paradigm to scripting languages for cross-platform development. DDC 3363 Programming III 5

Chapter 1: The Object Model REV 01 In VB, you will work with objects that have properties, methods, and events. Each object is based on a class. Objects equate to Nouns. Forms are windows. Controls are components contained inside a form. Properties equate to Adjectives. Color or size of a Form Methods are like Verbs. Typical methods include Close, Show and Clear DDC 3363 Programming III 6

Events occur when the user takes action. Chapter 1: Object Model REV 01 Events occur when the user takes action. User clicks a button, User moves a form Classes are templates used to create a new object. Classes contain the definition of all available properties, methods, and events. Each new object created is based on a class. Creating three new buttons makes each button a instance of the Button class. Events can be triggered by repainting a form or a timer reaching a preset point. Each button is based on the Button class and is called an instance of the class. It has its own set of properties, methods, and events. One button may be labeled “OK”, one “Cancel”, and one “Exit. DDC 3363 Programming III 7

Chapter 1: Object Model Analogy REV 01 Class = automobile Properties of automobile class= make, model, color, engine, year Object = Each individual auto is an object. Object is also an Instance of the automobile class. Methods = start, stop, speedup, slowdown Events of automobile class = Arrive, Crash To refer to the methods of a specific object of the class, use MyAuto.Start and YourAuto.Stop. DDC 3363 Programming III 8

Chapter 1: Visual Studio .NET REV 01 Included in Visual Studio .NET 2008 Visual Basic (can also be purchased separately) Visual C++ C# (C sharp) J# (J sharp) F# (F sharp) .NET 3.5 Framework Visual Studio .NET Editions Express Standard Professional Team System The Framework provides for easier development of Web-based and Windows-based applications, and allows objects from different languages to operate together. The .NET languages all compile to a common machine language, called MSIL. The MSIL code, runs in the Common Language Runtime (CLR), which is part of the .NET Framework. DDC 3363 Programming III 9

Chapter 1: Writing Visual Basic Projects REV 01 The 3-step process when writing a Visual Basic application: Set up the user interface Define the properties Create the code Planning Design the User Interface. Plan the Properties. Plan the Basic Code; follow the language syntax rules; use pseudocode (English expression or comment describing action) then you move on to Programming (and use the same 3-step process) Define the User Interface. Set the properties. Write the Basic code. Planning- Design the user interface—draw a sketch of the screens the user will see when running the project; include forms and all controls that are to be used including the names to be assigned. Plan the properties—for each object write down the properties that you plan to set or change during the design of the form. Plan the Basic code—plan the classes and procedures that will execute when the project runs including determining which events require action to be taken and then make a step-by-step plan for the actions. Programming- Define the user interface—Create Forms and Controls. Set the properties—Give each object a name and define attributes such as the contents of a label, size. Write the Basic code—use Basic programming statements to carry out the actions needed by the program. DDC 3363 Programming III 10

Chapter 1: VB Application Files REV 01 One Solution File—think of 1 solution file equals 1 project HelloWorld.sln Solution User Options File HelloWorld.suo Form Files HelloForm.vb Resource File for the Form HelloForm.resx Form Designer HelloForm.Designer.vb Project User Options File HelloWorld.vbproj.user Solution file—text file that holds information about the solution and the projects it contains; primary file Solution user options file—stores information about the selected options A.Vb file—holds the definition of a form, its controls, and code procedures Resource file—a text file that defines all resources used by the form including string of text, numbers and any graphics Project file—text file that describes the project and lists the files that are included in the project Project user option file—text file holds project option settings so that the next time a project is opened all selected options are restored Once a project is run, several more files are created by the system. The only file that is opened directly is the solution file. DDC 3363 Programming III 11

Chapter 1: Visual Studio Environment REV 01 The Visual Studio environment is where you create and test your projects. In Visual Studio, it is called an Integrated Development Environment (IDE) consisting of various tools including: Form Designer Editor for entering and modifying code Compiler Debugger Object Browser Help Facility IDE tools Form designer—allows to visually create a form Editor—entering and modifying program code Compiler—for translating the VB statements into the intermediate machine code Debugger—to help locate and correct program errors Object browser—to view the available classes, objects, properties, methods, and events Help facility Compiler—for translating the Visual Basic statements into the intermediate machine code Object browser—to view the available classes, objects, properties, methods and events Help facility—to provide answers to questions DDC 3363 Programming III 12

Chapter 1: Default Environment Settings REV 01 Visual Studio 2008 provides a new option that allows the programmer to select the default profile for the IDE. The first time you open Visual Studio, you are presented with the Choose Default Environment Settings dialog Box, where you can select VNB Development Settings. DDC 3363 Programming III 13

Chapter 1: The IDE Initial Screen REV 01 The Visual Studio IDE with the Start Page open, as it first appears in Windows XP, without an open project When you open the Visual Studio IDE, you generally see an empty environment with a Start Page. DDC 3363 Programming III 14

Chapter 1: IDE Main Window REV 01 Toolbars—are shortcuts for frequently used operations; each button represents a command. Document Window—largest window in the center of the screen; items that display in the Document window include: Form Designer, the Code Editor, the Object Browser, and the pages of Help that are requested. Form Designer—where a form is designed that makes up the user interface Solution Explorer Window—holds the filenames for the files included in your project and a list of the classes it references Properties Window—used to set the properties for the objects in a project Toolbox—holds tools that are used to place controls on a form Help—is expanded for >NET and includes the Microsoft Developer Network library containing reference materials for VB and other languages; as well as books, technical articles, Microsoft Knowledge Bases, and a database of FAQ’s. Toolbars Document Window Form Designer Solution Explorer Window Properties Window Toolbox Help Document window Document window Solution Explorer Properties window DDC 3363 Programming III 15

Chapter 1: ToolBox You can scroll to view more controls. REV 01 You can scroll to view more controls. To sort the tools in the toolbox: Right-click the toolbox and select. Sort Items Alphabetically from the context menu (shortcut menu). When you open the Visual Studio IDE, you generally see an empty environment with a Start Page. DDC 3363 Programming III 16

Design Time — used when designing the user interface and writing code Chapter 1: Modes REV 01 Design Time — used when designing the user interface and writing code Run Time — used when testing and running a project Break Time — if/when receiving a run-time error or pause error The Title Bar indicates which mode is currently being used. "Look at the Title Bar" DDC 3363 Programming III 17

Chapter 1: Writing Your First Visual Basic Project REV 01 Setting Up the Project Hello World Project 1 Step 1—set up the Workspace; run Visual Studio IDE and customize the workspace if desired. Step 2—start a New Project. Step 3—set up the environment—customize windows and toolbars. 2 3 DDC 3363 Programming III 18

Chapter 1: Planning the Project REV 01 Design the user interface. Set up the form. Resize the form. Place a label and a button control on the form using the toolbox. Lock the Controls in place. After the user interface is designed, the next step is to set the properties. Design the user interface by making a sketch of the form that includes the controls. Resize the form in the document window; drag the handle (key term) in the lower-right corner. Place the controls by pointing to the tool in the toolbox and clicking to select; drag the pointer over the form and the pointer becomes a crosshair; point to a spot to place the corner of the control and drag to create the control; a selected control that is selected will have 8 small square handles around it (Button 2). Once the controls have been selected and placed on the form, right-click on one of the controls and select Lock Controls from the context menu. DDC 3363 Programming III 19

Chapter 1: Setting Properties REV 01 Label 1 Name messageLabel Text leave blank Button 1 Name pushButton Text Push Me Button 2 Name exitButton Text Exit Form Name helloForm Text Hello World by your name Click on the control and then click in the properties window to select and change desired properties of the control and/or form. DDC 3363 Programming III 20

Chapter 1: Setting the Form Properties REV 01 The default startup object is Form1 The name of the form should always be changed to adhere to naming rules The properties window shows the files properties DDC 3363 Programming III 21

Chapter 1: Writing the Code REV 01 While the project is running, the user can perform actions. Each action by the user causes an event to occur. Write code for the events you care about; the events you want to respond to with code. Code is written as event procedures. VB will ignore events for which you do not write code. VB will automatically name event procedures as the object name, an underscore(_) and the name of the event. You write code in VB in procedures; currently each procedure will be a sub procedure (Key Term) and begin with the words Private Sub and end with End Sub. DDC 3363 Programming III 22

Chapter 1: More on Writing the Code REV 01 When writing the code for your first project, you will use the following: Remark Statement Assignment Statement Ending a Program Editor Window Details for the Remark statement, assignment statement, ending a program, and the editor window are shown on the following 4 slides. DDC 3363 Programming III 23

Chapter 1: Remark Statement REV 01 Also known as Comment, used for documentation; every procedure should begin with a remark statement providing explanation. Non-executable Automatically colored Green in Editor Begins with an apostrophe ( ' ) On a separate line from executable code At the right end of a line of executable code Example: ' This project was written by Jonathon Edwards. ' Exit the project. MessageLabel.Text = "Hello World" ' Assign the message to the Text property. 'Display the Hello World message. DDC 3363 Programming III 24

Chapter 1: Assignment Statement REV 01 Assigns a value to a property or variable Operates from right to left — the value appearing on the right side of the equal sign is assigned to the property named on the left of the equal sign. Enclose text strings in quotation marks (" ") General Form Object.Property = value Example: TitleLabel.Text = "A Snazzy Program" AddressLabel.Text = "1234 South North Street messageLabel.Text=" Hello World " DDC 3363 Programming III 25

Chapter 1: Ending a Program REV 01 Methods always have parentheses. (This will help you distinguish them from Properties which never have parentheses.) To execute a method of an object you write: Object.Method() Current Form may be referenced as Me To execute a method of the current object (the form itself), you use the Me keyword. And the method that closes the form and terminates the project execution is Close. Me.Close( ) DDC 3363 Programming III 26

Chapter 1: Editor Window REV 01 Declarations Section Class list Method list When double-clicking on a button, the Visual Studio editor opens with the first and last one of your sub procedure already in place and the insertion point indented inside the sub procedure. Declaration section—section at the top of the file DDC 3363 Programming III 27

Chapter 1: Run, Save, Modify, Print, Test, Debug, and Execute REV 01 Run Project Open Debug Menu, Start Debugging. Start Debugging button on the toolbar. Press F5, the Start Debugging command. Save Project — File Menu, Save All. Modify Project if needed. Print the Code. Correct any Errors and Rerun. When you start executing your program, the first step is called compiling, which means that the VB statements are converted to Microsoft Intermediate Language (MSIL). Your goal is to have no errors during the compile process: a clean compile. Run the project to determine if there are any errors (debugging) that need to be fixed. Save All saves the current form, project, and solution files to the path that was selected when you started the project. You cannot change the path after beginning a project. If wanting to move or rename the project it must be closed. Modify project is you want to change the controls or control properties such as font size, size of a label, etc. "Help is always available from the Help Menu or by pressing F1." DDC 3363 Programming III 28

Chapter 1: Print the Code REV 01 File Menu, Print Prints complete code listing Uses arrow symbol to denote line continuation DDC 3363 Programming III 29

Chapter 1: Finding and Fixing Errors REV 01 Syntax Errors Breaks VB’s rules for punctuation, format, or spelling Smart editor finds most syntax errors, compiler finds the rest. The editor identifies a syntax error with a squiggly blue line and you can point to an error to pop up the error message. You can display the Error List window and line numbers in the source code to help locate the error lines. Run-Time Errors Statements that fail to execute, such as impossible arithmetic operations Logic Errors Project runs, but produces incorrect results. DDC 3363 Programming III 30

Chapter 1: Naming Rules and Conventions REV 01 Have a set of standards and always follow them. No spaces, punctuation marks, or reserved words Use camel casing. Examples messageLabel exitButton dataEntryForm paymentAmountTextBox Using good consistent names for objects can make a project easier to read and understand, as well as easier to debug. When you select a name for an object, Visual Basic requires the name to begin with a letter or an underscore; names can contain letters, digits, and underscores but no spaces, punctuation marks, or reserved words such as Exit or It. Camel casing is beginning the name with a lowercase character and capitalizing each additional word in the name. DDC 3363 Programming III 31

Chapter 1: Recommended Naming Conventions for VB Objects REV 01 Object Class Example Form dataEntryForm Button exitButton Label totalLabel TextBox paymentAmountTextbox Radio button boldRadiobutton CheckBox printSummaryCheckBox Horizontal Scroll Bar rateHorizontalScrollBar Vertical Scroll Bar temperatureVerticalScrollBar PictureBox landscapePictureBox ComboBox bookListComboBox ListBox ingredientsListBox SoundPlayer introPageSoundPlayer DDC 3363 Programming III 32

Chapter 1: Visual Studio Help Additional Info REV 01 Visual Studio has an extensive Help facility. Filter MSDN help to display VB topics only. Run MSDN from hard drive, CD, or Web. You can access MSDN on the Web at http://msdn.microsoft.com The Help system display is greatly changed and improved in Visual Studio 2008. You view the Help topics in a separate window from the VS IDE, so you can have both windows opened at the same time. MSDN-Microsoft Developer Network library A good way to start using Help is to view the topics that demonstrate how to look up topics in Help. DDC 3363 Programming III 33

Chapter 1: Visual Studio Help Additional Info REV 01 When you choose How Do I, Search, Contents, Index, or Help Favorites from the Help menu, a new window opens on top of the IDE window. You can switch from one window to the other, or resize the windows to view both on the screen if your screen is large enough. A quick way to view Help on any topic is to use context-sensitive Help (Key term). Index Results window Main Document window DDC 3363 Programming III 34