Um i want to execute a VB code from a vb program... I think it works... Like i want to write in a textbox "Msgbox "Hello"" and i want a msgbox to popup.. heelp
Printable View
Um i want to execute a VB code from a vb program... I think it works... Like i want to write in a textbox "Msgbox "Hello"" and i want a msgbox to popup.. heelp
You can use the MS Scripting control, but it is a bit limited....
Jummy, tell me more!
Hehe that's easy! thanx for the tip!
I have posted this one before, but it may be something you can work with.
Code:
'Module Level
Option Explicit
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
Public Sub Main()
Form1.Show
End Sub
Public Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
'Form Level
Private Sub cmdExecute_Click()
Call ExecuteLine(txtCode.Text, False)
End Sub
Is this code working as it is or do i have to edit it some way? I can not get it to wark... Well its late.. good night and thanx in advance.:o
It works the way it is for very simple tasks. Add a module to your project paste in the module code. Place a textbox and a command button on you form behind the command paste in the code. Run the program in the textbox type in msgbox"HELLO"
press the command button. I am sure with some work it could do more.
It doesn't work compiled, I think the declare statement is bad because it can't find the DLL when compiled. Otherwise that is VERY cool. Better than callbyname...
Ok, i've also noticed you must call things from the lowest level:
eg: instead of label1.caption = "hi"
you use form1.label1.caption = "hi"
just a note, jonte might want to know???
Amazing that you found this inside the VB dll, what other functions hide in there?
Actually I found the code somewhere on the net. I haven't really done much with it, it has just been a play toy. Like you said you must call things from the lowest level. You have to type in the code simalar to using the debug window. For example, For i = 1 to 10: msgbox "The value of i is = " & i & ".": next i. It is cool, but not alot of use for me. I guess if I was one of these coding experts I could do more with it.