Grappling with Framework Class Descriptions

Team Fly 

Page 5

In fact, until VB.NET, the Visual Basic language didn't even permit the use of braces, semicolons, or brackets. Blessed simplicity, including the avoidance of extraneous junk punctuation, has always been a hallmark of Visual Basic.

To make this usable, to-the-point, Visual Basic-style sample code, you have to eliminate the C-flavored elements. What follows is a simplified, and pure-VB.NET, translation of this same sample. In addition to being written in recognizable VB programming style, it also has the advantage of focusing on IndexOf, the method being illustrated. The example displayed above from Help is overly complex: involving a loop, word counting, and one of the less frequently used of the IndexOf method's over-loaded variations. The idea that the example is supposed to be demonstrating gets lost in a mess of irrelevancies. To be really helpful to VB programmers, Help code and Help narrative explanations should be written by a professional writer/programmer, not simply someone technically competent, with a strong C bias. And the example code should simply illustrate the method being explained, like this:

 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim s As String = _ "Now is the time for all good men to come to the aid of their party." Dim found As Integer = s.IndexOf("men") Console.Write(found) End Sub 

Grappling with Framework Class Descriptions

You have to learn how to translate the class descriptions in the Object Browser, online documentation, or Help into useable VB code. Sure, there's example code in many Help entries, but that code all too often doesn't precisely demonstrate the syntax you are looking for (it was written by C programmers, after all).

Other entries offer no example code at all. There are tens of thousands of members in VB.NET, each with its own signature (parameter list) or set of signatures (thanks to overloading). And as you'll see in this chapter, even seemingly similar classes can require quite different instantiation and different syntactic interactions with other classes to accomplish a particular job.

You therefore frequently have to read a description in Help, the Object Browser, or other documentation and then translate that description into executable source code.

Press Ctrl+Alt+J to open the VB.NET Object Browser. Locate System.IO.File, then in the right pane locate the first version of the Create method, as shown in Figure 1.1. In the lower pane, you see this information:

 Public Shared Function Create(ByVal path As String) As System.IO.FileStream      Member of: System.IO.File 
Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net