PDA

Click to See Complete Forum and Search --> : Executing the contents of a string


wango
Jul 11th, 2001, 12:45 PM
I receive some great :D information about executing the contents of a string using the EbExecuteLine function within the vba6.dll. But I am having a problem :mad: ... this seems to work great when testing within Visual Basic, but as soon I run the compiled version (.exe) it gives me a memory read error!!!

Has anyones else experience this? What am I doing wrong?? Please help.

Here is the test code I am running:

Public stRETURN As String * 256
Private Declare Function EbExecuteLine Lib "vba6.dll" ( _
ByVal stStringToExec As Long, _
ByVal Unknownn1 As Long, _
ByVal Unknownn2 As Long, _
ByVal fCheckOnly As Long) As Long


Private Sub Main()

If ExecuteLine("stRETURN = Space(256):stRETURN = Cstr(Now())") = False Then
Call MsgBox("IT FAILED!!")
Else
Call MsgBox("IT WORKED!! RETURN = " & stRETURN)
End If
End Sub

Private Function ExecuteLine(stCode As String, Optional bCheckOnly As Boolean = False) As Boolean
Dim stCommand As String * 256
Dim lgPtr As Long

stCommand = stCode
lgPtr = StrPtr(stCommand)
ExecuteLine = EbExecuteLine(lgPtr, 0&, 0&, Abs(bCheckOnly)) = 0
End Function

Any help would be greatly appreciated!! :D

Jay Rogozinsky
Jul 29th, 2001, 12:56 AM
Very Interesting. I haven't used VB scripting before, so I can only answer in terms of VB6 and API conventions - maybe it'll help.

Try:

Declare Function EbExecuteLine Lib "vba6.dll" ( _
stStringToExec As Any, _
ByVal Unknownn1 As Long, _
ByVal Unknownn2 As Long, _
ByVal fCheckOnly As Long) As Long

Instead of:

Declare Function EbExecuteLine Lib "vba6.dll" ( _
ByVal stStringToExec As Long, _
ByVal Unknownn1 As Long, _
ByVal Unknownn2 As Long, _
ByVal fCheckOnly As Long) As Long

When passing your string use:

EbExecuteLine(BYVAL stCommand, 0&, 0&, Abs(bCheckOnly))

wango
Jul 30th, 2001, 09:17 AM
Thanks for the response, but when I tried this the call never returned a good return code. If anyone else has any suggestions, I'm all ears. Thanks. Wango

Jay Rogozinsky
Jul 30th, 2001, 01:21 PM
Perhaps you can explain WHY you are trying to do this. Also, if you would be so kind, you can tell me how you are "compiling" it.

I can compile in VB, but, as I understand, vba6.dll is a component of the Visual Basic for Applications model. This tells me that it is designed to read code as text (scripting).

(( Remember, I don't have a lot of experience with VBA - I have a lot with VB. ))

Also, I have found some references on the net regarding EbExecuteLine - none of it good. Be apprised that some things that are documented so poorly are only grief - even Microsoft's Knowledge Base has nothing on it. In VB5 you could use CreateThread OK, NOT SO in VB6 - things change - undocumented things can change without reason or explanation.

wango
Jul 31st, 2001, 10:22 AM
If I could do what I need to do a different way ... I'm all for it. Let me explain what I am trying to accomplish, and maybe you can help me from there.

We have a system that is very dynamic in design. We use system environment values often and try to accomidate for all situations if we can.

Currently I have an application that reads a task list (in the format of an ini file) and runs whatever task is needed. One of the things that makes this dynamic is a section called Variables that gives us the ability to create a variable and use a variable within the task list (see example below). To make this powerful, I was able to use the vba6.dll to run any VB function within the variable. Using the EbExecuteLine I was able to execute the string value of the variable to dynamically set the value (see example below).

Task List Example

[Variables]
TARGET_DIR;C:\Files\Upload;CONSTANT
EXTENSION;Format(Now,"yymmddHhNn");DYNAMIC
STORE;Environ("STORE");DYNAMIC

[Tasks]
MERGE;{TARGET_DIR}\DR{STORE}.log.{EXTENSION};C:\{STORE}.log*
MERGE;{TARGET_DIR}\EL{STORE}.log.{EXTENSION};C:\Logs\ErrorLog.??


Using the example above ... if the variable is DYNAMIC, the application set the variable (name is in the first position) to the execution (using the ebexecuteline) of the value in the second position. This gives us the power to use any VB Script command dynamically.

In the Task Section then, I am able to replace the variable with the results of the execution of the command.

I hope you can understand what I am trying to accomplish. If you know of a better way to accomplish this, please say so.

Thanks for your help,
Wango

Jay Rogozinsky
Aug 2nd, 2001, 03:18 PM
I'm reading about a lot of grief with vba6.dll.

Why not use msscript.ocx? It looks like it has some potential to work without blowing up all the time.