Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Visual Basic (.NET)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Simple example === The following is a very simple Visual Basic program, a version of the classic "[[Hello, World!]]" example created as a console application: <syntaxhighlight lang="vbnet"> Module Module1 Sub Main() ' The classic "Hello, World!" demonstration program Console.WriteLine("Hello, World!") End Sub End Module </syntaxhighlight> It prints "''Hello, World!''" on a [[command-line interface|command-line window]]. Each line serves a specific purpose, as follows: <syntaxhighlight lang="vbnet"> Module Module1 </syntaxhighlight> This is a module definition. Modules are a division of code, which can contain any kind of object, like constants or variables, functions or methods, or classes, but can not be instantiated as objects like classes and cannot inherit from other modules. Modules serve as containers of code that can be referenced from other parts of a program.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/aaxss7da(VS.80).aspx |title=Module Statement |publisher=MSDN β Developer Center |access-date=January 20, 2010 |archive-date=January 9, 2010 |archive-url=https://web.archive.org/web/20100109092122/http://msdn.microsoft.com/en-us/library/aaxss7da(VS.80).aspx |url-status=live }}</ref><br />It is common practice for a module and the code file which contains it to have the same name. However, this is not required, as a single code file may contain more than one module or class. <syntaxhighlight lang="vbnet"> Sub Main() </syntaxhighlight> This line defines a subroutine called "Main". "Main" is the entry point, where the program begins execution.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/ms235406(VS.80).aspx |title=Main Procedure in Visual Basic |publisher=MSDN β Developer Center |access-date=January 20, 2010 |archive-date=January 28, 2010 |archive-url=https://web.archive.org/web/20100128090733/http://msdn.microsoft.com/en-us/library/ms235406(VS.80).aspx |url-status=live }}</ref> <syntaxhighlight lang="vbnet"> Console.WriteLine("Hello, world!") </syntaxhighlight> This line performs the actual task of writing the output. ''Console'' is a system object, representing a command-line interface (also known as a "console") and granting programmatic access to the operating system's [[standard streams]]. The program calls the ''Console'' method ''WriteLine,'' which causes the string passed to it to be displayed on the console. Instead of Console.WriteLine, one could use MsgBox, which prints the message in a dialog box instead of a command-line window.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/3cf7t4xt(VS.80).aspx |title=Visual Basic Version of Hello, World |publisher=MSDN β Developer Center |access-date=January 20, 2010 |archive-date=January 11, 2010 |archive-url=https://web.archive.org/web/20100111152427/http://msdn.microsoft.com/en-us/library/3cf7t4xt(VS.80).aspx |url-status=live }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)