here this is how i did it, Hack sorry took me forever to find this out haha
First you have to add a component called Microsoft Script Control
and then a a textbox called Text1
and a commandbutton called CmdRun
Code:
Private Sub Form_Load()
'add the objects you want to use in your script
ScriptControl1.AddObject "form1", Form1
ScriptControl1.AddObject "command1", Command1
Text1.Text = "Sub Form1_Load" & vbcrlf & "form1.backcolor = vbwhite" & vbcrlf & "End Sub"
'Notice when you click on CmdRun it adds the text to the script and load the sub Form1_Load
Private Sub CmdRun_Click()
ScriptControl1.AddCode Text1.Text
ScriptControl1.Run "Form1_Load"
End Sub
you can add command buttons if you want
add a commandbutton called Command1
Code:
Private Sub Form_Load()
'add the objects you want to use in your script
ScriptControl1.AddObject "form1", Form1
ScriptControl1.AddObject "command1", Command1 'Mak sure u add objects(component) you need here!!
Text1.Text = "Sub Form1_Load" & vbcrlf & "form1.backcolor = vbwhite" & vbcrlf & "End Sub"
Text1.Text = Text1.Text & vbcrlf & vbcrlf & "Sub Command1_Click" & vbcrlf & "MsgBox" & " " & chr(34) & "Command 1 CLICKED" & chr(34) & vbcrlf & "command1.left = command1.left + 200" & vbcrlf & "End Sub"
'Notice when you click on CmdRun it adds the text to the script and load the sub Form1_Load
Private Sub CmdRun_Click()
ScriptControl1.AddCode Text1.Text
ScriptControl1.Run "Form1_Load"
End Sub
Private Sub Command1_Click()
On Error Goto ErrHandler
ScriptControl1.Run "Command1_Click" 'This will run the Command1_Click Sub
ErrHandler:
If err.num = 0 then
exit sub
End If
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
End Sub