Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing from VB6 to VBScript

Status
Not open for further replies.

jtheis

Technical User
Sep 9, 2004
41
0
0
US
I've got what I think is an unusual question. I have a very messy situation with multiple languages and trying to pass info from one to the other. Here's the short version.

I use VBScript to call a function in a VB6 .dll file. The VB6 .dll calls an old Delphi .dll and the Delphi .dll spits out a value. Here's how the code breaks down to do all of this.

VBScript snip:
Code:
Set objDLL2 = CreateObject("HTS2Interface.HTS2Objects")
Result = objDLL2.vbsShowLoadBuildDlg(TH, Weight, TableNo, 1)
MsgBox Result

VB6 HTS2Interface.dll snip from the CLASS MODULE:
Code:
Public Function vbsShowLoadBuildDlg(ByVal lngTH As Long, ByVal Weight As Long, ByVal TableNo As Long, ByRef LoadNo As Long) as Boolean
    On Error Resume Next
    modHTS2.Call_ShowLoadBuildDlg lngTH, Weight, TableNo, LoadNo
End Sub

VB6 HTS2Interface.dll snip from the MODULE:
Code:
Public Declare Function ShowLoadBuildDlg Lib "C:\windows\system32\HTS2.DLL" Alias "#152" (ByVal lngTH As Long, ByVal Weight As Long, ByVal TableNo As Long, ByRef LoadNo As Long) As Boolean

Public Function Call_ShowLoadBuildDlg(ByVal lngTH As Long, ByVal Weight As Long, ByVal TableNo As Long, ByRef LoadNo As Long) As Boolean
    Dim bolShowLoadBuildDlg As Boolean
    On Error Resume Next
    bolShowLoadBuildDlg = ShowLoadBuildDlg(lngTH, Weight, TableNo, LoadNo)
    MsgBox bolShowLoadBuildDlg, 0, "ShowLoadBuildDlg"
End Function

The message box from the MODULE portion of the .dll returns a TRUE value for bolShowLoadBuildDlg. I need to get that TRUE value passed back to the Result in the VBScript script.

I'm sure there is a cleaner, easier, 'more correct' way to do this, but I'm kind of stuck doing things this way. Any pointers for a non-scripter trying to write script?

Thanks in advance for the help!


Joe
 
Anyway, the vbsShowLoadBuildDlg Function doesn't return any value ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
objDLL2.vbsShowLoadBuildDlg(TH, Weight, TableNo, 1)

Public Function vbsShowLoadBuildDlg(ByVal lngTH As Long, ByVal Weight As Long, ByVal TableNo As Long, ByRef LoadNo As Long) as Boolean

You seem to be passing a constant as ByRef?

Hope this helps.

 
PHV,

Sorry, I left out that the vbsShowLoadBuildDlg always returns a False value for Result.

earthandfire,

I use the 1 because if I leave it as the variable LoadNo it doesn't do anything because LoadNo does not have a value at the time that it is called.

I apologize in advance if I'm leaving a lot out of my posts. I'm not a programmer by any stretch (as I'm sure you can all see) but I've been given this project and I'm just trying to make it work.

Thanks again!


Joe
 
Actually you have to do it this way. VBScript cannot call API functions (your ShowLoadBuildDlg Delphi function is such a beast), so such functions have to be wrapped in a COM library (so an ActiveX exe or DLL) if you want to use them from VBScript
 
PHV,

You had it right, I just didn't understand at first what you meant in your reply.

What I needed to add at the end of the MODULE function was
Code:
Call_ShowLoadBuildDlg = bolShowLoadBuildDlg

Then in my CLASS MODULE function I added
Code:
vbsShowLoadBuildDlg = modHTS2.Call_ShowLoadBuildDlg

And now my script returns the correct value.

Thanks to everyone who took the time to read this.


Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top