The With Construct

To wrap this chapter up, allow me to say that the VB6 With construct is still supported under VB 2008. In a nutshell, the With keyword allows you to invoke members of a type within a predefined scope. Do know that the With keyword is nothing more than a typing time saver.

For example, the System.Collections namespace has a type named ArrayList, which like any type has a number of members. You are free to manipulate the ArrayList on a statement-by-statement basis as follows:

Sub Main() Dim myStuff As New ArrayList() myStuff.Add(100) myStuff.Add("Hello")

Console.WriteLine("Size is: {0}", myStuff.Count) End Sub or use the VB 2008 With keyword:

Sub Main() Dim myStuff As New ArrayList() With myStuff .Add(100) .Add("Hello")

Console.WriteLine("Size is: {0}", .Count) End With End Sub

Was this article helpful?

0 0

Post a comment