Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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
Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:21 PM.


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