How do I perform a code in VB like EXEC in the SQL statement?

xiaoxiao2021-03-06  105

Using an API references vb6a.dll (Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long) may be implemented and executed the command character string String expressions (http://blog.9cbs.net/northwolves/archive/2004/04/05/19592.aspx), but because VB6A.DLL can only be applied to the IDE environment, the program is compiled, it is inevitable, unable to generate an executable file, such as:. Option ExplicitPrivate Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec as Long, ByVal Unknownn1 as Long, ByVal Unknownn2 as Long, ByVal fCheckOnly as Long) as LongPrivate Function ExecuteLine (sCode as String, Optional fCheckOnly As Boolean) As Boolean ExecuteLine = EbExecuteLine (StrPtr (sCode), 0 &, 0 &, Abs (fCheckOnly)) = 0End FunctionPrivate Sub Command1_Click () ExecuteLine "dim pi as double" ExecuteLine "pi = 4 * atn (1)" ExecuteLine "msgbox" "pi =" "& pi" End Sub

How to solve this problem, I have checked a lot of information, including the discussion in many forums, and I have not perfectly solved. Personally think that the ScriptControl control call is convenient: Option Explicitsub main () DIM SCR AS Object, mysub as stringset scR = CreateObject "Msscriptcontrol.scriptcontrol") mysub = "SUB MSG ()" & vbrlf mysub = mysub & "msgbox" "Today is" "& WeekDayName (WeekDay (Date) &"! "", Vbokcancel vbinformation, "prompt" "" "" "Mysub = mysub & vbrlf &" end sub "scr.language =" vbscript "scr.addcode mysub scra .Executestate" msg "set scR = Nothingend SUB The above code can run correctly before and after compilation.

转载请注明原文地址:https://www.9cbs.com/read-103398.html

New Post(0)