Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 30th, 2007, 03:18 PM
Authorized User
 
Join Date: Jan 2007
Location: , LA, .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to seymour_glass
Default stupid question...

Ok, I am making a simple calculator. All I am looking for is a method which acts like a Console.ReadLine, so that I can enter a value twice into a textBox during the same Click Event...

i.e...
{
val1 = int.Parse(uiUserTextBox.Text)
(some method)
val2 = int.Parse(uiUserTextBox.Text)
}

Help??

Seymour

  #2 (permalink)  
Old May 1st, 2007, 03:43 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you mean by "during the same click event"? If this is a winforms app, then you can't really do the equivalent of a console readline that waits for user input. You need to allow the user to input something, to an event (click button, press enter, etc) then enter another value and repeat the event to complete the operation.

-Peter
  #3 (permalink)  
Old May 1st, 2007, 09:17 PM
Authorized User
 
Join Date: Jan 2007
Location: , LA, .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to seymour_glass
Default

I knew that this might be a problem. I understand that I can't use a console readline being a windows app, however, I cannot seem to grasp this. If i have '3' in the TextBox and press plus, my current code is adding 3 to itself (because it is what gets parsed) and returning that value. Maybe if someone can view the code for my click_event it will help convey why I am still messing this up.

Code:
try
    {
          if(lngTotal == 0)
        {
        val2 = val1;
        val1 = long.Parse(uiAnswerTextBox.Text);
        uiAnswerTextBox.Clear();

        myMath ans = new myMath(); 
        lngTotal  = ans.Add(val1, val2); 
        uiAnswerTextBox.Text = (lngTotal.ToString());
        }
        else
            {
            val1 = lngTotal;
            val2 = long.Parse(uiAnswerTextBox.Text);

            myMath ans = new myMath(); 
            lngTotal  = ans.Add(val1, val2); 
            uiAnswerTextBox.Text = (lngTotal.ToString());
             }

            }
    catch
       {
          MessageBox.Show("Please input a number", 
               "Input Error", MessageBoxButtons.OK, 
           MessageBoxIcon.Hand);
        }
      }
I just need a direction because I dont see my problem....

Seymour

  #4 (permalink)  
Old May 2nd, 2007, 06:40 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I can't see where lngTotal is getting assigned originally, so I'm not sure how the branching logic will be handled.

But generally, I think the problem is that you can't actually execute the "add" process when you press the "+" key. That isn't how it works on most calculators anyway. You should handle a sequence of key presses like this:
    3
    +
    3
 [Enter]
You have to place the first value into a variable and capture the operation (+,-,*,/,etc.) to another variable. Then you can perform the desired operation (whether or not the user enters a different value).

-Peter


Similar Threads
Thread Thread Starter Forum Replies Last Post
Probably stupid question skiloff BOOK: ASP.NET Website Programming Problem-Design-Solution 0 July 6th, 2005 02:44 PM
stupid question j_pres44 Beginning PHP 4 December 13th, 2004 05:06 AM
stupid question Warbird General .NET 6 December 7th, 2004 09:33 AM
A really stupid question Phaedrus VB.NET 2002/2003 Basics 3 October 29th, 2003 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.