473,411 Members | 2,154 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,411 software developers and data experts.

New to windows app in C#

Hello all. I am used to using Write and WriteLine when trying to display my results using the COnsole.
Now working with windows applications, I am trying to display the results in a textbox but keep coming up with the wrong thing.
It should say:

The sum of [integer entered by the user in txtfirst textbox] and [integer entered by user in the txtsecond textbox] is: [displays answer here in txtanswer]

What it DOES say is:
The sum of System.Windows.Form.

I don't understand why I am getting that.
Here is the code for btnadd. Can someone give me some guidance please?

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void btnadd_Click(object sender, System.EventArgs e)
  3.         {
  4.  
  5.             string inValue;
  6.             string inValue2;
  7.             double firstNum;
  8.             double secondNum;
  9.             double add;
  10.  
  11.             inValue = txtfirst.Text;
  12.             inValue2 = txtsecond.Text;
  13.  
  14.             firstNum = double.Parse(inValue);
  15.             secondNum = double.Parse(inValue2);
  16.             add = (firstNum + secondNum);
  17.             txtanswer.Text = string.Format("The sum of {0} and {1} is: {2}", txtfirst, txtsecond, add).ToString();
  18.         }
  19.  
Jul 24 '09 #1
4 1369
tlhintoq
3,525 Expert 2GB
You are really close.

Expand|Select|Wrap|Line Numbers
  1. txtanswer.Text = string.Format("The sum of {0} and {1} is: {2}", txtfirst, txtsecond, add).ToString();
{0} is being formatted with textfirst (a control) not with txtfirst.text, the text of the control. If the textbox were wider you would see the rest of what it is trying to say:
"The sum of System.Windows.Forms.Textbox and System.Windows.Forms.Text is 42", or whatever the right sum is.


same issue with txtsecond

You can also take out the ending ".ToString();
string.Format returns a string, you don't have to turn a string into a string.
Jul 24 '09 #2
Ah ok. I understand now. Thanks so much. :)
Jul 24 '09 #3
I think it should be something like:
Expand|Select|Wrap|Line Numbers
  1. label1.Text = "The sum of " + textBox1.Text + " and " + textBox2.Text + " is:" + add.ToString();
  2.  
Jul 24 '09 #4
@pbj2009
write txtfirst.Text, txtsecond.Text in string.Format();

Reason for you error is that txtfirst is a text box not the text in that textbox.
Jul 24 '09 #5

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

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.