Author Topic: SBVB  (Read 26489 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
SBVB
« on: October 09, 2014, 11:38:35 AM »
This thread will demonstrate using the Script BASIC COM interface with Visual BASIC and .NET forms as COM ActiveX controls.

      



   



Code: Script BASIC
  1. import com.inc
  2.  
  3. obj = CreateObject("VB6.Sample")
  4.  
  5. 'Sample function prototypes
  6. '       longTest(v As Long)
  7. '       intTest(v As Integer)
  8. '       ByteTest(v As Byte)
  9. '       GetString(prompt As String, title, def) As String
  10. '       ShowUI() As Long
  11.  
  12. if obj = 0 then
  13.         print "CreateObject failed!\n"
  14. else
  15.  
  16.     print "TypeName obj = ", TypeName(obj), "\n"
  17.  
  18.     CallByName(obj, "longTest", VbMethod, 20000)
  19.     CallByName(obj, "intTest", VbMethod, 1000)
  20.     CallByName(obj, "byteTest", VbMethod, 255)
  21.    
  22.     'this one fails silently because its invalid value for byte type..
  23.    CallByName(obj, "byteTest", VbMethod, 256)
  24.  
  25.     retVal = CallByName(obj, "GetString", VbMethod, "Enter some Text:", "my title", "default value!")
  26.     print "GetString returned: ", retVal, "\n"
  27.    
  28.     'do NOT release objects you dont own..
  29.    objForm = CallByName(obj, "LaunchUI")
  30.     print "objForm = ", objForm, "\n"
  31.    
  32.     for i=0 to 10
  33.         CallByName(objForm, "AddItem", VbMethod, "Hello from script basic! " & i)
  34.     next
  35.    
  36.     print "Waiting until user closes form to proceede..\n"
  37.     CallByName(obj, "BlockUntilFormCloses")
  38.    
  39.     sDate = CallByName(obj, "SelectDate")
  40.     if len(sDate) = 0 then
  41.         print "User pressed cancel for date selection\n"
  42.     else
  43.         print "Date: ", sDate, "\n"
  44.     end if
  45.    
  46.     ReleaseObject(obj)
  47.     print "anndddd were done!\n"
  48.    
  49. end if
  50.  

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>




« Last Edit: October 09, 2014, 11:47:23 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SBVB
« Reply #1 on: October 09, 2014, 05:31:53 PM »
Here is a C# (C-Sharp) .NET calendar control example being called from Script BASIC COM.



Code: Script BASIC
  1. import com.inc
  2.  
  3. cs = CreateObject("Sample.Sample")
  4.  
  5. if cs = 0 then
  6.         print "Failed to create the C# com object did you register the dll with regasm and have .NET installed?"
  7.         return
  8. end if
  9.  
  10. d = CallByName(cs, "GetDate")
  11. print "User Selected date: ", d
  12.  

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>



Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SBVB
« Reply #2 on: October 09, 2014, 06:28:09 PM »
Here is an example of VB6 calling Script BASIC functions.

      

Code: Script BASIC
  1. import com.inc
  2.  
  3. 'in the VB6 GUI
  4. 'this one uses SBCallBackEx which supports multiple types and args
  5. 'return values can be either string or long.
  6. function Button1_Click(arg, arg1, arg2, arg3, arg4, arg5)
  7.         print "Button1_Click arg=", arg, "\n"
  8.         print "Button1_Click arg1=", arg1, "\n"
  9.         print "Button1_Click arg2=", arg2, "\n"
  10.         print "Button1_Click arg3=", arg3, "\n"
  11.         print "Button1_Click arg4=", arg4, "\n"
  12.         print "Button1_Click arg5=", arg5, "\n"
  13.         Button1_Click = arg + 1
  14. end function
  15.  
  16. 'in the VB6 GUI
  17. 'this one uses SBCallBack it only takes one long arg. return value is long
  18. function Button2_Click(arg)
  19.         print "Back in script basic Button2_Click arg=", arg, "\n"
  20.         Button2_Click = arg * 2
  21. end function
  22.  
  23. obj = CreateObject("VB6.Sample")
  24.  
  25. if obj = 0 then
  26.     print "CreateObject failed!\n"
  27. else
  28.         print "obj = ", obj, "\n"
  29.                
  30.         oCollection = CallByName(obj, "CallBackHandlers", VbGet)
  31.     print "oCollection = ", oCollection, "\n"
  32.    
  33.     CallByName(oCollection, "Add", VbMethod, ADDRESS(Button1_Click()), "frmCallBack.cmdOp1_Click" )
  34.     CallByName(oCollection, "Add", VbMethod, ADDRESS(Button2_Click()), "frmCallBack.cmdOp2_Click" )
  35.    
  36.     retVal = CallByName(obj, "LaunchCallBackForm", vbMethod, 21)
  37.     print "LaunchCallBackForm returned ", retVal, "\n"
  38.    
  39.     ReleaseObject(obj)
  40.     print "test complete!\n"
  41. end if
  42.  

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>


Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SBVB
« Reply #3 on: October 09, 2014, 09:59:58 PM »
This example uses an OCX control built with the FREE Microsoft VB5CCE (Visual BASIC 5 Controls Edition). HERE is a link to a zip that contains VB5CCE, xp theme manifest and help for CCE. (10.2 MB)

   

Code: Script BASIC
  1. import com.inc
  2.  
  3. function Button1_Click(arg)
  4.         print "Back in script basic Button1_Click arg=", arg, "\n"
  5.         Button1_Click = arg + 1
  6. end function
  7.  
  8. obj = CreateObject("VB5.CCESample")
  9.  
  10. if obj = 0 then
  11.     print "CreateObject failed!\n"
  12. else
  13.     print "obj = ", obj, "\n"
  14.                
  15.     oCollection = CallByName(obj, "CallBackHandlers", VbGet)
  16.     print "oCollection = ", oCollection, "\n"
  17.    
  18.     CallByName(oCollection, "Add", VbMethod, ADDRESS(Button1_Click()), "frmCallBack.cmdOp1_Click" )
  19.    
  20.     retVal = CallByName(obj, "LaunchCallBackForm", vbMethod, 21)
  21.     print "LaunchCallBackForm returned ", retVal, "\n"
  22.    
  23.     ReleaseObject(obj)
  24.     print "test complete!\n"
  25. end if
  26.  

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>


Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SBVB
« Reply #4 on: October 10, 2014, 10:44:45 AM »
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.

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SBVB
« Reply #5 on: October 18, 2014, 11:36:56 PM »
The following attached screen shots are of the Script BASIC IDE/Debugger themed. (XP & Win7)