Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of

Parameter Passing

The next line of code in Listing 1 passes a single argument, n, to the SquareIt() procedure:

 SquareIt n

The way in which that argument is passed to SquareIt(), however, is vastly different between VB6 and VBN.

When VB6 passes n to SquareIt(), it passes the lvalue (80,000) to the procedure. This is the default argument passing mechanism used by VB6. What this means is that the following statement:

Public Sub SquareIt(val As Long)

actually looks like this:

Public Sub SquareIt(80,000 As Long)

Because VB6 knows that the SquareIt() procedure is passed the lvalue of the parameter, VB6 does not allocate any memory for val. Instead, SquareIt() uses the lvalue passed to it to locate the rvalue to be used in the procedure.

If that's the case, what's the purpose of the As Long part of the SquareIt() argument list? The only reason the As Long keywords are present in the argument list is so VB6 knows how many bytes to grab at the lvalue it was just passed. (In other languages—such as C++, C#, and Java—the As Long keywords would be called data type specifier.) Therefore, the argument list for SquareIt() tells VB6: "Go to memory address 80,000, grab eight bytes of memory from that address, and use it as a Long data type in this procedure." (The Long data type is bigger in VBN and requires eight bytes of storage.)

  • + Share This
  • 🔖 Save To Your Account