0 ratings0% found this document useful (0 votes) 19 views32 pagesIntroduction To Visual Basic - NET Programming in Visual Basic - NET. - 20250114 - 190449
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Introduction to
Visual Basic.NET
Programming In
Visual Basic.NETWriting Windows ay
Applications with VB 2
* Windows Graphical User Interface
* Window = Form
¢ Toolbox of elements called Controls
— Text Box
— Label
— Check Box
— ButtonObject Model
* Object ==> Noun * Event ==> Occurs when the
— Form and Controls user takes action
ae — User clicks a button, User
* Property ==> Adjective .
perty uJ moves a form
— Color of a Form
~ Size of Text * Class ==> Template to
* Method ==> Verb create new object
— Move a Form ~ Each control added is an
Instance of a ClassObject Model Analogy oe)
* Class = automobile
* Properties = make, model, color, year
* Object = each individual car
— Object is an Instance of the automobile class
* Methods = start, stop, speedup, slowdown
« Eyents = car arrives, car crashes, car is purchasedDot Notation a;
* Used to reference object's properties and a:
methods in code
— Object dot Property
* Form.Text, TextBox.Text
— Object dot Method
* Form.Hide( ), TextBox.Focus( )
To reference an object's events use an
underscore in the Private Sub name and use a
dot in the Handles subclause of the Private Sub
statement
* Private Sub Button_Click () Handles Button.ClickVisual Basic.NET a
¢ Included in Visual Studio.NET
— Visual Basic (can also be purchased separately)
— C++
— C#
— .NET Framework
* Complete rewrite from VB Version 6Visual Studio.NET Editions @)
* Academic
¢ Professional
¢ Enterprise Developer
¢ Enterprise Architect“a,
Steps for Writing VB Projects a
* Design/Define the User Interface
* Plan/Set the Properties
Plan/Write the Code
¢ Test and DebugVB Application Files ”
“gk
Open this file directly to work on a Project
One Solution File sin
Solution User Options File .Suo
Project Files .vbproj
Project User Options File
Form Files
Resource File for the Form
.vbproj.user
.vb
.TeSXVisual Studio Environment g)
* Integrated Development Environment (IDE)
¢ Form Designer
¢ Editor for entering code
* Compiler
° Debugger
¢ Object BrowserVisual Studio IDE Start ee q ,
Start Po9e |
eoroject Dialog
“SD Visual Bask Projects
Gy Setup and Deployment Projects
(6-G Other Provects
‘visual studio Solutions:
*—
waza Class Library Windows
Control Library
a & &
ASP.NET Web ASP.NET Web Web Control
Application Service Library
{A project For creating an pplication with a Windows user interface
Name: MyVBProject
Location: AMY VOProjects
Project will be created at C:\MyVBProjects\MyVBProject.
_stee_| aIDE Main Window
Toolbars
Document Window
°
Form Designer
Solution Explorer
Properties Window
Toolbox
Class View
°
Dynamic Helpsalneaie ga
Ste oe Femi. Desi] |VB Toolbox
¢ Holds the tools
you place on a
form
fbi TextBox
& manmenu
WM checkbox
© RadioButton
] GroupBox
laf] PictureBox
(2 Panel
SL DataGrid
EW ListBox
ED CheckedtistBox
[3 ComboBox
General
Clipboard RingVisual Studio Help a
3
¢ Extensive Help feature
* Includes Microsoft Developer Network
library (MSDN)
¢ Entire reference manual
* Coding examplesModes
* Design Time
¢ Run Time
¢ Break Time
“Look at the Title Bar”Naming Conventions (p 43-44) a
aa
¢ Always use standard names for objects
* No spaces or punctuation marks
* 3 letter lowercase prefix identifies control
type
» Button-bin
* Label-lbl
* Form-fim
¢ If multiple words capitalize 1st letter of each
wordRecommended Naming
Conventions for VB Objects
Object Class Prefix | Example
Form frm frmDataEntry
Button btn btnExit
TextBox txt txtPaymentAmount
Label Ibl IbITotal
Radio Button rad radBold
CheckBox chk chkPrintSummary
Horizontal ScrollBar | hsb hsbRate
Vertical ScrollBar vsb vsbTemperature
PictureBox pic picLandscape
ComboBox cbo cboBookList
ListBox Ist IstIndegredientsHello World Project (p 13) a ¥
Design the User Interface *
Eien
IbIMessage
btnPush
btnExitSet the Properties
* Label
— Name
— Text
* Button 1
— Name
= Text
¢ Button 2
— Name
— Text
* Form
— Name
=] Text
IblMessage
leave blank
btnPush
Push Me
btnExit
Exit
frmHello
Hello World by your name| © (DynamicProperties
re Rename Labell
AccessibleDescri to IbIMessage
AccessibleName
AccessibleRole Default
AllowDrop False
(Name)
Indicates the name used in code to identify
the object.Set the Project's Startup a;
Object Re
* The default startup object is Form!
* The name of the form should always be
changed to adhere to naming rules
¢ Using Project menu, Properties change the
startup object to match the new nameWrite the Code a
“igh
St
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 with code
Code is written as event procedures
VB will ignore events for which you do not
write codeEditor Window
¢ Declarations Section
* Class list
¢ Method list
[?efrmttetto =] [g@btnPush_click >
=| Public Class frmiello
Inherits System.Windows.Forms.Form
»
a Private Sub btnPush Click(ByVal sender As System.Object, By'
| End Sub
End ClassRemark Statement a)
« Also known as Comments, used for
documentation
¢ Non-executable
* Automatically colored Green in Editor
* Begins with an apostrophe (' )
— Ona separate line from executable code
— At the right end of a line of executable code
' Display the Hello World messageAssignment Statement oe
* Assigns a value to a property or variable
* Operates from right to left
¢ Enclose text strings in quotation marks ("")
IbIMessage.Text="(Hello World)"Ending a Program a
¢ Execute the Close Method of the Form
* Methods always have parentheses (this will
help you distinguish them from Properties which
never have parentheses)
¢ Current Form may be referenced as Me
Me.Close( )Test and Debug
* Save Project - File Menu, Save All
* Run Project
— Debug Menu, Start
— Start Without Full Compile >| (FS)
— Start With Full Compile (CTRL F5)
¢ Correct any Errors and Rerun
— Compile errors
— Run-Time Errors
— Logic errors
— Syntax errorsPrint the Code
¢ File Menu, Print
* Prints complete code listing
¢ Uses arrow symbol / to denote line
continuation
* Examine sample output (Handout)Finding and Fixing Errors ow
nae:
* Syntax Errors (easy to see in editor)
¢ Run-Time Errors (identified when executed)
¢ Logic Errors (harder to find)