It can seem a bit murky at times.
In VB6 MsgBox() is a method of the global namespace object VBA. In a sense it is invoked as:
[tt]lngResult = VBA.MsgBox(strPrompt, ...)[/tt]
Because the VBA object is part of the global namespace though you generally don't need to mention it explicitly.
VBScript's MsgBox() is an intrinsic function with pretty much identical behavior in normal use. Thus VBScript can already display a MsgBox dialog with no additional help.
The ScriptControl object's method AddObject is used to add an object to the global namespace of the script you run via the control. By adding objects within your VB program to the script's global namespace you make it available to the script code.
This is how you make the VB program scriptable: you provide one or more such global objects that in turn the script can manipulate.
Here's a sample form module's code that uses VBScript to control a form by adding the form to the script's global namespace as [tt]Form[/tt]:
Code:
Option Explicit
Private Const MyScript As String = _
"Option Explicit" & vbNewLine _
& "Sub EnableExit()" & vbNewLine _
& " Form.cmdExit.Enabled = True" & vbNewLine _
& "End Sub"
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdRunScript_Click()
ScriptControl1.Run "EnableExit"
End Sub
Private Sub Form_Load()
With ScriptControl1
.AddObject "Form", Form1
.Language = "VBScript"
.AddCode MyScript
End With
End Sub
In this example [tt]cmdExit[/tt] is set to disabled at design time (via the IDE).
When [tt]cmdRunScript[/tt] is clicked the script is invoked, which enables the [tt]cmdExit[/tt] button. Then the button can be clicked to end the program.
One could easily add the VBA object to the script's global namespace too, but there is usually no good reason to do so.
Usually in a real program you'd have an instance of a Class you have written that gets added to the script's global namespace. The purpose is to provide a way to manipulate things back in your VB program.
Another example might be the cases of script run under the [tt]CScript.exe[/tt] or [tt]WScript.exe[/tt] script hosts. These create and add (slightly different version of) a WScript object with various methods and properties, to provide access to the environments provided by those script engines.
By using the Script Control your VB program becomes a new, custom script host. If you want your loaded script to be able to do much in terms of controlling your VB program you'll need to define and add appropriate objects having appropriate methods and properties.
Most such programs would only add one or a few objects to the script's namespace. Those objects need to represent the things you want automated via script. They can be ADO Recordsets, Collections, Forms, instances of user-writen Classes or almost any object that doesn't require data types (like UDTs) that VBScript cannot readily manipulate.