Execute a Command from a Textbox

I want to Execute a Command from a textbox..

Page 1 of 1

7 Replies - 2965 Views - Last Post: 19 July 2009 - 02:49 PM Rate Topic: -----

#1 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Execute a Command from a Textbox

Posted 18 July 2009 - 11:50 PM

Lets say i have a text box and i type picturebox.visible = false; then i press a button to execute it.
and My Picturebox is not visible now.
so How do i run that command since it was in a text box???
Is This A Good Question/Topic? 0
  • +

Replies To: Execute a Command from a Textbox

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 12:22 AM

What exactly are you trying to do? What's the role of the PictureBox control? It is not visible, and you want to set it to visible by using a command?
Was This Post Helpful? 0
  • +
  • -

#3 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 12:36 AM

This is what i'm trying to do.
I have a picturebox in my form and it is visible now.
i also have 1 button and 1 textbox.
so i run my program and i type picturebox.visible=false then i press my button to execute.
And the Result is that picturebox is hidden now.
so what i'm asking is, do someone know the code that can make that thing happen since i use textbox to make the code.
Was This Post Helpful? 0
  • +
  • -

#4 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 01:19 AM

You'll have to learn more about Reflection and dynamic code compilation (System.CodeDom.Compiler is a namespace you are looking for in this case).

Also please note, [rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#5 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 01:28 AM

Thanks Man.
Was This Post Helpful? 0
  • +
  • -

#6 Yaroslav94  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 294
  • Joined: 15-July 09

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 02:42 AM

View PostZevhEr, on 19 Jul, 2009 - 12:28 AM, said:

Thanks Man.

couldn't u use the change text event?

 if textbox1.text = "picturebox1.visible = false" then
picturebox1.visible = false
end if 



??? cant u use tht???
thnk me if i helped!
Was This Post Helpful? 0
  • +
  • -

#7 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 04:22 AM

I decided to give this a shot using C# which I'm more familiar with. I hope it helps you even though the programming language is wrong.

I made a form and filled it with the input (shown on attachment) and used this code behind the button_click event:

        private void button2_Click(object sender, EventArgs e) {
            CSharpCodeProvider vProvider = new CSharpCodeProvider();
            ICodeCompiler vCompiler = vProvider.CreateCompiler();

            CompilerParameters vParams = new CompilerParameters();
            vParams.GenerateExecutable = false;
            vParams.GenerateInMemory = true;
            vParams.ReferencedAssemblies.Add("System.dll");
            vParams.ReferencedAssemblies.Add("System.Data.dll");
            vParams.ReferencedAssemblies.Add("System.Deployment.dll");
            vParams.ReferencedAssemblies.Add("System.Drawing.dll");
            vParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");


            string vCode = "";
            vCode += "using System;";
            vCode += "public class " + txtClassName.Text;
            vCode += "{";
            vCode += "public void " + txtMethodName.Text + "(" + txtMethodParam.Text + " vParam)";
            vCode += "{";
            vCode += richTextBox1.Text;
            vCode += "}";
            vCode += "}";

            CompilerResults vResults = vCompiler.CompileAssemblyFromSource(
                vParams, vCode);

            if (vResults.Errors.Count == 0) {
                var vNewClass = vResults.CompiledAssembly.CreateInstance(txtClassName.Text);
                vNewClass.GetType().GetMethod(txtMethodName.Text).
                    Invoke(vNewClass, new[] { "Hello" });
            }
        }



As a result new form modal was opened with title "Hello". The code needs a lots of adjusting for it to become more useful.

Sorry for the C# code in VB.NET forum and the lack of comments. I hope that could help you a bit.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#8 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Re: Execute a Command from a Textbox

Posted 19 July 2009 - 02:49 PM

[quote name='Yaroslav94' date='19 Jul, 2009 - 01:42 AM' post='706742']
[quote name='ZevhEr' post='706723' date='19 Jul, 2009 - 12:28 AM']
Thanks Man.

couldn't u use the change text event?

 if textbox1.text = "picturebox1.visible = false" then
picturebox1.visible = false
end if 



??? cant u use tht???
thnk me if i helped!


Yes. That's help. Thanks. But that is not what i mean.
I didn't write Picturebox1.visible=false in my form code.
I just write it in my text box and run it.
And if i change the text box text to -> Picturebox1.visible=true
It can make the Picture box show.
So That text box is just like a form code where we type our code in.

This post has been edited by ZevhEr: 19 July 2009 - 02:54 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1