Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Visual Basic 2008 Tips and Tricks by myf11043


									Visual Basic 2008 Tips and Tricks
Lisa Feigenbaum
Program Manager
Microsoft Visual Studio Languages
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 responsiveness
IDE Improvements
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
VB Refactorings in 2005

1. Reorder Parameters     8. Extract Method
2. Surrounds With         9. Extract Property
3. Encapsulate field      10. Create Overload
4. Reverse Conditional    11. Introduce Local
5. Simplify expression    12. Introduce constant
6. Move initialization
   to declaration         13. Inline Temp
7. Split initialization   14. Replace Temp with
   from declaration           Query
8. Move declaration       15. Split Temporary
   near reference             Variable
VB Refactorings in 2008
For VB 8.0:                 For VB 9.0::
17. Create With Statement   26. Extract XML Literals
18. Inline With Statement       to Resource
19. Widen Scope             27. Make Explicit
20. Extract Interface       28. Make Explicit (and
                                Name Anonymous
21. Move Type to File
22. Introduce Parameter
                            29. Make Implicit
23. Remove Unused
                            30. Name Anonymous
24. Method to Property
25. Property to Method(s)
Refactor! 2008
Getting Productive with
• 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 in VB 2008
     Language INtegrated Query

            C# 3.0               VB 9.0                 Others…

                     .NET Language Integrated Query

       LINQ to       LINQ to     LINQ to     LINQ to         LINQ to
       Objects       DataSets      SQL       Entities          XML


       Objects                  Relational                    XML

Querying Relational Data
Accessing data the hard way

        Dim c As New SqlConnection(…)            Queries in
        c.Open()                                 quotes
        Dim cmd As SqlCommand( _
          "SELECT c.Name, c.Phone “ & _
          "FROM Customers c” & _                   Loosely bound
          "WHERE c.City = @p0")                    arguments
        cmd.Parameters("@p0“) = "London"
        Dim dr As DataReader= c.Execute(cmd)
        While (dr.Read())                        Loosely typed
           Dim name As String = r.GetString(0)   result sets
           Dim phone As String= r.GetString(1)
           Dim date As DateTime =
        End While
Querying Relational Data
Accessing Data with LINQ
    Public Class Customer …                         Classes describe
    Public Class Northwind
     Inherits DataContext
                                                     Tables are like
      Public Property Customers As Table(Of          collections
    End Class                                    Compile-time
    Dim db As New Northwind(…)
    Dim contacts = _
      From cust in db.Customers _                   Integrated
      Where cust.City = "London"                    query syntax
      Select cust.Name, cust.Phone

    For Each custInfo in contacts
      ColdCall(custInfo.Name, custInfo.Phone)   Strongly typed
    Next                                        results
LINQ Tips & Tricks
LINQ Demo Summary
Best 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#
Say it in XML!
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
• 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.
 Visual Basic Developer Center

 Blogs (VB Team) (Beth Massi)


 Visual Basic Forums

            THANK YOU!

Future Directions for VB: Thurs 14:30, Rm 6

To top