Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Visual Basic “Whidbey”: Advanced Language and IDE Features Steven Lees, Amanda Silver, Program Managers.

Similar presentations


Presentation on theme: "1 Visual Basic “Whidbey”: Advanced Language and IDE Features Steven Lees, Amanda Silver, Program Managers."— Presentation transcript:

1 1 Visual Basic “Whidbey”: Advanced Language and IDE Features Steven Lees, stevelee@microsoft.com Amanda Silver, amandas@microsoft.com Program Managers Microsoft Corporation Steven Lees, stevelee@microsoft.com Amanda Silver, amandas@microsoft.com Program Managers Microsoft Corporation Session Code: TLS300

2 2 Agenda Advanced IDE Features Lots of new language features Full platform support Advanced IDE Features Lots of new language features Full platform support

3 3 Advanced IDE Features Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention

4 4 Configuration and Settings Basic support in VS 2002 and 2003 App.config contains settings in XML Framework class for reading settings Can extend with additional capabilities Straightforward, but not really easy Basic support in VS 2002 and 2003 App.config contains settings in XML Framework class for reading settings Can extend with additional capabilities Straightforward, but not really easy

5 5 Configuration and 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 Extensible provider model Shared infrastructure across client and web 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 Extensible provider model Shared infrastructure across client and web

6 6 Settings Architecture SettingsBase ApplicationSettingsBase WindowsApp1Settings Provider Interface Local Settings RemoteSqlCustomAccessCustom My.Settings

7 7 Settings Architecture Customizable At the provider level By writing custom settings classes Customizable At the provider level By writing custom settings classes

8 8

9 9 Settings 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 VS will automatically create settings 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 VS will automatically create settings

10 10 Settings Architecture App settings User Settings Myapp.exe.config … fred.config … ethel.config … gladys.config …

11 11 Code Samples Load Save Handling events for validation Load Save Handling events for validation My.Settings.UseHighQuality = True ‘ Settings automatically loaded on first access Private Sub Settings_SettingChanging(ByVal sender As Object, ByVal e As SettingsArg) Handles MyBase.SettingChanging If e.SettingName = “SignatureFile” Then If e.SettingName = “SignatureFile” Then If Not My.Computer.FileSystem.FileExists(e.Setting.Value) Then If Not My.Computer.FileSystem.FileExists(e.Setting.Value) Then ‘ Cancel event ‘ Cancel event End If End If End Sub My.Settings.UseHighQuality = True My.Settings.Save()

12 12 Advanced IDE Features Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention

13 13 Application Designer One stop shopping for app settings Resources App and user settings References Version Info Deployment Easier to find Non-modal window for better usability One stop shopping for app settings Resources App and user settings References Version Info Deployment Easier to find Non-modal window for better usability

14 14 Application Designer New Application Events Startup Shutdown Unhandled exception Network connected Network disconnected New Application Events Startup Shutdown Unhandled exception Network connected Network disconnected

15 15 Advanced IDE Features Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention

16 16 Extensible Code Snippets Code snippets have standard schema You can add items to the right-click menu Snippet editor For creating, editing snippets Multiple snippet stores Local or network share Easy way to package code for reuse Sharing is encouraged! Code snippets have standard schema You can add items to the right-click menu Snippet editor For creating, editing snippets Multiple snippet stores Local or network share Easy way to package code for reuse Sharing is encouraged!

17 17 Rename Symbol Quick way to change identifiers Rename all cases of “TextBox1” Type declaration Variable declarations Events More precise than text replacement Doesn’t affect comments Working on other “refactoring” features Create method Rename all cases of “TextBox1” Type declaration Variable declarations Events More precise than text replacement Doesn’t affect comments Working on other “refactoring” features Create method

18 18 Advanced IDE Features Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention Application Designer Settings Extensible code snippets Rename Symbol New Async calling convention

19 19 Asynchronous 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 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

20 20 Background Worker Structure BackgroundArgs Dim arg1 As Integer Dim arg1 As Integer Dim arg2 As String Dim arg2 As String End Structure Private Sub Button1_Click(…) Handles Button1.Click Dim args As BackgroundArgs Dim args As BackgroundArgs BackgroundWorker1.RunWorkerAsync(args) BackgroundWorker1.RunWorkerAsync(args) End Sub Private Sub BackgroundWorker1_DoWork(…) Handles BackgroundWorker1.DoWork ‘ This is run on a background thread ‘ This is run on a background thread Dim args As BackgroundArgs Dim args As BackgroundArgs args = CType(e.Argument, BackgroundArgs) args = CType(e.Argument, BackgroundArgs) ‘ Now do something on the background thread ‘ Now do something on the background thread e.Result = e.Result = End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(…) Handles Background… result = e.Result result = e.Result End Sub

21 21 Advanced IDE Features

22 22 New Language Features Explicit array bounds Using statement Continue statement Global keyword Accessor accessibility Partial types Unsigned types Operator Overloading Generics Warnings Explicit array bounds Using statement Continue statement Global keyword Accessor accessibility Partial types Unsigned types Operator Overloading Generics Warnings

23 23 Explicit Array Bounds Arrays are still zero based You can now specify the lower and upper bounds in the declaration Arrays are still zero based You can now specify the lower and upper bounds in the declaration ‘In VS 2002 and 2003, you did it this way Dim x(10) As Integer ‘Now you can also declare it like this Dim y(0 To 10) As Integer

24 24 Using Statement Acquire, Execute, Release Fast way correctly release resources Easier to read than Try, Catch, Finally Couple with Dispose Pattern stub gen Fast way correctly release resources Easier to read than Try, Catch, Finally Couple with Dispose Pattern stub gen ‘Using block disposes of resource Using fStr As New FileStream(path, FileMode.Append) For i As Integer = 0 To fStr.Length For i As Integer = 0 To fStr.Length fStr.ReadByte() fStr.ReadByte() Next Next ‘End of block will close stream ‘End of block will close stream End Using

25 25 Continue Statement Skips to next iteration of loop Loop logic is concise, easier to read For j As Integer = 0 to 5000 While matrix(j) IsNot thisValue While matrix(j) IsNot thisValue If matrix(j) Is thatValue If matrix(j) Is thatValue ‘ Continue to next j ‘ Continue to next j Continue For Continue For End If Graph(j) Graph(j) End While End While Next j

26 26 Global Keyword Access to root (empty) namespace Complete name disambiguation Better choice for code generation Complete name disambiguation Better choice for code generation Namespace HeadTrax Class Form1 Class Form1 Inherits Windows.Forms.Forms Sub LastName(nm As String) Sub LastName(nm As String) Global.Microsoft.VisualBasic.Left(nm) Global.Microsoft.VisualBasic.Left(nm) End Sub End Sub End Class End Class End Namespace

27 27 Accessor Accessibility Granular accessibility on Get and Set Forces calls to always use get, set Easy way to enforce validation Forces calls to always use get, set Easy way to enforce validation Property Salary() As Integer Get Get Return mSalary End Get End Get Private Set( value As Integer) Private Set( value As Integer) If value < 0 Then Throw New Exception(“Mistake”) Throw New Exception(“Mistake”) End If End Set End Set End Property

28 28 Partial Types Single Structure, Class in Multiple Files Used to separate designer gen into another file Factor implementation Used to separate designer gen into another file Factor implementation Public Class Form1 Inherits Windows.Forms.Form Inherits Windows.Forms.Form ‘ Your Code End Class Partial Class Form1 ‘ Designer code Sub InitializeComponent() ‘ Your controls ‘ Your controls End Sub End Class

29 29 Unsigned Types Full support in the language Full platform parity Easier Win32 Api calls and translation Memory and performance win Full platform parity Easier Win32 Api calls and translation Memory and performance win Dim sb As SByte = -4 ‘Error:negative Dim us As UShort Dim ui As UInteger Dim ul As ULong ‘Full support in VisualBasic modules If IsNumeric(uInt) Then ‘ Will now return true End If

30 30 New Language Features

31 31 Operator Overloading Create your own base types Class Addr Private mString As String Private mString As String Property Value() As String Property Value() As String Get Get Return mString Return mString End Get End Get Set (value As String) Set (value As String) If Valid(value) Then If Valid(value) Then mString = value mString = value End If End If End Set End Set Shared Operator &(ad1 As Addr, ad2 As Addr) _ Shared Operator &(ad1 As Addr, ad2 As Addr) _ As Addr As Addr Return New Addr(ad1.Value & ad2.Value) Return New Addr(ad1.Value & ad2.Value) End Operator End Operator

32 32 Operator Overloading

33 33 List intList = new List() intList.Add(1) ‘ Argument is boxed intList.Add(2) ‘ Argument is boxed intList.Add("Three") ‘ Should be an error int i = CInt(intList(0)) ‘ Cast required Generics Public Class List Public Class List Private elements() As ItemType Private elements() As ItemType Private count As Integer Private count As Integer Public Sub Add(element As ItemType) Public Sub Add(element As ItemType) If (count = elements.Length) Then _ If (count = elements.Length) Then _ Resize(count * 2) Resize(count * 2) count += 1 count += 1 elements(count) = element elements(count) = element End Sub End Sub Public Property default(index As Integer) As ItemType Public Property default(index As Integer) As ItemType Get : Return elements(index) : End Get Get : Return elements(index) : End Get Set : elements(index) = value : End Set Set : elements(index) = value : End Set End Property End Property Public Property Count As Integer Public Property Count As Integer Get : Return count : End Get Get : Return count : End Get End Property End Property End Class Public Class List Private elements() As Object Private elements() As Object Private mCount As Integer Private mCount As Integer Public Sub Add(element As Object) Public Sub Add(element As Object) If (mCount = elements.Length) Then _ If (mCount = elements.Length) Then _ Resize(mCount * 2) Resize(mCount * 2) mCount += 1 mCount += 1 elements(mCount) = element elements(mCount) = element End Sub End Sub Default Public Property i(index As Integer) As Object Default Public Property i(index As Integer) As Object Get Get Return elements(index) Return elements(index) End Get End Get Set Set elements(index) = value elements(index) = value End Set End Set End Property End Property Public Property Count() As Integer Public Property Count() As Integer Get : Return mCount : End Get Get : Return mCount : End Get End Property End Property End Class Dim intList As New List intList.Add(1)intList.Add(2)intList.Add("Three") Dim i As Integer = intList(0) Dim intList As New List(Of Integer) intList.Add(1) ‘ No boxing intList.Add(2) ‘ No boxing intList.Add("Three") ‘ Compile-time error int i = intList(0) ‘ No cast required

34 34 Generics (Specifics) Compile Time Checking Eliminates runtime errors Performance No casting or boxing overhead Code reuse Easy to create strongly typed collections Generic Collection classes in Framework Dictionary, HashTable, List, Stack, etc. Compile Time Checking Eliminates runtime errors Performance No casting or boxing overhead Code reuse Easy to create strongly typed collections Generic Collection classes in Framework Dictionary, HashTable, List, Stack, etc.

35 35 Generics

36 36 Visual Basic Warnings Early warning of bad runtime behavior 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 Etc. 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 Etc.

37 37 Warnings

38 38 Additional Resources Related sessions TLS343 – Visual Studio “Whidbey”: Advanced Debugging Techniques (Tuesday 5:15 Room 408 AB) TLS344 – Visual Studio “Whidbey”: Deploying Applications Using ClickOnce (Wednesday 10:00 Room 511 ABC) ARC413 – CLR Under the Covers: “Whidbey” CLR Internals (Wednesday 5:00 Room 152/153) Related sessions TLS343 – Visual Studio “Whidbey”: Advanced Debugging Techniques (Tuesday 5:15 Room 408 AB) TLS344 – Visual Studio “Whidbey”: Deploying Applications Using ClickOnce (Wednesday 10:00 Room 511 ABC) ARC413 – CLR Under the Covers: “Whidbey” CLR Internals (Wednesday 5:00 Room 152/153)

39 39 Additional Resources Panels Ask The Experts (Tonight) Languages Panel (Thursday) Send us feedback! vswish@microsoft.com Newsgroup: microsoft.public.dotnet.vb http://msdn.microsoft.com/vstudio/whidbeypdc Other resources Paul Vick’s blog: www.panopticon.net Panels Ask The Experts (Tonight) Languages Panel (Thursday) Send us feedback! vswish@microsoft.com Newsgroup: microsoft.public.dotnet.vb http://msdn.microsoft.com/vstudio/whidbeypdc Other resources Paul Vick’s blog: www.panopticon.net

40 40 Summary Ease of use is built on solid infrastructure Many points of extensibility Very powerful new language features And some cool fit and finish ones too Full access to the platform Please fill out the eval! (Thank you!) Ease of use is built on solid infrastructure Many points of extensibility Very powerful new language features And some cool fit and finish ones too Full access to the platform Please fill out the eval! (Thank you!)

41 41 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

42


Download ppt "1 Visual Basic “Whidbey”: Advanced Language and IDE Features Steven Lees, Amanda Silver, Program Managers."

Similar presentations


Ads by Google