Declaration and Grammar Changes

This section describes changes to variable declarations in Visual Basic .NET.

As Any

VB6 supported the As Any clause used for Declare statements. As Any suppresses type checking and allows you to pass any data type to the library procedure, as demonstrated.

Private Declare Sub Sleep Lib "kernel32" _
  (ByVal Milliseconds As Any)

Private Sub Command1_Click()

  Call MsgBox("Press [OK] to sleep")
  Dim WaitFor As Long
  WaitFor = 1000
  Call Sleep(WaitFor)
  Call MsgBox("Awake!")
End Sub

The first statement declares the API procedure Sleep. The type is declared as an As Any type. The API procedure still requires a valid argument, but if the parameter is invalid, we are not aware of it until we use File, Make or actually run ...

Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.