通过控制台调用 VB 6 应用程序中的子例程或函数
Calling sub routine or function in VB 6 application via console
我想制作一个简单的应用程序,其中包含 1 个方法和 2 个参数,并且
该应用程序可以通过 console/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
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
所以在 console/cmd 中我只是像这样调用那个函数
myApp.exe plus 3 2
我怎样才能做到这一点?
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
我想制作一个简单的应用程序,其中包含 1 个方法和 2 个参数,并且 该应用程序可以通过 console/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
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
所以在 console/cmd 中我只是像这样调用那个函数
myApp.exe plus 3 2
我怎样才能做到这一点?
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