Visual Programming...2010/05/05 · Visual Studio .NET Microsoft‟s Integrated Development...
Transcript of Visual Programming...2010/05/05 · Visual Studio .NET Microsoft‟s Integrated Development...
CBVP2103
Evolved from BASIC
Beginner‟s All-Purpose Symbolic Instruction Code
Introduction to programming for novices
Introduced by Microsoft (1991)
Made programming for Windows much easier
• IDE facilitates quicker programming
Rapid Application Development
• Provided many extra features
Event handling
Graphical user interfaces
Object-oriented programming
Motivated by popularity of electronic devices
Provide interaction between wide variety of devices◦ Web-based applications distributed to different
devices
Cell phones
Personal Digital Assistants
Personal computers
◦ Allow communication between programs of disparate languages
Enhanced object orientation◦ Powerful library of components
Application development made even quicker
Enhanced language interoperability◦ Interaction between different languages
Old software compatible with Visual Basic .NET programs
Interaction over the Internet
Simple Object Access Protocol (SOAP)
Extensible Markup Language (XML)
Promotes use of Web services
Introduced by Microsoft (June 2000)◦ Vision for embracing the Internet in software
development
Independence from specific language or platform◦ Applications developed in any .NET compatible language Visual Basic .NET, Visual C++ .NET, C# and more
◦ Programmers can contribute to applications using the language in which they are most competent
Architecture capable of existing on multiple platforms
New program development process◦ Provides increased productivity
Additional information available at Microsoft Web site www.microsoft.com/net
Heart of .NET strategy◦ Manages and executes applications and Web services◦ Provides security, memory management and other
programming capabilities
Includes Framework class library (FCL)◦ Pre-packaged classes ready for reuse◦ Used by any .NET language
Details contained in Common Language Specification (CLS)◦ Submitted to European Computer Manufacturers
Association to make the framework easily converted to other platforms
Executes programs by Common Language Runtime (CLR)
Base Class LibraryBase Class Library
Common Language SpecificationCommon Language Specification
Common Language RuntimeCommon Language Runtime
ADO.NET: Data and XMLADO.NET: Data and XML
VBVB C++C++ C#C#V
isu
al S
tud
io.N
ET
Vis
ual S
tud
io.N
ET
ASP.NET: Web ServicesASP.NET: Web Services
And Web FormsAnd Web Forms
JScriptJScript ……
WindowsWindows
formsforms
Cla
ss L
ibra
ries
Com
pliant
Languages
Visual Studio .NET◦ Microsoft‟s Integrated Development Environment
(IDE)
◦ Used to create, run and debug programs (applications)
Visual programming◦ Dragging and dropping predefined building blocks
into place to create a simple Visual Basic program
Start Page in Visual Studio .NET.
Location bar
New Project dialog.
Design WindowT
oolbox
SolutionExplorer
PropertiesWindow
Menu Desc rip tion
File Contains commands for opening projects, closing projects, printing project data,
etc.
Edit Contains commands such as cut, paste, find, undo, etc.
View Contains commands for displaying IDE windows and toolbars.
Project Contains commands for managing a project and its files.
Build Contains commands for compiling a program.
Debug Contains commands for debugging (i.e., identifying and correcting problems in a
program) and running a program.
Data Contains commands for interacting with databases (i.e., files that store data,
which we discuss in Chapter 19, Databases, SQL and ADO .NET).
Format Contains commands for arranging a form’s controls.
Tools Contains commands for accessing additional IDE tools and options that enable
customization of the IDE.
Windows Contains commands for arranging and displaying windows.
Help Contains commands for accessing the IDE’s help features.
Fig. 2.5 Summary of Visua l Stud io .NET IDE menus.
Comma nd Desc rip tion
Contents Displays a categorized table of contents in which help articles are
organized by topic.
Index Displays an alphabetized list of topics through which the programmer
can browse.
Search Allows programmers to find help articles based on search keywords.
Fig. 2.13 Help menu c ommands.
Simple program executing.
Creating a new Windows Application.
Setting the project location in the Project Location dialog.
Fig. 2.18 Setting the form‟s Text property.
Form with sizing handles.
Changing the form‟s BackColor property.
Adding a label to the form.
Form elements are objects called controls
This form has:
◦ Two TextBox controls
◦ Four Label controls
◦ Two Button controls
The value displayed by a control is held in the text property of the control
Left button text property is Calculate Gross Pay
Buttons have methods attached to events
Should be meaningful 1st 3 lowercase letters indicate the type of
control◦ txt… for Text Boxes◦ lbl… for Labels◦ btn… for Buttons
After that, capitalize the first letter of each word
txtHoursWorked is clearer than txthoursworked Change the name property
◦ Set the name of button1 to btnWelcome◦ Set the name of button2 to btnExit
The GUI environment is event-driven
An event is an action that takes place within a program◦ Clicking a button (a Click event)
◦ Keying in a TextBox (a TextChanged event)
Visual Basic controls are capable of detecting many, many events
A program can respond to an event if the programmer writes an event procedure
An Event Procedure is a block of code that executes only when particular event occurs
Writing an Event Procedure◦ Create the event procedure stub
Double click on control from Design Window – for default event for that control
OR
Open the Code Editor (F7 or View Menu/Code option)
Select Control & Select Event from drop down windows in Code Editor
◦ Add the event code to the event procedure stub
Select the btnWelcome control from the Form Controls List Box
Select the Click event from the list of many available events
Buttons have 57 possible events they can respond to
Beginning of Procedure is created for you◦ If you create stub by double clicking on control it
will create a stub for the most commonly used event for that control
Write the code that you want executed when the user clicks on the btnWelcome button◦ Type: MsgBox (“Welcome to Visual Basic”)
◦ Must be contained within the Event Procedure Stub
Not Case Sensitive◦ Visual Basic will “correct” case issues for you
Keywords are in Blue◦ Special reserved words
Comments in Green
Problems with Syntax (Language) will be underlined in blue
Rules◦ Use spaces to separate the words and operators
◦ Indentation and capitalization have no effect
Recommendations◦ Use indentation and extra spaces for alignment
◦ Use blank lines before and after groups of related statements
◦ Code all variable declarations at the start of the procedure
◦ Group related declarations
Usage◦ Type an apostrophe ( ' ) followed by the comment
◦ The compiler ignores everything on the line after „
◦ Used for documentation/readability and to disable chosen statements during testing
Recommendations◦ Follow apostrophe with a star for readability ( „* )
◦ Use at beginning of program to indicate author, purpose, date, etc.
◦ Use for groups of related statements and portions of code that are difficult to understand
Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventAr…
'*Variable declarationsDim dOrderTotal As DecimalDim dDiscountAmount As Decimal
'*Get total from textbox dOrderTotal = txtOrderTotal.Text
'*Calculate the proper discountdDiscountAmount = dOrderTotal * 0.25'dDiscountAmount = dOrderTotal * 0.25
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)…
'*Code goes here
End Sub
End Class
Create an Event Procedure for when the btnExit button is clicked
Have it display “Goodbye” in a MsgBox
Then “End” – this will terminate the program
Make sure to save your work◦ SAVE ALL (not Save Form)
◦ Visual Basic applications are
◦ made of several files -
◦ Often even several forms