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

Visual Basic 2008 Tips and Tricks by myf11043

VIEWS: 32 PAGES: 20

									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 responsiveness
   http://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: 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
                                Type)
22. Introduce Parameter
                            29. Make Implicit
23. Remove Unused
                            30. Name Anonymous
    Parameter
                                Type
24. Method to Property
25. Property to Method(s)
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
     LINQ
     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

                                                              <book>
                                                                <title/>
                                                                <author/>
                                                                <year/>
                                                                <price/>
                                                              </book>




       Objects                  Relational                    XML

11
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 =
        r.GetDateTime(2)
        End While
        r.Close()
Querying Relational Data
Accessing Data with LINQ
    Public Class Customer …                         Classes describe
                                                    data
    Public Class Northwind
     Inherits DataContext
                                                     Tables are like
      Public Property Customers As Table(Of          collections
    Customer)
             …
    End Class                                    Compile-time
                                                 checking
    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
Demo
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#
Demo
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
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 Center
 http://msdn.com/vbasic

 Blogs
 http://blogs.msdn.com/vbteam (VB Team)
 http://blogs.msdn.com/bethmassi (Beth Massi)

 Refactor!
 http://msdn.microsoft.com/vbasic/bb693327

 Visual Basic Forums
 http://forums.msdn.microsoft.com/en-
 US/tag/visualbasic/forums/

 Connect
 https://connect.microsoft.com/VisualStudio
            THANK YOU!




Future Directions for VB: Thurs 14:30, Rm 6
     http://blogs.msdn.com/vbteam
    Lisa.Feigenbaum@microsoft.com

								
To top