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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ebExecuteLine 4

Status
Not open for further replies.

danjevans

Programmer
Jun 22, 2001
2
GB
Hi, I'm using ebExecuteLine in a program:

Private Declare Function EbExecuteLine Lib "vba6.dll" _
(ByVal pStringToExec As Long, ByVal Foo1 As Long, _
ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
...
EbExecuteLine StrPtr("Msgbox ""TEST"""), 0&, 0&, Abs(false)
...

This works fine when interpreted and messages TEST as expected. However when the program is compiled the line causes the program to crash out with...

"The instruction at "0x0fa916c8" referenced memory at "0x000002b0". The memory could not be read."

..the application is then terminated. Anyone have any advice on this? Why would it only fail when compiled?

Thanks,

-Dan Evans
 
I get that message all the time. They drive me insane! When it crashes for me it is caused by 2 things:
1) A dll you are using is looking for another dll that has not been referenced or cannot be found on the system.
2) You are accessing a database and you have not populated the connection string.

2 suggestions how to find out why:
1) Try to debug it step by step in immediate mode (looking at each value.
2) put in msgboxes and see which exact line makes it crash.

Another problem may be with the "byval" You need to take the termination string, that C++ uses, off the end when using it in VB.

Try this function:
Public Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function


I hope this helps. Let me know if it doesn't, send me the necessary code and I'll look into it deeper.
Brett Please visit my websites!
 
It may be the excessive use of quotes also. Change this:
EbExecuteLine StrPtr("Msgbox ""TEST"""), 0&, 0&, Abs(false)

-to-

dim TempStr as string
TempStr = "Msgbox " & chr(34) & "TEST" & chr(34)
EbExecuteLine StrPtr(TempStr), 0&, 0&, Abs(false)

Please visit my websites!
 
Thanks, I'll try those on Monday (Damned if I'm working over the weekend!)

Cheers,

-Dan
 
I know this is the Win32API forum, but one alternative might be to consider the Script Control, since it supports an ExecuteStatement method. eg:

Dim tempStr As String
Dim wscript As ScriptControl

Set wscript = New ScriptControl
wscript.Language = "vbscript"

tempStr = "Msgbox " & Chr(34) & "TEST" & Chr(34)

wscript.ExecuteStatement tempStr
 
StrongM,
That is a very good suggestion. It could also be written in javascript just as easy. Plus, with VBS and JS you can write an external script and use it on multiple pages.

Dan,
If this interests you, let me know and I'll whip up some simple code for you!

Brett Please visit my websites!
 
danjevans
Hi, Have you solved your problem yet? I have got the exact problem as you did. If you or any body know how to make it right, please let me know. I use this function to load forms, it is important to me.

Thanks
 
Hi, every one
The scriptControl can only work on normal VB command, it won't work on object (if the object has not created).
What I want is like this "Load Form1" or "Form1.Show". The question is: at this moment, Form1 is an object that has not been created, so scriptControl can not do it.
The EbExecuteLine only works in the IDE environment, what could I do? Anyone can help me?
 
Hi,smsforce

All of the forms are design-time forms, I mean those are existed in the vb code. The forms' name are stired in a database table, at run time, the program search the table and get get the appreciated form's name. Becuase the form name is stored in a string variable, the normal vb code can not execute it. The EbExecuteLine won't do it when compiled. the scriptControl can only work on objects that have already been loaded.
What I want is to execute a statement in a string like this:
"Load frmBooks"
"frmBooks.Show"

Thanks
Huangggx
 
I use the EbExecuteLine API for Evaluate Strings and i get the same error.
I can't solve this with a script because this just execute but don't evaluate.
My english not is good, but i are learnig(is this the correct word?), so sorry.
I wait for your help.

Chicho
 
Huanggx,

Here's an example of a function that will Show a form using a string containing the required form's name (there's no error handling in the example, so you'll have to expand it yourself to check for things such as legitimate form names, or whether a form is already loaded):
[tt]
Private Function ShowNamedForm(strForm As String) As Form
Dim frmTemp As Form
Set frmTemp = Forms.Add(strForm)
frmTemp.Show
Set ShowNamedForm = frmTemp
End Function
 
You CAN operate on any object in your program, as long as you explicitly tell the script control it is allowed to do so. For example, even if you have not EXPLICITLY loaded form2, you can still add it as an available object to the Script Control.

Example:

Create 2 forms, Form1 and Form2, with Form1 as your startup form. Add a command button Command1 to Form1, a Textbox Text1 and a Script Control ScriptControl1.
Add the following code to Form1.

Code:
Private Sub Command1_Click()
    ScriptControl1.ExecuteStatement Text1.Text
    Text1.Text = ""
End Sub

Private Sub Form_Load()
    ScriptControl1.AddObject Form2.Name, Form2
End Sub

Now start the project, and type Form2.show and click command1.



If you want to explicitly add ALL CONTROLS on the form automatically to the script control, use the following code for your Form1_Load():


Code:
Private Sub Form_Load()
    ScriptControl1.AddObject Form1.Name, Form1
    ScriptControl1.AddObject Form2.Name, Form2

    For i = 0 To Form1.Controls.Count - 1
        ScriptControl1.AddObject Form1.Controls(i).Name, Form1.Controls(i)
    Next i
    For i = 0 To Form2.Controls.Count - 1
        ScriptControl1.AddObject Form2.Controls(i).Name, Form2.Controls(i)
    Next i
    
End Sub

You can even get access to a control at runtime.. THROUGH THE SCRIPT CONTROL. You can even CREATE a control at runtime, Give yourself access to it, and alter it as you wish.. Add this function to your project:

Code:
Public Function GetAccess(ByVal sControlName As String)
    ScriptControl1.AddObject sControlName, Form1.Controls(sControlName)
End Function

Now, in Text1 type the following:

form1.controls.add "vb.textbox", "Text2"
Form1.GetAccess "Text2"
text2.top = 0
text2.left = 0
text2.visible = True

s-)

(Sorry, I never even touched the ScriptControl before but it's pretty cool.. so I got a little excited :) )..

Hope some of this helped someone! :)

--NipsMG

 
For the eBExecuteLine API call, more than likely the vba6.dll is not being found during runtime when it is compiled.
 
No, Mind_Flayer, sadly the problem is that EbExecuteLine just does not work properly in compiled programs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top