Beth's Chinese blog
We just published another community article onto the Visual Basic Developer Center by Maurice de Beijer, Visual Basic MVP, on .NET RIA Services. Maurice explains what they are and how they help you build Silverlight line-of-business applications. Sample source code is included here.
Read Getting Started with .NET RIA Services.
Many thanks to Maurice for donating this article. I’m looking forward to part 2 myself ;-)
Enjoy!
At the MVP summit this year Kathleen and I asked MVPs using Visual Basic what kinds of applications they’re building, what other technologies they’re using, what their favorite features are, and more. Many thanks to all of you who humored me! The result? A great series of videos on Channel 9. (I told you I’d get back at you Jim Duffy!) ;-)
But Lisa decided to take this a step further to give more people, not just MVPs, a chance to tell their story. Check out www.imavb.net (which redirects to a page on the VB Dev Center) that also has links to written interviews submitted by MVPs. Here’s your chance to submit your own story and have your interview appear on the VB Dev Center!
Okay I just threw a lot of links at you up there. Just visit www.imavb.net!
If you haven’t seen it yet, we’ve got a new article from Robert Green (VSTO MVP) up on the Visual Basic and VSTO Dev Centers. In this article, learn how you can use Visual Basic to build application-level add-ins that automate common Microsoft Office tasks. It’s a good introduction to Office development with Visual Studio so check it out!
Create an Application-Level Add-In to Automate Common Office Tasks
Joe Stagner’s second podcast is up and this time he’s interviewing the one and only Lisa Feigenbaum from the VB team. Joe pins her down on what the future of VB really is and discusses perceptions, parity and co-evolution. It’s a great interview so check it out:
Misfit Geek Podcast - Episode #2 Does VB have a Future?
I got a little nervous at about 31 minutes into it when Joe calls me the “Princess of Visual Basic” (better than an old queen I guess ;-)) and mentions that there should be a crew of Beth Massi’s out there to crank out VB content. I can think of more than a few people besides my family that would be scared to have more copies of me running around and screaming out there. LOL. But many many thanks, Joe! I’ll keep it coming.
Last week I spoke at DevTeach in Vancouver which was held at the beautiful Four Seasons in downtown. I love this Canadian conference because the attendees are great – super friendly and social, and ask a lot of great questions. I mostly interacted with folks building applications for the government or working as consultants and wanting to freshen up their .NET skills. It was also nice to see a good number of VB developers here. I gave three talks and ended up in the top 3 speakers overall which was great :-).
Future Directions for Visual Basic and C#
Before the conference I did a joint user’s group talk and about 120 people showed up to see “Future Directions for Visual Basic and C#” which has also been delivered before at PDC and TechEd by folks on the Language Team. I did a flavor of Jonathan Aneja’s TechEd talk but I also included new C# features which I have to say are a welcome relief to me personally. Unfortunately my VM was misbehaving so badly that Visual Studio was running at a snail’s pace. But I joked around and got through it ending up with some good comments and questions. I did the talk again at the conference and my VM was just fine – go figure. As a bonus for the conference attendees I also included a VB REPL demo and it was a hit. Check out John’s TechEd recording for variations of the VB demos that I showed.
Most interesting was the group that attended the talk. It was almost a 50/50 split between VB and C# devs in the room with some cross-over (doing both). I even had 3 C++ programmers attend. I started out with all the new VB features, then showed all the new C# features and then finished up with the new features in both. I had a lot of fun with the session, jabbing at both languages here and there and poking fun in places where one was catching up to the other and vice versa. Here’s the breakdown of new stuff in each language:
Y = Already exists in VB9/C#3Y = New in VB10/C#4
Check out the Visual Studio 2010 Language samples and language walkthroughs for details on each of these features.
The C# crowd seemed in particular to like the Named & Optional parameter support commenting that “It’s useful because it saves me writing code”. I actually showed all of the C# 4 features in one method that demonstrated COM interop with Office lifted from this walkthrough. The VB crowd was particularly pleased to see no more underscores and auto-implemented properties. And those that commented in the session were pleased to see the language parity. I’m just glad I didn’t get any rotten tomatoes thrown at me from either side. :-)
Here’s some more resources to check out:
Data Sources and Data Binding with WPF
I’ve done this talk many times before and it’s always a lot of fun. I've been blogging on data binding in WPF as well as doing How Do I videos for a while now. This talk takes WPF data binding from a Winforms developer perspective and I try to demonstrate that investments made in your Winforms data sources can be used in WPF. The crowd seemed relieved ;-). I also showed the drag-drop data binding in Visual Studio 2010 building a form similar to what Milind showed in this Channel 9 interview. The team has also been blogging heavily about WPF data binding in VS2010 on the VS Data blog so check it out.
Conquering XML with LINQ in Visual Basic 9
This has got to be one of my most favorite talks of all time. I've written a lot on this topic. I have been doing this one for a couple years now and what’s great about it is that it never gets old. It’s amazing how many folks are still not aware of XML Literals in VB. Only about 10% of attendees had used them before so I started with the basics and worked my way up into the demos. This talk scored very high for me and I think it’s because I show a lot of practical examples of using XML Literals and LINQ to XML. I didn’t show any betas or unreleased bits either and I think folks appreciated that they could go home and get working with it right away.
I got through all the demos and showed a good amount of Open XML SDK to manipulate Office 2007 documents. I also showed off the VSTO Power tools a bit for viewing the Open XML packages. Amongst the many demos we went through, we built a letter generator from scratch like I've shown before here. I also did my famous Virtual Earth demo that people always enjoy.
I also attended a few sessions myself on MVVM and Silverlight so you may see more of that cranking out of this blog at some point. ;-) I look forward to the next DevTeach!
One of the many samples released for Visual Studio 2010 Beta 1 that you should be aware of are examples of WPF data binding against Entity Data Models. You can find some easy to follow samples here: http://code.msdn.microsoft.com/WPFDatabinding
This sample demonstrates how to create a WPF Forms solution that checks user input with validation code, demonstrates common controls such as DataGrid and ComboBox, and shows typical data manipulation including create, read, update, and delete. The sample solution is available in both Visual Basic and C# and is intended for use with Visual Studio 2010 Beta 1 and with the .NET Framework 3.5. In the future, we will release a sample that performs with the .Net Framework 4.0 Beta.
Check out the VS Data Team blog for more information on WPF data-binding and Karl’s blog on a great WPF sample series.
Kathleen McGrath has started a series where she takes Visual Studio 2010 walkthroughs and demonstrates them with a screen-cast each week on Channel 9. If you’re just digging into the VS2010 Beta you should definitely check these out to help get you started on all the new features.
Don’t miss my favorites so far…
Visual Basic 10 (in Visual Studio 2010) is getting a new feature called Collection Initializers which contains the same functionality as the C# 3 feature but it takes it one step further. Let me show you what I mean.
Visual Basic 9 (in Visual Studio 2008) already has Object Initializers which come in handy when you want to quickly populate some public properties on an object. For instance, say I have a class called Student that has Name (string), Age (integer) and Score (integer) public properties. In a single line of code I can initialize a new object and specify only the properties I want to set as long as the Student class has a default constructor:
Dim s As New Student With {.Age = 29, .Name = "Beth"}
Object Initializers are also used often in LINQ statements when you want to project selected values into your own named objects:
'produces a collection of Student objects from a LINQ query. IEnumerable(Of Student): Dim myStudents = From contact In ContactList _ Select New Student _ With {.Age = contact.Age, _ .Name = contact.Name}
However if you want to create a Generic.List(Of Student) in Visual Basic 9 you can’t do it in one line. A trick is to use Array Initializers to populate an array with objects using Object Initializers and then call ToList to create the generic List:
'Use Array & Object Initializers to create an array of Students Dim s As Student() = {New Student With {.Age = 10, .Name = "Beth"}, _ New Student With {.Age = 11, .Name = "Alan"}, _ New Student With {.Age = 12, .Name = "Robert"}, _ New Student With {.Age = 13, .Name = "Jenn"}} 'Convert the array to a Generic.List Dim studentList As List(Of Student) = s.ToList()
But this is really less than ideal because of the casting. What we really want to do is have the objects automatically added to the list via the List.Add method. Collection Initalizers do just that. They are basically just a shorthand syntax for calling the Add method explicitly on the collection.
Collection Initializers in C# 3 look like this:
var nums = new List<int> { 1, 2, 3, 4, 5 };
var studentList = new List<Student> {new Student {Age = 10, Name = "Beth"}, new Student {Age = 11, Name = "Alan"}, new Student {Age = 12, Name = "Robert"}, new Student {Age = 13, Name = "Jenn"}};
Visual Basic 10 now also provides this feature using the From keyword (note, VB 10 does not require underscores and provides a new syntax coloring):
Dim nums As New List(Of Integer) From {1, 2, 3, 4, 5} Dim studentList As New List(Of Student) From {New Student With {.Age = 10, .Name = "Beth"}, New Student With {.Age = 11, .Name = "Alan"}, New Student With {.Age = 12, .Name = "Robert"}, New Student With {.Age = 13, .Name = "Jenn"}}
What’s happening in these cases is the compilers are looking for the existence of an Add method on the collection and calling that for you. However in VB 10 they took it a step further. In C# 3 the Add method must be an instance method on the collection but in VB 10 you can provide your own Extension Method and provide your own functionality. For instance, we can make the calling syntax even simpler by writing an extension method that does the object initialization as well:
<Runtime.CompilerServices.Extension()> Sub Add(ByVal list As List(Of Student), ByVal age As Integer, ByVal name As String) list.Add(New Student With {.Age = age, .Name = name}) End Sub
Now we can initialize our Generic.List(Of Student) like so:
Dim studentList As New List(Of Student) From {{10, "Beth"}, {11, "Alan"}, {12, "Robert"}, {13, "Jenn"}}
You can also omit the From keyword and pass the collection initialization directly to the constructor of the Generic.List because the List has an overloaded constructor that accepts an IEnumerable:
Dim nums As New List(Of Integer)({1, 2, 3, 4, 5})
So the rule of thumb is, use From to call the Add method or you could pass directly to call the constructor if it accepts an IEnumerable. Passing values this way directly isn't as efficient though because an array is created first and then passed to the constructor (which then loops through and calls Add internally). Using the From keyword calls the Add method directly for you.
Pick up a copy of the Visual Studio 2010 Beta 1 and try it out for yourself.
Joe Stagner, ASP.NET/Web community guru, has just launched a new podcast on MisfitGeek.com. In this first episode he talks with Scott Hunter, a Senior Program Manager Lead on the ASP.NET Team, about the future of Web Forms and how Web Forms compares with ASP.NET MVC. He also talks about web data controls and compares the web forms development experience to the ease of VB6 forms development which is interesting to me.
Episode #1 - Scott Hunter on the Future of Web Forms
This Joe’s first podcast and he’s taking suggestions on how to make it better so please send him comments here.
Last week Alan and I headed up to Yosemite National Park with my sister and her boyfriend and Robert Green (VSTO MVP and log-time friend) and his wife, Colette. We had an absolutely fabulous time and I recommend that everyone in the world come visit. And believe me, Memorial Day weekend it seems like everyone in the world is doing just that! ;-) Luckily we stayed the whole week so after Sunday people left the valley and we were left with a peaceful vacation.
The falls are full, the Merced river is flowing high and the flowers are all in bloom.
We all agreed that heaven must look something like this. This is the view from inspiration point just as you come through the Wawona tunnel – showing Half Dome at the east end of the Yosemite Valley, El Capitan to the North and Bridal Vail Falls to the South (click to enlarge).
And here’s Half Dome (left), Vernal Falls (lower) and Nevada Falls (upper) from Glacier Point. Stunning. We hiked down the 4-mile trail from Glacier Point down to the valley with views of Yosemite falls (first and fourth picture above) the whole time.
We stayed in a cottage in Yosemite West and did a lot of day hiking and long valley walks. The highlight was Robert, Colette and I hiked 16.4 miles up to the top of Half Dome and back on Tuesday which took us about 10 hours. You hike up to Vernal then Nevada falls first and then a long walk up the John Muir trail through Little Yosemite Valley and cut over onto the Half Dome trail. I’ve done it once before about 15 years ago but I didn’t remember how hard those cables were, especially coming down, but we did it!
Yosemite only takes about 3.5 hours to drive there from my house so I’m already thinking about our next long weekend….
I really enjoyed this vacation.