谁用过 Microsoft Script Control 啊?这个怎么用啊?

fzlong 2005-04-30 12:04:18
听说这个可以实现vb程序在不作改动的情况下,进行扩展,怎么做啊?
能用它直接调用没有加到工程里的modul里的方法吗?
有谁有例子,给一个看看!!谢谢,高分啊!!!不够,再加啊!
...全文
490 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hwshws123 2005-05-02
  • 打赏
  • 举报
回复
深切关注!
neuafei 2005-04-30
  • 打赏
  • 举报
回复
这个例子是往里加代码得,具体得方法你下载msc后应该很容易用出来
'Make a MSScriptControl. (See source for Rod's ' fully commented code. I cut most. Ed.)
Dim script_control As New MSScriptControl.ScriptControl
script_control.Language = "VBScript"
script_control.AddObject "TheForm", Me
script_control.AllowUI = True
'Enter the script code.
script_control.AddCode "Sub Main()" & vbCrLf & " TheForm.BackColor = vbRed" & vbCrLf & " TheForm.Caption = ""VB6 scripting is easy!""" & vbCrLf & " TheForm.Width = 5 * 1440" & vbCrLf & " TheForm.Height = 3 * 1440" & vbCrLf & "End Sub"
'Execute the Main subroutine.
script_control.Run "Main"
DooDu 2005-04-30
  • 打赏
  • 举报
回复
可以看看:http://www.zdnet.com.cn/developer/code/story/0,2000081534,39035199,00.htm
=====================================================================

在VB编程中采用Windows脚本控件实现程序脚本化

作者: BUILDER.COM
Thursday, May 23 2002 11:26 AM
电子邮件脚本病毒在网络上泛滥成灾之后,作为脚本缺陷的始作俑者,WSH(Windows脚本主机)受到了广泛和强烈的抨击,不过,对应用程序开发人员而言,WSH仍然具备相当大的潜质和开发魅力。是的,脚本技术完全可能取代网络管理员对批处理文件的依赖,更时髦的脚本相信对那些“真正”的开发人员仍具相当的实用性。
比方说,你知道微软的Office套件如此流行的原因吗?其中之一就是所有的Office应用程序都包括了了简单的开发环境,稍有技术的用户都可以由此实现重复任务的自动化。VBA(Visual Basic for Applications)就为Office软件提供了这种环境,而且,如果你能承担微软要求的许可证费用,你还可以在你自己的应用程序中使用VBA。现在,我们再来看看WSH和Windows Script Control,它们是对VBA廉价而且相当有用的替代选择。为Visual Basic应用程序提供了自动的脚本化技术。


therockdelt 2005-04-30
  • 打赏
  • 举报
回复
帮顶 蹭分
daisy8675 2005-04-30
  • 打赏
  • 举报
回复
Example
In Visual Basic, create a new project (Form1 is created by default).


Click Components on the Project menu, and then select the "Microsoft Script Control 1.0" check box.


Add the Script control (ScriptControl1), a text box (Text1), three command buttons (Command1, Command2, Command3), and two list boxes (List1, List2) to Form1. Set the MultiLine property of the text box to TRUE. Size the text box to accommodate 5 lines of 30 characters.


Add the following code to Form1:

Private Sub Command1_Click()
ScriptControl1.Modules.Add Text1.Text
Form_Activate
End Sub

Private Sub Command2_Click()
ScriptControl1.Modules(List1).AddCode Text1.Text
List1_Click
End Sub

Private Sub Command3_Click()
Dim RetVal As Variant, m As Variant
Set m = ScriptControl1.Modules(List1.Text)
With m.Procedures(List2.Text)
Select Case .NumArgs
Case 0
RetVal = m.Run(List2.Text)
Case 1
RetVal = m.Run(List2.Text, 5)
Case 2
RetVal = m.Run(List2.Text, 4, 23)
Case Else
MsgBox "Procedure has too many arguments"
End Select
If .HasReturnValue Then
MsgBox List2.Text & " returned: " & RetVal
End If
End With
End Sub

Private Sub Form_Activate()
Dim m As Variant
List1.Clear
With SCriptControl1
.Language = "VBScript"
.AllowUI = True
For Each m In .Modules
List1.AddItem m.Name
Next m
End With
End Sub

Private Sub Form_Load()
Command1.Caption = "Add Module"
Command2.Caption = "Add Code"
Command3.Caption = "Run Procedure"
End Sub

Private Sub List1_Click()
Dim m As String, p As Variant
m = List1
List2.Clear
If m = "" Then Exit Sub
For Each p In ScriptControl1.Modules(m).Procedures
List2.AddItem p.Name
Next p
End Sub

Private Sub List2_Click()
Dim m As String, p As String, r As Boolean, a As Long
m = List1
p = List2
With ScriptControl1.Modules(m).Procedures(p)
r = .HasReturnValue
a = .NumArgs
End With
MsgBox m & "." & p & " has " & IIf(r, "a", "no") & _
" return value and " & a & " arguments"
End Sub



Run Form1.


Create a new module by typing the following in the text box and clicking Add Module:

Mod2




Type the following script in the text box:

Function Calc(X)
Calc = X * 2
End Function



Select Global in List1, and then click Add Code to add to the global module.


Type the following script into the text box:

Function Calc(X, Y)
Calc = X * Y
End Function

Sub Test()
MsgBox "The Test Sub in Module Mod2"
End Sub



Select Mod2 in List1, and then click Add Code to add to the global module.


Click on the various modules and procedures. When you select the procedure a message box appears, indicating whether the procedure has a return value as well as the number of arguments it takes.


After selecting a procedure, click Run Procedure to run it. The code determines the number of arguments to use and you will see varying message boxes with the results.


NOTE:

The global module name might not always be "Global" depending on control version or localization. Use the GlobalName constant instead of hard- coding the word "Global".


There is no method to remove individual modules or procedures. You have to use the .Clear method of the script control to erase all code. You can overwrite a procedure by using the .AddCode method with a procedure of the same name.





REFERENCES
For information about obtaining the Script control, please see the following article in the Microsoft Knowledge Base:


Q184739 : INFO: Where to Obtain the Script Control

For additional information and examples on calling procedures in the Global module, please see the following article in the Microsoft Knowledge Base:

Q184740 : HOWTO: Call Functions Using the Script Control

Microsoft Script control Help Topics:


HasReturnValue Property
NumArgs Property
AddCode Method
Run Method
Modules Collection
Procedures Collection

daisy8675 2005-04-30
  • 打赏
  • 举报
回复
你可以查KB和MSDN里面
//
HOWTO: Use Script Control Modules and Procedures Collections

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
Microsoft Visual Basic for Applications version 5.0

--------------------------------------------------------------------------------


SUMMARY
This article demonstrates how to use the Modules and Procedures properties of the Microsoft Script control to segment code. It also demonstrates how you can dynamically determine the number of arguments and whether the procedure is a Function or Sub.



MORE INFORMATION
The Microsoft Script control includes features that allow the host application to segment scripts into different modules. The default module, "Global", is always present. Different modules may contain procedures of the same name (that is, procedure names have module scope).

The Microsoft Script control also includes procedure properties that allow the host application to dynamically determine whether the procedure is a Function or a Sub as well as the number of arguments it expects. This allows the host application to prompt the user for the correct number of parameter values.

The Modules property of the Script control is an object that contains a collection of module objects. It has the following properties and methods:


Count: The number of modules.


Item(x): Returns a single Module object.


Add name: Adds a blank module with the given name.


The Module Object has the following properties and methods:

Name: The module name.


Procedures: The Procedures object.


AddCode code: Adds the code to the module.


Run name, args: Runs the named procedure.


The Procedures object contains a collection of Procedure objects. It has the following properties and methods:

Count: The number of procedures in the module.


Item(x): Returns a single Procedure object.


The Procedure object has the following properties and methods:

Name: The procedure name.


HasReturnValue: Indicates whether the procedure is a Sub or a Function.


NumArgs: The number of arguments the procedure requires.


NOTE: Not all properties and methods of the listed objects are given, just those relevant to this article.

The following example provides an interactive program that illustrates how to use these properties and methods:

IMPORTANT: Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.

fzlong 2005-04-30
  • 打赏
  • 举报
回复
script_control.Modules(GlobalModule) 的用法是什么意思?
  • 打赏
  • 举报
回复
能用它直接调用没有加到工程里的modul里的方法吗?

这个是不能的

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧