|
-
Mar 13th, 2007, 04:43 AM
#1
Thread Starter
Lively Member
[RESOLVED] Executing VB Code
How can i run VB6 code from a textbox like i have a text box on form that textbox contains "msgbox "Hello" and on clicling ok button vb6 should run that code. how can i do this?
-
Mar 13th, 2007, 04:51 AM
#2
Re: Executing VB Code
This one
vb Code:
Option Explicit
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 'Api Declartion to Execute the VBCode
Function FExecuteCode(stCode As String, Optional fCheckOnly As Boolean) As Boolean
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Private Sub Command1_Click()
FExecuteCode Text1.Text, False
End Sub
'Make sure that you are giving the right command.Otherwise you wont get 'any output
Please mark you thread resolved using the Thread Tools as shown
-
Mar 13th, 2007, 05:07 AM
#3
Thread Starter
Lively Member
Re: Executing VB Code
Thank you 
-
Mar 13th, 2007, 05:08 AM
#4
Re: [RESOLVED] Executing VB Code
EbExecuteLine works only in IDE. In compiled exe, you'll get an error.
You can use Microsoft Script Control for this:
vb Code:
' Add Microsoft Script Control in the form
Option Explicit
Private Sub ExecuteScript(strScript As String)
On Error GoTo ExecuteScript_Err
ScriptControl1.ExecuteStatement Text1.Text
Exit Sub
ExecuteScript_Err:
If Err.Number = 13 Then
MsgBox "Syntax Error", vbCritical
End If
End Sub
Private Sub Command1_Click()
ExecuteScript Text1.Text
End Sub
Private Sub Form_Load()
Text1.Text = "MsgBox " & """" & "Hello World" & """"
End Sub
-
Mar 19th, 2007, 04:27 AM
#5
Thread Starter
Lively Member
Re: [RESOLVED] Executing VB Code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|