Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript with VB6: Calling global subs/functions

Posted on 2008-10-11
10
Medium Priority
?
1,736 Views
Last Modified: 2013-11-26
I am using VBscript in VB6, and what I want to do is actually call a GLOBAL function/sub without having to define the form so I can throw it in a global module. For example, I use VB6 to call a VBscript, in the VBScript called MyScript.vbs I have:

Function Test()
              Call test2()
End Function

test2 being in a module in my global script. I currently know you can do something like:

Function Test(whatform)
              Call whatform.test2()
End Function

To actually call something INSIDE a form, if 'whatform' has the function/sub.

Basicly what I am trying to do is have it so it's a global command, so my 'scripters' don't have to do anything additional, so they can call a function on VB6 side that are public. Get me? Including the example I'm using, it's modified a bit to run with my server so just remove anything additional if you want it. Currently frmServer is the frm it is called in, which is not public functions.
Public Sub Test(ByVal Index As Integer, ComArray() As String, Comi As Long)
 
            ScriptFileName = "MyScript.vbs"
            Dim StrScript As String
            Open App.Path & "\" & ScriptFileName For Binary Access Read As #1
                StrScript = String(LOF(1), 0)
                Get #1, , StrScript
            Close #1
            
            On Error Resume Next
            frmServer.SCShards.AllowUI = True
            frmServer.SCShards.UseSafeSubset = True
            frmServer.SCShards.Reset
            frmServer.SCShards.AddCode StrScript
            Dim shardtest As String
            If frmServer.SCShards.Procedures.Count > 0 Then
              shardtest = frmServer.SCShards.Run("Test", frmServer, userchp(Index))
            End If
            If Err.Number <> 0 Then MsgBox "Error: " & Err.Number & " (&H" & Hex(Err.Number) & ")" & vbNewLine & vbNewLine & Err.Description, vbExclamation
 
End Sub
 
Public Sub test2()
    MsgBox "Working"
End Sub

Open in new window

0
Comment
Question by:Valleriani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
10 Comments
 
LVL 7

Author Comment

by:Valleriani
ID: 22695549
Basicly, I want to be able to call functions in modules, not forms, using VBscript.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22696841
the vbscript is in .vbs files, right?
the vb6 is a compiled exe, in the end, right?
you will need to create "some" instance of the .exe (or better, a activeX-dll) to be able to call something from the vb6 project.

can you explain the big picture, here?
0
 
LVL 7

Author Comment

by:Valleriani
ID: 22698075
Ahh okay, well basicly, I have the server, and I want people to be able to script things (I will be having basic functions they can use, like SETHP, GETHP, etc.)

Basicly what I want for them to beable to call up functions for them to use in a VBscript, but I suppose I will have to use a activex-dll/form to do so? They would need to then call it like FORM.sethp(name) correct? For example?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:Valleriani
ID: 22698173
As well, how would I use a activeX-dll exactly, I'm not sure I understand how to use those yet.
0
 
LVL 7

Author Comment

by:Valleriani
ID: 22783568
I'm still not sure how to use a active-x dll file. Currently I'm using a form to do this.;
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 2000 total points
ID: 22858185
Once you have written your VB6 project to be an ActiveX dll with public functions you can use it like you would use any ActiveX object for example like the FileSystemObject. You just use the CreateObject function to create and instance of your ActiveX object
Set myObject = CreateObject("myActiveXObject")
The you use your object to access the public functions you have written
e.g.:
a = myObject.SETHP()
0
 
LVL 7

Author Closing Comment

by:Valleriani
ID: 31505357
I understand now! Just a quick question as it finishes, can you call variables using this way within the project?
0
 
LVL 18

Expert Comment

by:JR2003
ID: 22858569
You would have to write Properties within the class to access and set variables.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question