200 likes | 401 Views
Visual Basic 2008 Tips and Tricks. Lisa Feigenbaum Program Manager Microsoft Visual Studio Languages http://blogs.msdn.com/vbteam Lisa.Feigenbaum@microsoft.com. VB 2008 Tips and Tricks. Session Objectives Learn language & IDE productivity features
E N D
Visual Basic 2008 Tips and Tricks Lisa Feigenbaum Program Manager Microsoft Visual Studio Languages http://blogs.msdn.com/vbteam Lisa.Feigenbaum@microsoft.com
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
You asked. We listened! • “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
Demo IDE Improvements
Code just like you think! • Refactor! for VB • Visual Studio Plug-in, available FREE on MSDN • Partnership with Developer Express, Inc. • Total: 16for VB 2005, 14more for VB 2008 • Six Refactorings in C# 2005 & 2008: • Rename • Extract Method • Remove/Reorder parameters • Promote Local • Extract Interface • Encapsulate Field
VB Refactorings in 2005 • Reorder Parameters • Surrounds With • Encapsulate field • Reverse Conditional • Simplify expression • Move initialization to declaration • Split initialization from declaration • Move declaration near reference • Extract Method • Extract Property • Create Overload • Introduce Local • Introduce constant • Inline Temp • Replace Temp with Query • Split Temporary Variable
VB Refactorings in 2008 For VB 8.0: • Create With Statement • Inline With Statement • Widen Scope • Extract Interface • Move Type to File • Introduce Parameter • Remove Unused Parameter • Method to Property • Property to Method(s) • For VB 9.0:: • Extract XML Literals to Resource • Make Explicit • Make Explicit (and Name Anonymous Type) • Make Implicit • Name Anonymous Type
Demo Refactor! 2008
Getting Productive with IntelliSense • 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
Demo Getting Productive with IntelliSense in VB 2008
<book> <title/> <author/> <year/> <price/> </book> XML Relational Objects LINQ Language INtegrated Query C# 3.0 VB 9.0 Others… .NET Language Integrated Query LINQ toObjects LINQ toDataSets LINQ toSQL LINQ toEntities LINQ toXML
Querying Relational Data Accessing data the hard way Queries in quotes 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 While r.Close() Loosely bound arguments Loosely typed result sets
Querying Relational Data Accessing Data with LINQ Classes describe data Public Class Customer … Public Class Northwind Inherits DataContext Public Property Customers As Table(Of Customer) … End Class Tables are like collections Compile-time checking Dim db As New Northwind(…) Dim contacts = _ From custin db.Customers _ Where cust.City= "London" Select cust.Name, cust.Phone For Each custInfo in contacts ColdCall(custInfo.Name, custInfo.Phone) Next Integrated query syntax Strongly typed results
Demo LINQ Tips & Tricks
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#
Demo Say it in XML!
XML in VS 2008Topics Covered • Inline XML in VB • Embedded Expressions • XLinq • Axis Properties • Children, Descendants, Attributes • XML IntelliSense for VB • XML Case Sensitivity • Multi-Line Strings
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.
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
THANK YOU! • Future Directions for VB: Thurs 14:30, Rm 6 • http://blogs.msdn.com/vbteam • Lisa.Feigenbaum@microsoft.com