|
|
|
Hello all,
I'd like to know if there is a method in C# that I can call to convert texts into math operators. For instance if I type the text +, -, *, or / into a text box, is there a way to convert them into math operators that the compiler can understand. If there is such a function, if I type a string like 5 - 1 into a text box then call that function, it will convert the text "-" into the minus sign.
I know I will need to convert the text 5 and 1 in the string into numbers before the expression can be evaluated. All I need is to know how to turn text symbols into those four operators and I think I can do the rest. I will try to write functions to handle more complex expressions later. Please point me in the right direction, thanks for your time.
modified 17-Jun-12 5:41am.
|
|
|
|
|
No, there isn't. You cannot convert the text representation into an actual operator in your code they way you're describing.
Depending on what you're doing and the complexity of your expressions, you may just get away with selecting the operation to perform using a Select Case block on the text and performing the actual operations in an expression dedicated to that operation, or you may have to build a expression evalutation engine using something like Reverse Polish Notation[^].
|
|
|
|
|
You can do this quite easily by building a very simple parser.
Give it a try and if you face issues, post them here, someone might be able to help you.
|
|
|
|
|
fill the value in data set
|
|
|
|
|
If this is supposed to be a question it is not at all clear what you want. Please try and think about your problem and explain clearly what is or is not happening.
|
|
|
|
|
|
I never use DataSet s; they're horrible.
|
|
|
|
|
The gerbils attack at midnight.
|
|
|
|
|
Phew - glad I read that, 5 minute warning!
|
|
|
|
|
Wow. We both got a rather weak 1-vote for this. Somebody doesn't have a sense of humor.
|
|
|
|
|
No, you fill the dataset.
|
|
|
|
|
do the following code:
DataTable dt = ds.Table["Employee"];
DataRow row = dt.NewRow();
row["id"] = 1;
row["name"] = "Kishan";
..............
|
|
|
|
|
Hi all,
I am using a windows form timer to check running processes, but this is not a good way to do it, it is blocking the UI.
Wat would be the best way to do this?
This is what I use:
private void check_RunningProcessTimer_Tick(object sender, EventArgs e)
{
if (IsProcessRunning("Some_proces"))
{
this.SendToBack();
}
else
{
this.Activate();
}
if (IsProcessRunning("osk"))
{
btnOskKeyBoard.Text ="X" ;
}
else
{
btnOskKeyBoard.Text = "";
}
}
I would also like to do this for other things like checking if Com port is open or closed.
Thanks,
Groover.
|
|
|
|
|
You should move this type of function to a background thread so that it does not block the UI.
|
|
|
|
|
I have never used threads before and I do not really know how to implement it, please help me on the way.
some questions:
Should I include the public bool that returns the running process in the thread?
Do I have to create a event in the thread for each process change?
How do I deal with with change of Com port change?
I think of using a system timer with autoreset, what would be the timer interval to make sure all the changes are detected?
this is the public bool I use ;
public bool IsProcessRunning(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
Please point me in the right direction,
thanks,
Groover
|
|
|
|
|
I don't think those questions can be reasonably answered in a forum like this. I would suggest you try a search for some of the articles here that deal with thread programming, and try a few test programs to get familiar with the issues surrounding synchronisation and data transfer between processes.
|
|
|
|
|
OK,
I changed Windows forms timer to System.Threading.Timer and Invoked all UI controls in the TimerCallback.
There is one problem left, the:
this.Activate() is called every timer timeout and this causes a problem with dialogs and message boxes.
I can do a:
runningProcess_Timer.Change(Timeout.Infinite, Timeout.Infinite); for every call to a dialog or message
and a:
runningProcess_Timer.Change(0, 100); after closing.
I there an event I can create or handle on dialogs and message boxes I can use to disable and enable the timer when these pop-ups need attention?
Groover.
|
|
|
|
|
You are not doing it quite right. All the UI code including dialogs and message boxes (which are merely custom dialogs) should run in the main thread without interference or timers. Anything that requires periods of inactivity (such as sleep, wait for external event etc) should run in a background thread. The background threads can communicate with the foreground by using shared memory or sending messages. I'm sure you can find some good samples in the Articles section.
|
|
|
|
|
Thank You for Your advice,
I think You don't understand what I am trying to do.
On my main form I have a button that starts the on screen keyboard and if it is running kills it.
There is no problem unless the user uses the close box on the application.
To make the button the right state(close or open) I use the timer to check if the application is running or not.
The same with the Some_process, it has to be topmost until it closes. I have no code for Some_process, it is not my application.
Some_process is killed by a comport event and my code makes my application topmost again and hide the task-bar and start menu.
If the user closes Some_process with the closing button, my application looses focus. To prevent this I have to check if Some_process is running or not.
I have changed the code in my timer handling and it seems not to interfere with any forms an custom message boxes.
Not sure if it interferes with message boxes from System.Windows.Forms MessageBox Class and dialogs.
This is what I have now:
System.Threading.Timer runningProcess_Timer;
runningProcess_Timer = new System.Threading.Timer(new TimerCallback(checkRunningProcesses), null, 0, 100);
private void checkRunningProcesses(object obj)
{
if (this.IsHandleCreated)
{
if (!IsProcessRunning("osk"))
{
this.Invoke(new EventHandler(delegate
{
btnKeyBoard.Text = "";
}));
}
else
{
this.Invoke(new EventHandler(delegate
{
btnKeyBoard.Text = "X";
}));
}
if (!IsProcessRunning("Some_process"))
{
this.Invoke(new EventHandler(delegate
{
int i = 0;
foreach (Form f in Application.OpenForms)
{
if (f.Enabled)
{
i += 1;
}
}
if (i < 2)
{
this.Activate();
}
}));
}
}
}
Groover
|
|
|
|
|
GrooverFromHolland wrote: I think You don't understand what I am trying to do.
That is true.
|
|
|
|
|
messbox can not show until i press the "Alt" on the keyboard,i am confused that,
the detail is:
i run the program in "MainForm",then i open the other form ,when i need the messbox to show,it just can not work ,unless i press the "Alt" key? what's problem?please help,thanks
|
|
|
|
|
We have no idea what the problem is as you you haven't described what the app does, or what the app was doing at the time you showed the MessageBox, nor what the code looks like that created the message box. Without that, it's impossible to answer your question.
|
|
|
|
|
Please don't cross post: Help:messbox can not show normally[^]
Follow at one place. For now, your said behavior about messagebox is not a standard one. Thus, it's difficult to comment on the reason.
|
|
|
|