Title: Nieuw in Visual Basic'NET Whidbey
1Nieuw in Visual Basic "Whidbey" Alex
ThissenTwice IT Training
2Agenda
- Visual Basic "Whidbey" design goals
- Language enhancements
- IDE enhancements
3Agenda
- Visual Basic "Whidbey" design goals
- Language enhancements
- IDE enhancements
4Visual Basic.NET design goals
- Increase productivity
- Do more with less code and fewer clicks
- Half development time and 50 less code
- Full access to .NET Platform
- New language features
- MSBuild and Yukon managed procedures
- Writing correct code
- Design-time expression evaluation
- Error correction with Smart Tags à la Office
5Improved Debugging Cycle
- Edit and Continue is back
- Change code without stopping or re-starting your
debugging session - Fix issue while code is executing in debugger
- Visual indication of "legal" and "illegal" edits
- Access to debugger values
- Debugger visualizers
- Enhanced data tool tips
- Formatted debugger output windows
6Improved Debugging Cycle
- Improved exception interaction
- Ability to continue after an exception
- Break in the debugger on exception states (First
Chance, Unhandled and User-unhandled) - New Exception Assistant
- Provides access to exception details
- Includes troubleshooting tips for handling the
exception
7Configuration and Settings
- Basic support in VS 2002 and 2003
- App.config contains settings
- Framework for reading settings
- Section handlers for custom settings
- Huge improvements in Whidbey
- Framework classes support read/write
- Strongly-typed access to settings
- IntelliSense for settings
- Choose app-scoped or user-scoped settings
- Works in partial trust
- Validation model
- Shared infrastructure across client and web
8Settings architecture
- Extensible provider model
- Customizable
- At the provider level
- By writing custom settings classes
SettingsBase
ApplicationSettingsBase
WindowsApp1Settings
My.Settings
Provider Interface
LocalSettings
Remote
SqlServer
Custom
Access
Custom
9Settings
MyApp.exe.config ltapplicationSettingsgt lt/applic
ationSettingsgt
- Designer allows
- Creating, modifying, deleting entries
- Type of entry for strong typing
- Choosing user-scoped or app-scoped
- Default value
- Different profiles
- Special support for
- Connection Strings
- Web service proxies
- Visual Studio will automatically create settings
piet.config ltuserSettingsgt lt/userSettingsgt
karin.config ltuserSettingsgt lt/userSettingsgt
jan.config ltuserSettingsgt lt/userSettingsgt
10(No Transcript)
11Agenda
- Visual Basic "Whidbey" design goals
- Language enhancements
- IDE enhancements
12DEMO
- Various new language features
13Partial Types
- Single Structure or Class in multiple files
- Separate designer generated from custom code
- Factor implementation
- ASP.NET now uses code-beside instead of
code-behind - Large interfaces implementation
Public Class MyDataSet Inherits
System.Data.DataSet 'Generated code End
Class Expands Class MyDataSet 'Expands might
become Partial Sub ExtraMethod() 'My code
End Sub End Class
14Explicit Array Bounds
- You can now specify the lower and upper bounds in
the declaration - But arrays are still zero based
Visual Studio.NET 2002, 2003Dim x(10) As
Integer Avoid confusion (for C programmers,
e.g.) Dim y(0 To 10) As Integer
Tip Create non-zero based array using
Array.CreateInstance
15Using Statement
- Fast way to correctly release resources
- Object "being used" must implement IDisposable
interface - Runtime will call Dispose method when Using block
goes out of scope - Compiler creates Try, Catch, Finally block
Using block disposes of resource Using objSR As
New StreamReader(strFileName) While
objSR.Peek() gt 0 Console.WriteLine(objSR.Read
Line()) End While 'StreamReader will be
disposed automatically End Using
16Continue Statement
- Skips to next iteration of loop
- Loop keyword specifies which iteration in case of
(multiple) nested loops - Continue For, Continue While
- Continues nearest enclosing loop
For index As Integer 0 to MyArray.Length
While MyArray(index) gt 100 If MyArray(index)
0 Then To next iteration of
index Continue For End If
CalculateValue(MyArray(index)) End While Next j
17Global Keyword
- Provides access to root, empty namespace
- Complete name disambiguation
- Better choice for code generation
Namespace SampleApp Class Form1 Inherits
Windows.Forms.Forms Sub LastName(nm As
String) Global.Microsoft.VisualBasic.Left(nm
) End Sub End Class End Namespace
18Property accessor accessibility
- Provides granular control over accessibility to
getter and/or setter of property - ExampleA read-only property can still have a
setter, available only from within the class
Property Age() As Integer Get Return Me.age
End Get Private Set (ByVal Value As
Integer) If Value lt 0 Then Throw New
ApplicationException(Mistake) End If Me.age
Age End Set End Property
19Unsigned Types
- Unsigned integers are now intrinsic types
- Syntactic equivalent to System.UInt16, UInt32,
- Better support for overload resolution
- Convenient for Interop scenarios
- Easier Win32 API calls and translation
Dim sb As SByte -4 Dim us As UShort Dim ui As
UInteger Dim ul As ULong Full support in Visual
Basic modules If IsNumeric(ui) Then Should now
return True End If
20Operator Overloading
- Create your own operators, -, , , , , gt, lt,
, CType, Not, IsTrue, IsFalse - Operators are Shared methods
- Method signature must include at least one
reference to enclosing type
Public Class Point Public x, y As Integer
Public New(ByVal x As Integer, Byval y As
Integer) ... Public Shared Operator (p1 As
Point, p2 As Point) _ As Point Return
New Point(p1.x p2.x, p1.y p2.y) End
Operator End Class
21Generics
- CLR based, compile-time and type-safe way to
reuse code for different data-types - Similar to C templates, but not same
- No compiler code generation!
- Lots of goodness
- No boxing and unboxing
- Compile-time checking of types used
- Generic collection classes in .NET Framework
- System.Collections.Generic namespace
- Dictionary, HashTable, List, Stack, etc.
22DEMO
23Agenda
- Visual Basic "Whidbey" design goals
- Language enhancements
- IDE enhancements
24Application Designer
- One stop shopping for app settings
- Resources
- Application and user settings
- References
- Version Info
- Deployment
- Easier to find
- Non-modal window for better usability
25(No Transcript)
26My. Classes
- Shortcuts into .NET Framework
- Common classes
- Application level version of Me
- Simple, flat hierarchy to work with
- Visual Basic.NET only!
27My. Classes
- My.Application
- Make application-related properties more
accessible - Allow commonly referenced services and classes to
be enabled easily - Provide a more manageable framework for
application startup and shutdown. - My.Computer
- Access to host computer's properties and hardware
resources - Audio, Printer, Screen, Keyboard, Mouse,
Registry, File System, Serial Ports, Network, - My.User
- User Login Name, Domain Name, Display Name,
Roles,
28My. Classes
- Application level version of Me
- My.Forms
- My.Forms.Form1.Show
- My.WebServices
- My.WebServices.MSDN.Search(VB)
- My.Resources
- PictureBox1.Image My.Resources.Logo
- My.Settings
- My.Settings.User.FormLocation Me.Location
29DEMO
30Symbolic Rename
- Quick way to change identifiers
- Rename all cases of TextBox1
- Type declarations declaration
- Variable
- Events
- More precise than text replacement
- Doesnt affect comments
- Working on other refactoring features
- Create method
31Asynchronous calling
- Easier way to call slow background tasks
- Model asynchronous calls as events
- PictureBox1.LoadAsync(url)
- PictureBox1_LoadCompleted(, )
- Completion routine is on main thread
- Web service proxies
- Supports progress, cancellation
- Background worker component
32Background Worker
Structure BackgroundArgs Dim x, y As
Integer End Structure Private Sub
Button1_Click() Handles Button1.Click Dim
args As BackgroundArgs BGW1.RunWorkerAsync(arg
s) End Sub Private Sub BGW1_DoWork() Handles
BGW1.DoWork This is run on a background
thread Dim args As BackgroundArgs args
CType(e.Argument, BackgroundArgs) e.Result
SomeLengthyOperation(args.x, args.y) End
Sub Private Sub BGW1_RunWorkerCompleted()
Handles result e.Result End Sub
33DEMO
- BackGroundWorker component
34Code Snippets
- Reusable pieces of code
- Editor to create and modify snippets
- Customization placeholders
- Context-aware in code editor
- Includes required project references and file
imports - Final release should include 500 task oriented
snippets - Extensible Architecture
- Specify multiple snippet stores (local, network
share, etc.)
35Visual Basic Warnings
- Overlapping catch blocks or cases
- Recursive property access
- Unused Imports statement
- Unused local variable
- Function, operator without return
- Reference on possible null reference
- Option Strict broken down
- Late binding
- VB Style Conversions
36Summary
- Visual Basic "Whidbey" improves framework
productivity - Improves navigation of the Framework
- 50 less code for common tasks
- Visual Basic "Whidbey" enables building robust
applications in less time - Identify and fix errors before you build
- Provides the most productive Visual Basic
debugging environment yet!
37Other resources and information
- http//msdn.microsoft.com/vbasic/whidbey
- Newsgroup microsoft.public.dotnet.vb
- http//communities.microsoft.com/newsgroups/defaul
t.asp?icpwhidbeyslcidus - Blog www.panopticalcentral.net
- Send feedback to vswish_at_microsoft.com
- Visit us at the Twice IT booth!!
38Questions and Answers