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?
Printable View
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?
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
Thank you :):)
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
thnaks iPrank