Keywords: VB Script Author: Dong Jun containing
This article introduces the easiest way, requires not high only implementing some code
If you want to use more complete features, it is
MicrSoft Script Control
Please refer to Ye Sailing articles
VBScript script uses (the Script Program and Host Program)
http://blog.9cbs.net/yefanqiu/archive/2004/10/15/137928.aspx
VBScript script is used
http://www.bjjr.com.cn/yefan/sourcecode/yfvbscript.rar
Discuss how to make your own application support script
It was also found on the blog of 9CBS, but I found that I couldn't find it again. I am grateful to the original author's prompt.
Using the range, you can use the script when you develop, and use the EXE or DLL to interface development although it is powerful, it is inconvenient, with a script, or a well-known script is more convenient.
Method 1: Make a compiler interpreter
Method 2: Using existing interpreters, script, omitted compiler
Obviously, the second method is simple. The problem is what existing interpreter (I called the scripting engine), where to find, how to support ...
Python is popular, can be used for the game script engine, but I will not use it at present (after all, I am not God)
VBA is Office VBA, with VB6 grammar, I chose this. Because I have seen VB, I am particularly kind ...
It is estimated that Kelie can't use this technology ....
The most critical is to find this legendary VBA6.dll he is responsible for explaining
Private Declare Function EbexecuteLine Lib "VBA6.DLL" (_
Byval pstringtoexec as long, _
BYVAL UNKNOWN1 As Long, _
BYVAL UNKNOWN2 As Long, _
BYVAL FCHECKONLY AS Long) As long
DLL declaration, as the name suggests, it is to implement a line
The first parameter, pointing to the pointer to the command line string
The rest of the parameters don't know what to use ...
When used:
This is convenient for packaging this
Function Stepline (Byval Cmd As String) As long 'cmd is VB6 code
DIM L As long 'temporary variable, meaning is not large
L = EbexecuteLine (strptr (Byval CMD), 0, 0, 0) 'This is the essence, simple
Debug.print CSTR (L) ":" CMD 'debugging, meaningless
END FUNCTION
You can use it directly
Debug.print Ebexecuteline (STRPTR ("Dim A As Long, B As Long, C as Long", 0, 0, 0)
Debug.print ebexecuteline (Strptr ("a =" & 3), 0, 0, 0)
Debug.print ebexecuteline (Strptr ("B =" & 5), 0, 0, 0)
Debug.print ebexecuteline (Strptr ("c =" & 2), 0, 0, 0)
Debug.print ebexecuteline (Strptr ("Clipboard.Settext (A B) / C"), 0, 0, 0)
Debug.print EbexecuteLine (Strptr ("Msgbox Clipboard.getText"), 0, 0, 0)
You can also
Stepline "Dim A As Long, B As Long, C as Long"
Stepline "a =" & 3
Stepline "B =" & 5Stepline "c =" & 2
Stepline "Clipboard.Settext (A B) / C"
Stepline "msgbox clipboard.gettext"
Or put the text in ListBox, or even progressive (of course, interested you can do the debugger yourself)
If List1.listcount = 0 THEN
Msgbox "no code"
Else
List1.listIndex = 0
DIM I as long
For i = 0 to list1.listcount - 1
Stepline List1.list (i)
NEXT
END IF
Of course, the direct execution text is also possible.
Assume that text1.text is all code
List1.clear
DIM Arr () AS String
DIM I as long
DIM S As String
Arr = split (Text1.Text, Chr (13) CHR (10))
For i = 0 to Ubound (arr ())
Stepline Arr (i)
NEXT
Simple
And these are completely object-oriented
Your program is equivalent to virtual machine, VBA6.DLL is the interpreter
What can be done in the script !! Even the API can use COM
If your virtual machine support (that is, the program provides an existing object), he can use directly (also known as an API, but you provide, not Windows offering)
Given several instance scripts (the following is the process, automatically populate the text1)
Private sub fascist4_click ()
TEXT1.TEXT = "'example VB6 syntax"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "DIM A As Long, B As Long, C as long"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "a =" & 3
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "B =" & 5
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "C =" & 2
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "Clipboard.SetText (A B) / C"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "Msgbox Clipboard.getText"
End Sub
Private sub fascist5_click ()
TEXT1.TEXT = "The example is really object-oriented, changing new titles"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "DIM F AS FORM1"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "SET F = New Form1"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "F.Show"
TEXT1.TEXT = TEXT1.TEXT CHR (13) CHR (10) "f.caption =" "AAAA" "" End Sub
Private subss6_click ()
TEXT1.TEXT = "'example of example running the application, and send a button !!"
Text1.text = text1.text chr (13) chr (10) "shell" "Notepad.exe C: /example.txt", vbnormalfocus "
Text1.text = text1.text chr (13) chr (10) "SendKeys" "Hello World!" "
End Sub