How to AddObject to MSScriptControl?

MadMaxMSCN

Newcomer
Joined
Aug 18, 2004
Messages
23
Location
Bavaria, Germany
Hi everybody,

I have to use MSScriptControl in my Application.
First I added the reference to MSScriptControl, of course.
Then I created some objects and a ScriptControl.
When I try to add the objects to the ScriptControl I get an Exception.

Dim script As New MSScriptControl.ScriptControl

In Button_Click:

dim oTest As New Object
dim btnTest As New Button
script.AddObject("form", Me, True) 'this works
script.AddObject("object", oTest, False) 'works, too
script.AddObject("button", btnTest, False) 'Exception
script.AddObject("otherButton", Me.Button1, False) 'Exception

Why do I get this Exception:
An unhandled exception of type 'System.InvalidCastException' occurred in WindowsApplication2.exe

Additional information: Schnittstelle nicht unterstützt

in English: No such Interface supported

What's wrong?
 
Joe Mamma said:
Man. . . Exceptions in German look extremely angry!!!

German translation is bad, English texts are more better, often you know what's wrong when you read the English exception text but you have no idea when reading the German.
In Spanish it's: "Interfaz no compatible" (looks strange for a German)


It doesn't matter if my objects are private, public in form1 or public in button_click. The problem is always the same.
 
you have a form - Form1
it has a Public Property MainButton that returns a reference to a button on the form

you add it to the ScriptContro via

dim frm as New Form1
sc.AddObject("TheForm", Form1, true)

in the script can you reference Form.btnTest ?

i.e.

dim caption
caption = Form.btnTest.Text
 
The Code shown in my post ist only for testing.

In my project it's much more difficult:

My task is to upgrade an old vb6-app to vb.net.

I have a form: Form1.
On Form1 there's a user control: ucCustomForm.
ScriptControl is private in ucCustomForm.

The user can make some controls at runtime. These Controls are saved in a public property in ucCustomForm.

In vb6 the ScriptControl got (AddObject()) this property, a public object from a module and the ucCustomForm object itself.


The application has to be converted to vb.net without changing the scripts because there are very much of them. Is this possible?
 
Solutions to common Scriptcontrol problems in VB.NET

I've just converted an application from VB to VB.NET. This application used the scriptcontrol a lot.

In my experience there were the following problems after the upgrade:

1. Everything the scripts can access must be made public, or you will get the "No such Interface supported" error.

2. The scriptcontrol seems to have problems accessing overloaded procedures. This includes collections or dictionaries, where you can use both the col("key") syntax as well as the col(7) syntax.

This second problem can be solved by replacing the "public col as Collection" declaration with the following piece of code:

Private objCol As New Collection

Public Function col(Optional ByVal IndexOrKey As Object = Nothing) As Object
If IndexOrKey Is Nothing Then
Return objCol​
Else
Return objCol(IndexOrKey)​
End If​
End Function
 
Back
Top