Putting text into a textbox, and then calling methods with constructors through the t

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thisismykindabyte
    New Member
    • Oct 2008
    • 9

    Putting text into a textbox, and then calling methods with constructors through the t

    Hey-o!

    Can anyone tell me how to make this work?

    Long story short, I would like to use text from TextBox1.Text as the functions I would like to call. Then I would like TextBox1.Text to show the result of the functions I just called.

    (Pretend the line below is a textbox)
    [ Multiply(4,Grab NumFromAray(Ran domNumGen(4))) ]

    So therefore, TextBox1.Text would look like this = "Multiply(4,Gra bNumFromAray(Ra ndomNumGen(4))) "

    Most importantly about this: I need a way for the textbox to take any amount of functions with any amount of variables. In other words I need to be able to input a string into textbox1.text such as: Multiply(4,Grab NumFromAray(Ran domNumGen(4))) AS WELL AS RandomNumGen(Mu ltiply(4,5)). It would be nice if this could handle overloaded constructors as well (...Such as: textbox1.text = Multiply(4,Rand omNumGen(1,4).. . where 1,4 are 2 varibles for RandomNumGen to use as opposed to just the 1 variable I have specified in the code below)

    I don't know if this can be done, but anything will help. Thanks!

    The code would look like this:

    Using System
    //Using whatever we have too to get the job done, System.Reflecti on?

    Class MyClass {

    int[] iarray = new int[4];
    iarray = {10,20,30,40,50 };

    /* We are also using TextBox1 and Button1, which would be shown in InitializeCompo nents.... */

    Void Main()
    {
    InitializeCompo nents();
    }

    public void Button1_Click(o bject sender, EventArgs e) //<-- Forgot what button method looks like
    {
    int i;
    /* Type t = this.GetType();
    MethodInfo mi = t.GetMethod(Tex tBox1.Text); */
    //Do we need to use the code above for what I need to do?
    i = ? //This is where I would like to run the functions listed in textbox1.text, and return the result to i here....
    //The line below is to show the result of all the functions from textbox1.text being run...
    textbox1.text = Convert.ToStrin g(i);
    }

    public void Multiply(int multiplier, int number)
    { int i;
    i = multiplier * number; // This would be 160, because we're using 4(as shown above), and 40(as shown below)

    return i;
    }


    public GrabNumFromAray (int i)
    {
    int myint;
    myint = iarrary[i]; /*pretend i here is 3, as stated below, which means myint now equals 40 */
    return myint;
    }


    public int RandomNumGen(in t i)
    {
    //Call random roller function, forgot how but it would look like this
    Random roller = new Random(max value for random generation = i)
    i = roller.roll; //So we return 0-4... Lets pretend we return 3;
    return i;
    }


    Something that would be helpful to know too... If I can call a function within a function through using the textbox, does anyone have any ideas how to specify parts of the textbox text that are string or int for the actual method? Basically, pretend I have Function1, which takes a int and a string "Function1( int i, string s) {code here}", if I can call Function 1 through the textbox, how can I specify that the first argument is an integer and the second is a string? Or does reflection take care of that/Is it something I don't have to worry about?

    Thank you so much!!

    //Using C# 2.0(Could use 3.5 if have too), making WindowsApplicat ion..
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Is this a homework assignment for school?

    Comment

    • thisismykindabyte
      New Member
      • Oct 2008
      • 9

      #3
      No.

      Is there something simple and effecient that I am overlooking in regards to executing any combination of multiple functions with multiple functions as parameters(whic h could contain more functions as parameters) through a textbox control? Reflection doesn't seem to be able to handle this idea in it's entirety, hopefully I'm wrong.

      Comment

      Working...