Download - VISUAL BASIC 2005 EXPRESS
VISUAL BASIC 2005 VISUAL BASIC 2005 EXPRESSEXPRESS
- Lakoća programiranja -
Dragan JankovićKatedra za RačunarstvoElektronski fakultet, Niš
Sve to može ovakoSve to može ovako
A može i ovakoA može i ovakoExpress ProizvodiExpress Proizvodi
UčenjeUčenje.NET.NET
KreiranjeKreiranjeapliaplikacijakacija
UčenjeUčenjeVBVB
Hobi
UUčenicičenici Studenti
Penzioneri
RAD ?RAD ?• Brzo učenje• Motivacija• Brz i efikasan razvoj aplikacija• Gotovi elementi interfejsa• Programiranje upravljano dogadjajima• “Programiranje mišem”
– Drag & Drop– Podesi– Dopuni
Jednostavnije i efikasnijeJednostavnije i efikasnije
BasicBasic
Visual Visual BBasicasic
VBVB.NET.NET
VB2005VB2005.NET.NET
Visual Basic .NETVisual Basic .NET• Unapredjen jezik
– Potpuno podržana OO paradigma:• Klase, nasleđivanje, konstruktori, destruktori• Overloading, polimorfizam, ...
– Obrada izuzetaka
• Potpuni pristup .NET frameworku– Multithread, garbage collection
• Unapredjen razvoj Web apikacija– Kreiranje Web formi po ugledu na Windows forme– Kreiranje Web servisa – jednostavno
• Poboljšan security• Jednostavan i fleksibilan deployment
Šta je novo?Šta je novo?• Edit and Continue • My• Generics • Click Once• Data Sources Windows• Object Binding• Web Service Binding• Debugger Visualizers • Just My Code Debugging • The Exception Assistant • Design Time Expression
Evaluation • IntelliSense Code Snippets • XML Comments • Error Correction and
Warnings • Rename • Attribute Editing
• IntelliSense Filtering • IntelliSense in Zone • New VB Item Templates • Find References • Exportable Development
Settings • Simplified Tools ->
Options• Project Designer • Starter Kits • XML Editor• Zero Impact Projects• Start Page• Authenticode signing
support• Custom Setup Bootstrapper• Big 5 Bootstrapper
packages(Fx 2.0, SSE, etc.)
• Strongly typed Resources
• Registration Free COM• Strongly typed Settings• Using statement• Continue statement• Global keyword• Accessor accessibility • Partial types• Unsigned types• Operator overloading• Warnings• Custom Events• TableAdapters• DataSet Designer• Drag Once Form creation• Smart Tags• Parameterized query• Connect the Dots databinding• Custom Control drag / drop
• Lookup table binding• Upgrade WebBrowser• Upgrade Masked Edit • Upgrade Rich textbox • Upgrade Windows Common
Controls– TreeView, ListView,
ImageList– ToolBar, StatusBar,
ProgressBar• Upgrade Common Dialogs• Upgrade MTS/COM+ Projects• Upgrade BackgroundImageLayout
Property • Upgrade keys in KeyPress event • Upgrade additional Keywords• Updated Keys In Control
Collections • Upgrade Unload Mode in
FormClosing Event
NeNešštoto više o ... više o ...
• Generics• Partial Types• IsNot• Continue• Operator overloading• My Object (namespace)• Code Snippets• …
GenericsPrivate _Items As CollectionPrivate _Items As Collection
Private Sub Class_Initialize()Private Sub Class_Initialize() Set _Items = New CollectionSet _Items = New CollectionEnd SubEnd Sub
Private Sub Class_Terminate()Private Sub Class_Terminate() Set _Items = NothingSet _Items = NothingEnd SubEnd Sub
Public Function NewEnum() As stdole.IUnknownPublic Function NewEnum() As stdole.IUnknown Set NewEnum = moItems.[_NewEnum]Set NewEnum = moItems.[_NewEnum]End FunctionEnd Function
Public Function Item(Key As String) As PersonPublic Function Item(Key As String) As Person On Error Resume NextOn Error Resume Next Set Item = _Items.Item(Key)Set Item = _Items.Item(Key)End FunctionEnd Function
Public Property Get Count() As LongPublic Property Get Count() As Long Count = _Items.CountCount = _Items.CountEnd PropertyEnd Property
Public Sub Add(Person As Person, Key As String)Public Sub Add(Person As Person, Key As String) _Items.Add Text, Text.Key_Items.Add Text, Text.KeyEnd SubEnd Sub
Public Sub Remove(Index As Integer)Public Sub Remove(Index As Integer) _Items.Remove Index_Items.Remove IndexEnd SubEnd Sub
Public Class Cars : Inherits CollectionBasePublic Class Cars : Inherits CollectionBase Public Sub Add(ByVal item As Person)Public Sub Add(ByVal item As Person) MyBase.InnerList.Add(item)MyBase.InnerList.Add(item) End SubEnd Sub
Default Property Item(ByVal index As Integer) As PersonDefault Property Item(ByVal index As Integer) As Person GetGet Return DirectCast(MyBase.InnerList(index), Person)Return DirectCast(MyBase.InnerList(index), Person) End GetEnd Get Set(ByVal Value As Person)Set(ByVal Value As Person) MyBase.InnerList(index) = ValueMyBase.InnerList(index) = Value End SetEnd Set End PropertyEnd PropertyEnd ClassEnd Class
VB6
VB.NET
VB2005Dim Cars As New List(Of Car)
Cars.Add(New Car())
Zašto GenericsZašto Generics??
• Kod tipiziran
• Izbegnute run-time greške
• IntelliSense radi
• Bolje performanse
• Primer:Primer: Efikasnost realizacije primenom• Array 344• ArrayList 4656• Generic List 797
File Class1.vbFile Class1.vbPublic Class CarPublic Class Car Public Sub Start()Public Sub Start() End SubEnd SubEnd ClassEnd Class
File Class2.vbFile Class2.vbPublic Public PartialPartial Class Car Class Car Public Sub Stop()Public Sub Stop() End SubEnd SubEnd ClassEnd Class
Dim T As New Car()Dim T As New Car()T.Start()T.Start()T.Stop()T.Stop()
Partial TypesPartial Types
IsNot OperatorIsNot Operator
Public Sub Test(ByVal o As SomeType)Public Sub Test(ByVal o As SomeType) If Not o Is Nothing ThenIf Not o Is Nothing Then o.DoSomething()o.DoSomething() ElseElse Throw New NullReferenceException()Throw New NullReferenceException() End IfEnd IfEnd SubEnd Sub
Public Sub Test(ByVal o As SomeType)Public Sub Test(ByVal o As SomeType) If o If o IsNotIsNot Nothing Then Nothing Then o.DoSomething()o.DoSomething() ElseElse Throw New NullReferenceException()Throw New NullReferenceException() End IfEnd IfEnd SubEnd Sub
ContinueContinue
For i as Int32=0 to 10For i as Int32=0 to 10 If (i mod 2 =0 ) Then Continue ForIf (i mod 2 =0 ) Then Continue For Debug.WriteLine(i) ‘ 1,3,5,7,9Debug.WriteLine(i) ‘ 1,3,5,7,9NextNext
Dim i, j, k As Int32Dim i, j, k As Int32Dim rnd As New Random(DateTime.Now.Millisecond)Dim rnd As New Random(DateTime.Now.Millisecond)ForFor i = 0 To 5 i = 0 To 5 j = 0 j = 0 WhileWhile (j < 3) (j < 3) j += 1 j += 1 k = 0 k = 0 DoDo k += 1 k += 1 If (rnd.Next(100) >= 90) Then If (rnd.Next(100) >= 90) Then Continue ForContinue For LoopLoop Until k > j Until k > j End WhileEnd While Debug.WriteLine(String.Format("{0} {1} {2}", i, j, k)) Debug.WriteLine(String.Format("{0} {1} {2}", i, j, k))NextNext
Overloading operatoraOverloading operatora
Public Class SetPointPublic Class SetPoint Public Temperature as Single Public Temperature as Single Public Sub New (value as Single) Public Sub New (value as Single) Me.Temperature=valueMe.Temperature=value End Sub End SubEnd ClassEnd Class
Dim T1 as New SetPoint(12.5)Dim T1 as New SetPoint(12.5)Dim T2 as New SetPoint(13)Dim T2 as New SetPoint(13)Dim T3 as SetPoint = T1 + T2Dim T3 as SetPoint = T1 + T2
Public Class SetPointPublic Class SetPoint Public Temperature as Single Public Temperature as Single Public Sub New (value as Single) Public Sub New (value as Single) Me.Temperature=valueMe.Temperature=value End Sub End Sub
Public Shared Public Shared OperatorOperator +(ByVal a As SetPoint,_ +(ByVal a As SetPoint,_ ByVal b As SetPoint) As SetPointByVal b As SetPoint) As SetPoint
Return New SetPoint(a.Temperature + b.Temperature)Return New SetPoint(a.Temperature + b.Temperature)End OperatorEnd Operator
End ClassEnd Class
Overloading operatora(2)Overloading operatora(2)Public Class Complex Public Real As Double Public Imag As Double
Public Sub New(ByVal rp As Double, ByVal ip As Double) Real = rp Imag = ip End Sub
Shared Operator +(ByVal lhs As Complex, ByVal rhs As Complex)_ As Complex Return New Complex(lhs.Real + rhs.Real, lhs.Imag + rhs.Imag) End OperatorEnd Class
'new Complex + operator works intuitively'new Complex + operator works intuitively Dim lhs As Complex = New Complex(2.1, 3.3)Dim lhs As Complex = New Complex(2.1, 3.3) Dim rhs As Complex = New Complex(2.5, 4.6)Dim rhs As Complex = New Complex(2.5, 4.6) Dim res As Complex = lhs + rhsDim res As Complex = lhs + rhs 'res.real = 4.6, res.imag = 7.9'res.real = 4.6, res.imag = 7.9
My
Application
Computer
User
Resources
Settings
WebServices
Forms
— Application title, version, logs, description, …— Registry, Printer, Audio, File System, …
— User name, group, domain, …
— Pristup resursi aplikacije: icons, images, …
— User i application settings
— Kolekcija formi u aplikaciji, show / hide
— Jednostavan pristup web servisima ukjučenim u projekat (Web references)
My NamespaceMy Namespace
My.ApplicationMy.Application
TitleTitle
VersionVersion
DescriptionDescription
LogLog
WorkingDirectoryWorkingDirectory
… …
Exit()Exit()
My.ComputerMy.Computer
MouseMouse
AudioAudio
NetworkNetwork
RegistryRegistry
… …
FileSystemFileSystem
ClipboardClipboard
My.UserMy.User
Login NameLogin Name
DomainDomain
AuthenticationAuthentication
RolesRoles
……
Custom PrincipalCustom Principal
My.ResourcesMy.Resources
PictureBox1.Image = PictureBox1.Image =
My.Resources.LogoMy.Resources.Logo
My.SettingsMy.Settings
My.Settings.FormLocation = My.Settings.FormLocation =
Me.LocationMe.Location
My.FormsMy.Forms
My.Forms.Form1.Show My.Forms.Form1.Show
My.WebServicesMy.WebServices
My.WebServices.MSDN.Search(“My.WebServices.MSDN.Search(“
VB”)VB”)
Code SnippetsCode Snippets
Desni-klik u editoru koda i selekcija taska izaziva insetovanje ranije pripremljenog koda.
Desni-klik u editoru koda i selekcija taska izaziva insetovanje ranije pripremljenog koda.
Start Page Start Page uu VVBB 2005 Express 2005 Express
Prikaz Web stranePrikaz Web strane
New New PProject dijalogroject dijalog
Design modeDesign mode
MeniMeniMeni Opis
File Sadrži komande za otvaranje, zatvaranje, dodavanje i pamćeje projekta kao i printanje i izlazak tj završetak rada.
Edit Sadrži komande za editovanje programa kao npr. cut, copy, paste, undo, redo, delete, find i select.
View Sadrži komande za prikaz prozora (npr., Solution Explorer, Toolbox, Properties prozora) i za dodavanje toolbara u IDE.
Project Sadrži komande za upravljanje projektima injihovim fajlovima.
Build Sadrži komande za kompajliranje programa.
Debug Sadrži komande za debagiranje i izvršavanje programa.
Meni (nastavak)Meni (nastavak)Meni Opis
Data Sadrži komande za interakciju sa bazama podataka.
Format Sadrži komande za izmenu i uredjenje kontrola na formi. Ovaj meni se pojavljuje samo kada je selektovana GUI komponenta u Design modu.
Tools Sadrži komande za pristup dodatnim IDE alatima (npr., Toolbox) i opcije koje omogućavaju kastomizaciju IDE.
Window Sadrži komande za prikaz i aranžiranje prozora.
Community Sadrži komande za slanje pitanja direktno u Microsoft, proveru statusa pitanja, slanje odgovora i searching CodeZone developer centra i Microsoft developers community sajta.
Help Sadrži komande za pristup helpu IDEa.
ToolbarToolbar
HelpHelp
• Dinamički help
• Context-Sensitive Help
Komande Help menijaKomande Help menija
Komanda Opis
How Do I? Sadrži linkove do odgovarajućih tema, kako izvršiti upgrade, o web servisima, arhitecture i dizajnu, fajlovima i I/O, podacima, debagiranju itd.
Search Pronalaženje help sadržaja na osnovu kljućnih reči is search-a.
Index Prikaz alfanumerički sortirane liste svih postojećih sadržaja.
Contents Prikaz sadržaja u obliku tabele kategorija u kojoj su sadržaji organizovani po oblastima.
Dinamički helpDinamički help
Context sensitive helpContext sensitive help
Kako uKako učiti?čiti?
• 2373B Programming with Microsoft Visual Basic .NET
• Microsoft IT Academy – Elektronski fakultet u Nišu
• PIL program:Microsoft Software & ELEF– Portal: www.pil-vb.net– Dušan Vučković, Elektronski fakultet, Niš– [email protected]– [email protected]
VB.NET2005