网站建设资讯

NEWS

网站建设资讯

vb.net入口主函数 vbnet implements

VB.net窗体程序如何让cmd调用?

VB.NET 里面会有一个main方法表示函数的入口

专注于为中小企业提供成都做网站、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业平乡免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

main方法的参数就是命令行传给它的

shutdown.exe能直接调用是因为你的环境变量有C盘的windows目录

你只要在你程序的输出目录(一般为bin)里面打开命令行输入程序名称.exe就可以直接执行你的窗体

如果你要调试输入命令的效果,你打开你项目的属性,找到调试里面的命令行参数,在里面输入测试参数就能在你main函数里面看到结果了

那如果你想打开任何命令行都可以执行你的窗体程序,那你把你程序的安装目录设置为环境变量,这样就可以直接执行这个命令了

vb.net工程的main函数在哪个文件

看来您不了解vb.net的程序结构。vb.net的Windows方面的工程分为两种:窗体应用程序和控制台应用程序。窗体应用程序没有Main函数,直接从一个窗体启动(例如启动对象设置为Form1),启动时会自动加载Form1.Designer.vb获得控件信息(窗体设计器自动生成),Form1.vb获得你编写的代码和事件处理程序。控制台应用程序需要从一个Module启动。一个控制台应用程序可以含有多个模块,但启动时只调用选择的启动对象里面的Sub Main()。

详细阐述 vb.net 中main

每个 Visual Basic 应用程序均必须包含一个称为VB.NET Main过程。该过程为应用程序的起始点并为应用程序提供总体控制。.NET Framework 在已加载应用程序并准备将控制传递给它时,将调用 Main 过程。除非您要创建 Windows 窗体应用程序,否则就必须为自运行的应用程序编写 Main 过程。

Main 中包含首先运行的代码。在 Main 中,可以确定在程序启动时首先加载的窗体,确定系统上是否已在运行您的应用程序副本,为应用程序建立一组变量,或者打开应用程序需要的数据库。

VB.NET Main过程的要求

独立运行的文件(扩展名通常为 .exe)必须包含 Main 过程。库(例如,扩展名为 .dll)不独立运行,因而不需要 Main 过程。可以创建的不同类型的项目的要求如下:

控制台应用程序可以独立运行,而且您必须提供至少一个 Main 过程。

Windows 窗体应用程序可以独立运行。但是,Visual Basic 编译器会在此类应用程序中自动生成一个 Main 过程,因而您不需要编写此过程。

类库不需要 Main 过程。这些类库包括 Windows 控件库和 Web 控件库。作为类库部署 Web 应用程序。

声明VB.NET Main过程

有四种方法可以声明 Main 过程。它可以使用参数或不使用参数,可以返回值或不返回值。

注意

如果在类中声明 Main 过程,则必须使用 Shared 关键字。在模块中,Main 不必是 Shared。

最简单的方法是声明一个不使用参数或不返回值的 Sub 过程。

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

还可以返回一个 Integer 值,操作系统将其作为程序的退出代码。其他程序可以通过检查 Windows ERRORLEVEL 值来测试该代码。若要返回退出代码,必须将VB.NET Main过程声明为 Function 过程而不是 Sub 过程。

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

还可以采用一个 String 数组作为参数。数组中的每个字符串均包含一个用于调用程序的命令行参数。您可以根据它们的值采取不同的操作。

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

可以声明VB.NET Main过程来检查命令行参数而不返回退出代码,如下所示。

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


标题名称:vb.net入口主函数 vbnet implements
分享路径:http://cdweb.net/article/dohiigj.html