|
-
Jun 18th, 2008, 05:19 AM
#1
Thread Starter
Addicted Member
Run code from textbox
So,
I searched, and found a code.
I added scriptcontrol1 component(and also added in references)
I have this code:
Code:
scriptcontrol1.executestatement text1.text
when i enter "msgbox "test"" in text1 and press command1 button then it shows a messagebox
however
when i enter "form4.caption = "test"" then it shows error 424: object required form4
-
Jun 18th, 2008, 07:40 AM
#2
Re: Run code from textbox
You use the control's AddObject method to add host objects to the script's namespace.
A Google search should produce a number of introduction and tutorial articles.
-
Jun 18th, 2008, 11:17 AM
#3
Re: Run code from textbox
Do it like this. Instead of adding the script control add a reference to the Microsoft Script Control 1.0 in your project's references.
Code:
Option Explicit
Dim script As ScriptControl
Private Sub Command1_Click()
script.ExecuteStatement Text1.Text
End Sub
Private Sub Form_Load()
Set script = New ScriptControl
script.Language = "VBScript"
script.AddObject "Form1", Form1
'Text1.Text = "MsgBox ""Hello"""
'Text1.Text = "Form1.Command1.Caption = ""Hello"""
Text1.Text = "Form1.Caption = ""Hello"""
End Sub
Last edited by jmsrickland; Jun 18th, 2008 at 11:23 AM.
-
Jun 19th, 2008, 02:20 AM
#4
Thread Starter
Addicted Member
Re: Run code from textbox
The above code works fine but how can I like, change variables?
I have
Code:
Public Type Player
Attack As Integer
Class As Integer
DeathCount As Integer
Defense As Integer
EXP As Integer
HP As Integer
KillCount As Integer
Level As Integer
MaxHP As Integer
Meteors As Integer
Money As Integer
Name As String
End Type
in a module.
But i can't use
Code:
Player.Name = "test"
-
Jun 19th, 2008, 07:56 AM
#5
Re: Run code from textbox
You will have to call a Sub that loads the fields of the UDT and you also need to dimension the UDT, which you didn't do.
-
Jun 20th, 2008, 03:38 AM
#6
Thread Starter
Addicted Member
Re: Run code from textbox
-
Jun 20th, 2008, 02:10 PM
#7
Re: Run code from textbox
In a Module add the following
Code:
'
'
Public Type Player
Attack As Integer
Class As Integer
DeathCount As Integer
Defense As Integer
EXP As Integer
HP As Integer
KillCount As Integer
Level As Integer
MaxHP As Integer
Meteors As Integer
Money As Integer
Name As String
End Type
'
'
In the Form add the following
Code:
'
'
Dim script As ScriptControl
Dim Players As Player
Private Sub Command1_Click()
Text1.Text = "Sub CallLoadPlayers" & vbCrLf & _
" '" & vbCrLf & _
" ' This is the internal Sub that the VBScript Calls" & vbCrLf & _
" '" & vbCrLf & _
" LoadPlayers" & vbCrLf & _
"End Sub"
Set script = New ScriptControl
script.Language = "VBScript"
script.AddObject "Any text you want", Me, True
script.AddCode Text1.Text
'
' Run the Sub that is in the VBScript code
'
script.Run "CallLoadPlayers"
End Sub
Public Sub LoadPlayers()
'
' This Sub us called by the VBScript in the Text1 Textbox
'
Players.Name = "test"
'
'
End Sub
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
|