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,GrabNumFromAray(RandomNumGen(4))) ]
So therefore, TextBox1.Text would look like this = "Multiply(4,GrabNumFromAray(RandomNumGen(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,GrabNumFromAray(RandomNumGen(4))) AS WELL AS RandomNumGen(Multiply(4,5)). It would be nice if this could handle overloaded constructors as well (...Such as: textbox1.text = Multiply(4,RandomNumGen(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.Reflection?
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 InitializeComponents.... */
Void Main()
{
InitializeComponents();
}
public void Button1_Click(object sender, EventArgs e) //<-- Forgot what button method looks like
{
int i;
/* Type t = this.GetType();
MethodInfo mi = t.GetMethod(TextBox1.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.ToString(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(int 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 WindowsApplication..