通过控制台调用vb6应用程序中的子程序或函数
我想做一个简单的应用程序,其中有1个方法和2个参数,并且 该应用程序可以通过控制台/CMD启动,如下所示:通过控制台调用vb6应用程序中的子程序或函数,vb6,console,console-application,Vb6,Console,Console Application,我想做一个简单的应用程序,其中有1个方法和2个参数,并且 该应用程序可以通过控制台/CMD启动,如下所示: name_of_app.exe name_of_method param1 param2 例如: 我有一个名为myApp.exe的应用程序,其方法如下 Module Module1 Sub Main() Console.WriteLine("Hello World!") Dim x As Integer, y As Integer
name_of_app.exe name_of_method param1 param2
例如:
我有一个名为myApp.exe
的应用程序,其方法如下
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Dim x As Integer, y As Integer
Dim total As Integer
x = Console.ReadLine()
y = Console.ReadLine()
total = plus(x, y)
Console.WriteLine("result: " & total)
Console.ReadLine()
End Sub
Private Function plus(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Module
myApp.exe plus 3 2
因此,在console/cmd中,我只是像这样调用该函数
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Dim x As Integer, y As Integer
Dim total As Integer
x = Console.ReadLine()
y = Console.ReadLine()
total = plus(x, y)
Console.WriteLine("result: " & total)
Console.ReadLine()
End Sub
Private Function plus(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Module
myApp.exe plus 3 2
我怎样才能做到这一点?我已经制作了下面这样的模块,到目前为止,我已经制作了下面这样的模块,非常感谢您的回答,但它有一个错误,它说“错误1'Me'在模块内无效”。你能解释一下你的密码吗?无论如何,谢谢你应该在“Form”中粘贴代码,因为“CallByName”方法只在Form或Class之类的对象中触发。如何在cmd中运行它?你能上传可以在VB 2010中运行的项目吗?你应该从vb6项目中生成exe,然后在cmd中运行,或者像这样运行调用“c:\myapp.exe加3 4”谢谢你的回答,但它说有一个错误“错误1‘Me’在模块内无效“.你能解释一下你的密码吗?无论如何,谢谢你应该在“Form”中粘贴代码,因为“CallByName”方法只在Form或Class之类的对象中触发。如何在cmd中运行它?你可以上传可以在VB 2010中运行的项目吗?你应该在vb6项目和cmd中生成exe,或者像这样运行调用“c:\myapp.exe加3 4”
Private Sub Form_Load()
Dim strCommand As String
Dim s() As String
Dim spliter As String
Dim returnValue As Variant
strCommand = Command
Do While InStr(1, strCommand, " ", vbTextCompare) > 0
strCommand = Replace(strCommand, " ", " ")
Loop
spliter = " "
s = Split(strCommand, spliter)
returnValue = CallByName(Me, s(0), VbMethod, Val(s(1)), Val(s(2)))
MsgBox returnValue
End Sub
Public Function Plus(ByVal Param1 As Variant, ByVal Param2 As Variant)
Plus = Param1 + Param2
End Function