ScriptBasic

Extension Modules => Extension Modules => COM => Topic started by: Support on June 22, 2014, 12:57:23 AM

Title: ActiveX with VB.NET
Post by: Support on June 22, 2014, 12:57:23 AM
I was curious if Visual BASIC .NET could create controls Dave could use with his Script BASIC COM extension module. From my initial research, it looks like it can.

Create ActiveX in .NET Step by Step (http://www.codeproject.com/Articles/24089/Create-ActiveX-in-NET-Step-by-Step)

How to generate an OCX activex control using VB.NET (http://social.msdn.microsoft.com/Forums/vstudio/en-US/3712047d-f962-4f89-9893-e6cb38cff143/how-to-generate-an-ocx-activex-control-using-vbnet?forum=vbgeneral)

Title: Re: ActiveX with VB.NET
Post by: dzzie on June 22, 2014, 02:52:35 PM
yup should work without a problem, I have used .NET code from VB6 projects through COM before. You just have to set the COM aware attribute to true
and then register the typelib or generate a registry file to include on  distribution.
Title: Re: ActiveX with VB.NET
Post by: Support on June 22, 2014, 06:15:02 PM
That's great news Dave. I'm assuming this holds true for visual COM controls. (ribbon control (http://msdn.microsoft.com/en-us/library/ff799534%28v=vs.110%29.aspx), ...)

The Date Picker (http://msdn.microsoft.com/en-us/library/ff468213%28v=vs.110%29.aspx) control might be a good first one to try. You already nailed the VB ActiveX version.

(http://files.allbasic.info/ScriptBasic/SBCOM/vb.net_date.png)

I attached the project and the compiled .exe for this.
Title: Re: ActiveX with VB.NET
Post by: dzzie on June 23, 2014, 11:03:22 AM
attached, see readme
Title: Re: ActiveX with VB.NET
Post by: Support on June 23, 2014, 12:36:48 PM
Amazing!

(http://files.allbasic.info/ScriptBasic/SBCOM/date.net.png)

Code: [Select]
import com.inc

cs = CreateObject("Sample.Sample")

if cs = 0 then
print "Failed to create the C# com object did you register the dll with regasm and have .NET installed?"
return
end if

d = CallByName(cs, "GetDate")
print "User Selected date: ", d

C:\SB22\sbcom\sbvb6>scriba cs_date.sb
User Selected date: 6/23/2014
C:\SB22\sbcom\sbvb6>


Q. What does the return do in your example?
Title: Re: ActiveX with VB.NET
Post by: dzzie on June 23, 2014, 02:29:19 PM
the return just exits the script early so I didnt have to protect the lower block with an else end if
Wasnt sure if it would work but it did. swap the equal to not equal logic to test
Title: Re: ActiveX with VB.NET
Post by: Support on June 23, 2014, 03:44:30 PM
Didn't know that and have always used END. Thanks for the trick.

Title: Re: ActiveX with VB.NET
Post by: Support on June 23, 2014, 11:28:26 PM
I was unable to get the .net date picker to run under Windows 7.  I registered the control and copied the Sample.dll to the bin directory.


C:\sb22_32\sbvb-2>scriba cs_date.sb
Failed to create the C# com object did you register the dll with regasm and have .NET installed?(0): error &H26:The command RETURN can not be executed, because there is no where to return.

I think the RETURN is causing scriba to exit due to failure and END should probably be used. I'm surprised your not seeing an ERROR 38 with the RETURN with nowhere to go. (possibly exited before error message could be displayed ?)

FYI: You can add your own key/data pairs to the Script BASIC configuration file and call it with the SB ext. module API.

BTW: I really enjoy your videos. Very informative!
Title: Re: ActiveX with VB.NET
Post by: dzzie on June 24, 2014, 06:28:59 AM
I just tested it on a Win7 machine, the registry file method wasnt enough not sure why.

For win7 i had to fall back to the regasm [dll path] method in which case it then worked as expected.

Your right on the return thing, oops, guess I wasnt reading the output close enough. End is what I was looking for thanks :)
Title: Re: ActiveX with VB.NET
Post by: Support on June 25, 2014, 12:23:21 AM
The RegAsm of the DLL did the trick on Windows 7 64 bit.

(http://files.allbasic.info/ScriptBasic/SBCOM/sbvb_date.net.png)

C:\sb22_32\sbvb-2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe Sample.dll
Microsoft .NET Framework Assembly Registration Utility version 4.0.30319.18408
for Microsoft .NET Framework version 4.0.30319.18408
Copyright (C) Microsoft Corporation.  All rights reserved.

Types registered successfully

C:\sb22_32\sbvb-2>scriba cs_date.sb
User Selected date: 6/25/2014
C:\sb22_32\sbvb-2>