visual basic 2008 tips and tricks
DESCRIPTION
Visual Basic 2008 Tips and Tricks. Lisa Feigenbaum Program Manager Microsoft Visual Studio Languages http://blogs.msdn.com/vbteam [email protected]. VB 2008 Tips and Tricks. Session Objectives Learn language & IDE productivity features - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/1.jpg)
Visual Basic 2008 Tips and TricksLisa FeigenbaumProgram ManagerMicrosoft Visual Studio Languageshttp://blogs.msdn.com/[email protected]
![Page 2: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/2.jpg)
VB 2008 Tips and Tricks
• Session Objectives• Learn language & IDE productivity features• Gain tips, tricks, best practices & answers
to FAQs• Agenda• IDE Improvements• New VB Refactorings & IntelliSense• Tips for writing LINQ queries• Using XML in VB 2008
![Page 3: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/3.jpg)
• “Stop highlighting my snippets”• “Add my Imports statements for me”• And more…
• Performance• Large solutions, web apps, stepping,
first-time intelliSense, error list, editor responsivenesshttp://blogs.msdn.com/vbteam/archive/tags/Performance/default.aspx
You asked. We listened!
![Page 4: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/4.jpg)
DemoIDE Improvements
![Page 5: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/5.jpg)
Code just like you think!
• Refactor! for VB• Visual Studio Plug-in, available
FREE on MSDN• Partnership with Developer Express, Inc.• Total: 16 for VB 2005, 14 more for VB 2008
• Six Refactorings in C# 2005 & 2008:• Rename• Extract Method• Remove/Reorder parameters• Promote Local• Extract Interface• Encapsulate Field
![Page 6: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/6.jpg)
VB Refactorings in 2005
1. Reorder Parameters 2. Surrounds With 3. Encapsulate field 4. Reverse Conditional 5. Simplify expression 6. Move initialization
to declaration 7. Split initialization
from declaration 8. Move declaration
near reference
8. Extract Method 9. Extract Property 10.Create Overload 11.Introduce Local 12.Introduce constant 13.Inline Temp 14.Replace Temp with
Query 15.Split Temporary
Variable
![Page 7: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/7.jpg)
For VB 8.0: 17.Create With
Statement 18.Inline With
Statement 19.Widen Scope 20.Extract Interface 21.Move Type to File 22.Introduce Parameter 23.Remove Unused
Parameter 24.Method to Property 25.Property to
Method(s)
For VB 9.0::26.Extract XML
Literals to Resource
27.Make Explicit 28.Make Explicit
(and Name Anonymous Type)
29.Make Implicit 30.Name
Anonymous Type
VB Refactorings in 2008
![Page 8: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/8.jpg)
DemoRefactor! 2008
![Page 9: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/9.jpg)
• Benefits• Less typing• Less memorizing of names and grammar• Fewer errors
• IntelliSense Everywhere• New line, Expressions, Keywords, Variables
• IntelliSense Features• Transparency• Filter-As-You-Type• Documentation: Keyword & Syntax tips
Getting Productive with IntelliSense
![Page 10: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/10.jpg)
DemoGetting Productive with IntelliSense in VB 2008
![Page 11: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/11.jpg)
11
LINQ
Objects
<book> <title/> <author/> <year/> <price/></book>XM
L
.NET Language Integrated Query
C# 3.0 VB 9.0 Others…
Relational
LINQ toObjects
LINQ toSQL
LINQ toXML
LINQ toEntities
LINQ toDataSets
Language INtegrated Query
![Page 12: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/12.jpg)
Dim c As New SqlConnection(…)c.Open()Dim cmd As SqlCommand( _ "SELECT c.Name, c.Phone “ & _ "FROM Customers c” & _ "WHERE c.City = @p0")cmd.Parameters("@p0“) = "London"Dim dr As DataReader= c.Execute(cmd)While (dr.Read()) Dim name As String = r.GetString(0) Dim phone As String= r.GetString(1) Dim date As DateTime = r.GetDateTime(2)End Whiler.Close()
Queries in quotes
Loosely bound arguments
Loosely typed result sets
Querying Relational DataAccessing data the hard way
![Page 13: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/13.jpg)
Public Class Customer …
Public Class Northwind Inherits DataContext
Public Property Customers As Table(Of Customer)
…End Class
Dim db As New Northwind(…)Dim contacts = _ From cust in db.Customers _ Where cust.City = "London" Select cust.Name, cust.Phone
For Each custInfo in contacts ColdCall(custInfo.Name, custInfo.Phone)Next
Classes describe data
Compile-time checking
Integrated query syntax
Strongly typed results
Tables are like collections
Accessing Data with LINQQuerying Relational Data
![Page 14: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/14.jpg)
DemoLINQ Tips & Tricks
![Page 15: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/15.jpg)
LINQ Demo SummaryBest Practices, Gotchas, FAQs• IntelliSense• Query result shape• Aliasing columns• Composing queries• Ordering operators• Designing for Performance• The Aggregate operator• Understanding Deferred Execution• Debugging• Running SQL from VB/C#
![Page 16: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/16.jpg)
DemoSay it in XML!
![Page 17: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/17.jpg)
XML in VS 2008 Topics Covered
• Inline XML in VB• Embedded Expressions• XLinq• Axis Properties• Children, Descendants, Attributes
• XML IntelliSense for VB• XML Case Sensitivity• Multi-Line Strings
![Page 18: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/18.jpg)
Summary
• What We’ve Seen• IDE Improvements• Refactor!• New IntelliSense• LINQ• Integrated XML Support
• Call to Action• Use the demo code. Try it out.• Look up the resources.• Tell us your feedback & what you want to
see in the future.
![Page 19: Visual Basic 2008 Tips and Tricks](https://reader035.vdocuments.us/reader035/viewer/2022062720/5681332c550346895d9a25b0/html5/thumbnails/19.jpg)
Resources
Visual Basic Developer Centerhttp://msdn.com/vbasic
Blogshttp://blogs.msdn.com/vbteam (VB Team)http://blogs.msdn.com/bethmassi (Beth Massi)
Refactor!http://msdn.microsoft.com/vbasic/bb693327
Visual Basic Forumshttp://forums.msdn.microsoft.com/en-US/tag/visualbasic/forums/
Connecthttps://connect.microsoft.com/VisualStudio