473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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,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..
Oct 12 '08 #1
2 1085
tlhintoq
3,525 Expert 2GB
Is this a homework assignment for school?
Oct 13 '08 #2
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(which 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.
Oct 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Trond | last post by:
First i must say i am sorry for the repost. I noticed to late that i forgot to add text in the subject field. I made a class that has one purpose. That is to read a log file into an array and...
8
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
3
by: Casper | last post by:
Hi .Net experts, I am trying to build a user control of textbox and would like to add a public method to the object like public void CheckOptions(string str) { // codes here }
2
by: Sathyaish | last post by:
How does a constructor of one class call another of the same class? When would this mechanism make sense or be required? PS: Two instances I saw are: (a) While using the Singleton pattern...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
14
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
11
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I know I sound like a one-note Johnny on this but I'm still looking for a solution. I need to display characters coming in from a serial port or a socket. I also need to be able to type...
0
by: JosAH | last post by:
A Simple Text-Based Menu System Read this this post; there are numerous posts like that: a newbie struggling with some sort of menu implementation. They want nested menus of course and an option...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.