You are not logged in.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Tuesday, May 7th 2013, 7:17am

JaCoB Again and How to Use VBScript inside Jabaco

Hello community,

often we discuss about JaCoB (Java to COM Bridge).

Jabaco is absolut cool. It can natively combine DLL and JAR functions and with JaCoB also COM functions. Is there any other programming language that offers a similar range of variants on the Windows platform?

This combination works perfect from Windows XP to Windows 7, with all Java Version from 1.6.x to 1.7.x. I like it very much.

So here is another example, how to call VBScript inside Jabaco:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'-Begin-----------------------------------------------------------------

  '-Constants-----------------------------------------------------------
    Const Quote = Chr(34)

  '-Sub RunScript-------------------------------------------------------
    Sub RunScript(Script As String)

      '-Variables-------------------------------------------------------
        Dim MSScript As com#jacob#activeX#ActiveXComponent
  
      Set MSScript = New ActiveXComponent("MSScriptControl.ScriptControl.1")
      If MSScript <> Nothing Then
        MSScript.setProperty("AllowUI", True)
        MSScript.setProperty("Language", "VBScript")
        MSScript.invoke("ExecuteStatement", Script)
      End If

    End Sub
    
  '-Main-----------------------------------------------------------------
    Public Sub Command1_Click()
      RunScript "MsgBox " & Quote & "Ja" & Quote
    End Sub

'-End--------------------------------------------------------------------


Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

2

Friday, May 10th 2013, 8:02am

Hello community,

here is a small extension. With the function ReadScript exists the possibility to read a whole VBScript file and use it. If the argument FileName is empty, the function uses an open file dialog to chosse the file.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'-Begin-----------------------------------------------------------------

  '-Constants-----------------------------------------------------------
    Const Quote = Chr(34)

  '-Sub RunScript-------------------------------------------------------
    Sub RunScript(Script As String)

      '-Variables-------------------------------------------------------
        Dim MSScript As com#jacob#activeX#ActiveXComponent
  
      Set MSScript = New ActiveXComponent("MSScriptControl.ScriptControl.1")
      If MSScript <> Nothing Then
        MSScript.setProperty("AllowUI", True)
        MSScript.setProperty("Language", "VBScript")
        MSScript.invoke("ExecuteStatement", Script)
      End If

    End Sub

  '-Function ReadScript--------------------------------------------------
    Function ReadScript(FileName As String) As String
    
      '-Variables--------------------------------------------------------
        Dim ScriptFile As VBFileHandler
        Dim FileChooser As javax#swing#JFileChooser
    
      If FileName = "" Then
        Set FileChooser = New javax#swing#JFileChooser
        FileChooser.showOpenDialog(Null)
        FileName = FileChooser.getSelectedFile
      End If  
      ScriptFile = Open(FileName, Input, Read)
      ReadScript = ScriptFile.readAll
      ScriptFile.close

    End Function    
    
  '-Main-----------------------------------------------------------------
    Public Sub Command1_Click()
      RunScript "MsgBox " & Quote & "Ja" & Quote
    End Sub

    Public Sub Command2_Click()
      RunScript ReadScript("Test.vbs")
      'or
      'RunScript ReadScript("") with FileOpen dialog
    End Sub
    
'-End--------------------------------------------------------------------


Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Rate this thread
WoltLab Burning Board