VB.net program cannot be compiled in command line

  • Thread starter Thread starter Lovely Dola
  • Start date Start date
L

Lovely Dola

I have the following simple "Hello, world" vb.net program named "prog01.vb" :

Module prog01
sub Main()
MsgBox("Hello, world!")
end sub
end Module

and compile it using vbc.exe as follows:

vbc /reference:Microsoft.VisualBasic.dll prog01.vb

but receive error messages as follows:

prog01.vb(3) : error BC30451: Name 'MsgBox' is not declared.

I have no Visual Studio.NET but use .NET Framework SDK 1.1 instead.
Could anyone pls tell me what's wrong with the program or the
compilation process?
 
Lovely Dola,
The /reference on the command line only allows you to use the Types
(classes, modules, structures, delegates, and interfaces) within the listed
assembly.

You also need to either give the fully name or import the namespace where
MsgBox is.

Either of the following should work (along with the /reference on the
command line):

Imports Microsoft.VisualBasic
Module prog01
sub Main()
MsgBox("Hello, world!")
end sub
end Module

Module prog01
sub Main()
Microsoft.VisualBasic.Interaction.MsgBox("Hello, world!")
end sub
end Module

Hope this helps
Jay
 
Back
Top