In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what are the four declaration methods in the VB.NET Main process, which are concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
VB.NET programming language has a wide range of applications, and the particularity of its writing method has greatly attracted the attention of programmers. When we learn this language, we will encounter relevant concepts about the VB.NET Main process, so how can we correctly understand the declaration of this process? You can find some answers here.
Every Visual Basic application must contain a process called VB.NET Main. This process provides the starting point for the application and provides overall control for the application. The .NET Framework calls the Main procedure when the application is loaded and is ready to pass control to it. Unless you want to create a Windows forms application, you must write Main procedures for self-running applications.
The Main contains the code that runs first. In Main, you can determine which form is loaded first when the program starts, determine whether a copy of your application is already running on the system, create a set of variables for the application, or open the database that the application needs.
Requirements of VB.NET Main process
Files that run independently (usually with a .exe extension) must contain Main procedures. Libraries (for example, with a .dll extension) do not run independently and therefore do not require Main procedures. The requirements for the different types of projects that can be created are as follows:
The console application can run independently, and you must provide at least one Main procedure.
Windows forms applications can run independently. However, the Visual Basic compiler automatically generates a Main procedure in such an application, so you don't need to write this procedure.
The class library does not require a Main procedure. These class libraries include Windows control library and Web control library. Deploy the Web application as a class library.
Declare the VB.NET Main procedure
There are four ways to declare a Main procedure. It can use parameters or no parameters, and can return a value or no value.
Be careful
If you declare a Main procedure in a class, you must use the Shared keyword. In the module, Main does not have to be Shared.
The easiest way is to declare a Sub procedure that takes no parameters or returns no values.
Module mainModule
Sub Main ()
MsgBox ("The Main procedure"
Is starting the application. ")
'Insert call to appropriate
Starting place in your code.
MsgBox ("The application"
Is terminating. ")
End Sub
End ModuleMain
You can also return an Integer value that the operating system uses as the exit code for the program. Other programs can test the code by checking the Windows ERRORLEVEL value. To return the exit code, the VB.NET Main procedure must be declared as a Function procedure rather than a Sub procedure.
Module mainModule
Function Main () As Integer
MsgBox ("The Main procedure"
Is starting the application. ")
Dim returnValue As Integer = 0
'Insert call to appropriate
Starting place in your code.
'On return, assign appropriate
Value to returnValue.
'0 usually means successful
Completion.
MsgBox ("The application is"
Terminating with error level "_
& CStr (returnValue) & ".")
Return returnValue
End Function
End ModuleMain
You can also take a String array as a parameter. Each string in the array contains a command-line argument for invoking the program. You can take different actions depending on their values.
Module mainModule
Function Main (ByVal cmdArgs ()
As String) As Integer
MsgBox ("The Main procedure is"
Starting the application. ")
Dim returnValue As Integer = 0
'See if there are any arguments.
If cmdArgs.Length > 0 Then
For argNum As Integer = 0 To
UBound (cmdArgs, 1)
'Insert code to examine cmdArgs
(argNum) and take
'appropriate action based on its value.
Next argNum
End If
'Insert call to appropriate starting
Place in your code.
'On return, assign appropriate
Value to returnValue.
'0 usually means successful completion.
MsgBox ("The application is"
Terminating with error level "_
& CStr (returnValue) & ".")
Return returnValue
End Function
End Module
You can declare a VB.NET Main procedure to check command-line arguments without returning an exit code, as shown below.
Module mainModule
Sub Main (ByVal cmdArgs () As String)
MsgBox ("The Main procedure is"
Starting the application. ")
Dim returnValue As Integer = 0
'See if there are any arguments.
If cmdArgs.Length > 0 Then
For argNum As Integer = 0 To
UBound (cmdArgs, 1)
'Insert code to examine cmdArgs
(argNum) and take
'appropriate action based on its value.
Next argNum
End If
'Insert call to appropriate
Starting place in your code.
MsgBox ("The application is"
Terminating. "
End Sub
End Module
What are the four declaration methods in the VB.NET Main process? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.