ScriptBasic

Extension Modules => Extension Modules => COM => Topic started by: Support on October 09, 2014, 06:38:35 pm

Title: SBVB
Post by: Support on October 09, 2014, 06:38:35 pm
This thread will demonstrate using the Script BASIC COM interface with Visual BASIC and .NET forms as COM ActiveX controls.

(http://files.allbasic.info/ScriptBasic/SBCOM/1_mb_long.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/2_mb_int.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/3_mb_bool.png)

(http://files.allbasic.info/ScriptBasic/SBCOM/4_form_string.png)

(http://files.allbasic.info/ScriptBasic/SBCOM/5_form_listbox.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/6_form_lbnotify.png)

(http://files.allbasic.info/ScriptBasic/SBCOM/7_calendar.png)

import com.inc

obj = CreateObject("VB6.Sample")

'Sample function prototypes
'       longTest(v As Long)
'       intTest(v As Integer)
'       ByteTest(v As Byte)
'       GetString(prompt As String, title, def) As String
'       ShowUI() As Long

if obj = 0 then
        print "CreateObject failed!\n"
else

    print "TypeName obj = ", TypeName(obj), "\n"

    CallByName(obj, "longTest", VbMethod, 20000)
    CallByName(obj, "intTest", VbMethod, 1000)
    CallByName(obj, "byteTest", VbMethod, 255)
   
    'this one fails silently because its invalid value for byte type..
   CallByName(obj, "byteTest", VbMethod, 256)

    retVal = CallByName(obj, "GetString", VbMethod, "Enter some Text:", "my title", "default value!")
    print "GetString returned: ", retVal, "\n"
   
    'do NOT release objects you dont own..
   objForm = CallByName(obj, "LaunchUI")
    print "objForm = ", objForm, "\n"
   
    for i=0 to 10
        CallByName(objForm, "AddItem", VbMethod, "Hello from script basic! " & i)
    next
   
    print "Waiting until user closes form to proceede..\n"
    CallByName(obj, "BlockUntilFormCloses")
   
    sDate = CallByName(obj, "SelectDate")
    if len(sDate) = 0 then
        print "User pressed cancel for date selection\n"
    else
        print "Date: ", sDate, "\n"
    end if
   
    ReleaseObject(obj)
    print "anndddd were done!\n"
   
end if
 
Console Output

C:\ScriptBasic_Control-master\engine\COM_Extension_DLL>scriba COM_VB6_Example.sb
TypeName obj = _Sample
GetString returned: Script BASIC talks to VB6.
objForm = 1417320
Waiting until user closes form to proceede..
Date: 9/10/2014
anndddd were done!

C:\ScriptBasic_Control-master\engine\COM_Extension_DLL>




Title: Re: SBVB
Post by: Support on October 10, 2014, 12:31:53 am
Here is a C# (C-Sharp) .NET calendar control example being called from Script BASIC COM.

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

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
 
Console Output


C:\ScriptBasic_Control-master\engine\COM_Extension_DLL\CS_Sample>scriba cs_date.sb
User Selected date: 10/9/2014
C:\ScriptBasic_Control-master\engine\COM_Extension_DLL\CS_Sample>


Title: Re: SBVB
Post by: Support on October 10, 2014, 01:28:09 am
Here is an example of VB6 calling Script BASIC functions.

(http://files.allbasic.info/ScriptBasic/SBCOM/1_callback.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/2_callback.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/3_callback.png)

import com.inc

'in the VB6 GUI
'this one uses SBCallBackEx which supports multiple types and args
'return values can be either string or long.
function Button1_Click(arg, arg1, arg2, arg3, arg4, arg5)
        print "Button1_Click arg=", arg, "\n"
        print "Button1_Click arg1=", arg1, "\n"
        print "Button1_Click arg2=", arg2, "\n"
        print "Button1_Click arg3=", arg3, "\n"
        print "Button1_Click arg4=", arg4, "\n"
        print "Button1_Click arg5=", arg5, "\n"
        Button1_Click = arg + 1
end function

'in the VB6 GUI
'this one uses SBCallBack it only takes one long arg. return value is long
function Button2_Click(arg)
        print "Back in script basic Button2_Click arg=", arg, "\n"
        Button2_Click = arg * 2
end function

obj = CreateObject("VB6.Sample")

if obj = 0 then
    print "CreateObject failed!\n"
else
        print "obj = ", obj, "\n"
               
        oCollection = CallByName(obj, "CallBackHandlers", VbGet)
    print "oCollection = ", oCollection, "\n"
   
    CallByName(oCollection, "Add", VbMethod, ADDRESS(Button1_Click()), "frmCallBack.cmdOp1_Click" )
    CallByName(oCollection, "Add", VbMethod, ADDRESS(Button2_Click()), "frmCallBack.cmdOp2_Click" )
   
    retVal = CallByName(obj, "LaunchCallBackForm", vbMethod, 21)
    print "LaunchCallBackForm returned ", retVal, "\n"
   
    ReleaseObject(obj)
    print "test complete!\n"
end if
 
Console Output

C:\ScriptBasic_Control-master\engine\COM_Extension_DLL>scriba COM_VB6_CallBack_Example.sb
obj = 1417264
oCollection = 1417344
Button1_Click arg=21
Button1_Click arg1=two
Button1_Click arg2=3
Button1_Click arg3=four
Button1_Click arg4=5
Button1_Click arg5=1356152
Back in script basic Button2_Click arg=22
LaunchCallBackForm returned 44
test complete!

C:\ScriptBasic_Control-master\engine\COM_Extension_DLL>

Title: Re: SBVB
Post by: Support on October 10, 2014, 04:59:58 am
This example uses an OCX control built with the FREE Microsoft VB5CCE (Visual BASIC 5 Controls Edition). HERE (http://files.allbasic.info/ScriptBasic/SBCOM/VB5_CCE.zip) is a link to a zip that contains VB5CCE, xp theme manifest and help for CCE. (10.2 MB)

(http://files.allbasic.info/ScriptBasic/SBCOM/1_cce_form.png)   (http://files.allbasic.info/ScriptBasic/SBCOM/2_cce_form.png)

import com.inc

function Button1_Click(arg)
        print "Back in script basic Button1_Click arg=", arg, "\n"
        Button1_Click = arg + 1
end function

obj = CreateObject("VB5.CCESample")

if obj = 0 then
    print "CreateObject failed!\n"
else
    print "obj = ", obj, "\n"
               
    oCollection = CallByName(obj, "CallBackHandlers", VbGet)
    print "oCollection = ", oCollection, "\n"
   
    CallByName(oCollection, "Add", VbMethod, ADDRESS(Button1_Click()), "frmCallBack.cmdOp1_Click" )
   
    retVal = CallByName(obj, "LaunchCallBackForm", vbMethod, 21)
    print "LaunchCallBackForm returned ", retVal, "\n"
   
    ReleaseObject(obj)
    print "test complete!\n"
end if
 
Console Output


C:\ScriptBasic_Control-master\engine\COM_Extension_DLL\vb5cce_Example>scriba VB5_Example.sb
obj = 1402016
oCollection = 1410024
Back in script basic Button1_Click arg=21
LaunchCallBackForm returned 22
test complete!

C:\ScriptBasic_Control-master\engine\COM_Extension_DLL\vb5cce_Example>

Title: Re: SBVB
Post by: Support on October 10, 2014, 05:44:45 pm
Mike from for O2 forum gave the Script BASIC IDE/Debugger/COM a try on the new Windows 10 preview release. This is good news for all VB classic hold outs.
Title: Re: SBVB
Post by: Support on October 19, 2014, 06:36:56 am
The following attached screen shots are of the Script BASIC IDE/Debugger themed. (XP & Win7)