473,396 Members | 1,847 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,396 software developers and data experts.

converting data types

How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks OK,
the vlaues are used for calcualtions... but they need to be double data type.
Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott

Nov 16 '05 #1
8 4457
double aux = Int64.Parse(textbox.Text);
aux += aux;
textbox.Text = aux.ToString();

I hope this help you.
Ernesto Lores (Bcn)

"Scott" <Sc***@discussions.microsoft.com> escribió en el mensaje
news:36**********************************@microsof t.com...
How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks OK, the vlaues are used for calcualtions... but they need to be double data type. Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott

Nov 16 '05 #2
Scott,

You can use double.Parse(textbox.Text) to convert it to a double, and then
use textbox.Text = answer.ToString()

Is that what you need?

Joel
http://www.rosscode.com

"Scott" <Sc***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks OK, the vlaues are used for calcualtions... but they need to be double data type. Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott

Nov 16 '05 #3
Thanks. That worked...

"e-lores" wrote:
double aux = Int64.Parse(textbox.Text);
aux += aux;
textbox.Text = aux.ToString();

I hope this help you.
Ernesto Lores (Bcn)

"Scott" <Sc***@discussions.microsoft.com> escribió en el mensaje
news:36**********************************@microsof t.com...
How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks

OK,
the vlaues are used for calcualtions... but they need to be double data

type.
Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott


Nov 16 '05 #4
double aux = double.Parse(textbox.Text) ;
is the correct form.

(Int64 is used to convert to long integer)
"e-lores" <e_*****************@yahoo.es> escribió en el mensaje
news:es**************@TK2MSFTNGP09.phx.gbl...
double aux = Int64.Parse(textbox.Text);
aux += aux;
textbox.Text = aux.ToString();

I hope this help you.
Ernesto Lores (Bcn)

"Scott" <Sc***@discussions.microsoft.com> escribió en el mensaje
news:36**********************************@microsof t.com...
How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks

OK,
the vlaues are used for calcualtions... but they need to be double data

type.
Then, after the calculations, how to do I convert the double back into the data type needed by the textbox control?

Thanks,
Scott


Nov 16 '05 #5
Thanks for help! The code I wrote is below. So far, everything is working
just fine...

double bearingOne = double.Parse(textBox1.Text) ;
double bearingTwo = double.Parse(textBox2.Text) ;
double angleBetween = bearingOne + bearingTwo ;

textBox3.Text = angleBetween.ToString() ;

Thanks,
Scott

"Joel Ross" wrote:
Scott,

You can use double.Parse(textbox.Text) to convert it to a double, and then
use textbox.Text = answer.ToString()

Is that what you need?

Joel
http://www.rosscode.com

"Scott" <Sc***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks

OK,
the vlaues are used for calcualtions... but they need to be double data

type.
Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott


Nov 16 '05 #6
Any thoughts about when user doesn't enter a valid real number?? :)
Please explore Double.TryParse method

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
I recognize the need to add some form of input validation but, since I'm new
to c#, I still need to figure oout that part. I'm collecting the values from
textboxes on a form and would prefer to throw a message / flag instructing
the user to enter a valid value.

Any suggestions / code samples are greatly appreciated.

Thanks,
Scott

"Maqsood Ahmed" wrote:
Any thoughts about when user doesn't enter a valid real number?? :)
Please explore Double.TryParse method

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #8
Maybe you can use ...

1. ... KeyPress event (you control key by key)
2. ... Validating event (you control the value inserted)

Ernesto Lores (Bcn)
"Scott" <Sc***@discussions.microsoft.com> escribió en el mensaje
news:88**********************************@microsof t.com...
I recognize the need to add some form of input validation but, since I'm new to c#, I still need to figure oout that part. I'm collecting the values from textboxes on a form and would prefer to throw a message / flag instructing
the user to enter a valid value.

Any suggestions / code samples are greatly appreciated.

Thanks,
Scott

"Maqsood Ahmed" wrote:
Any thoughts about when user doesn't enter a valid real number?? :)
Please explore Double.TryParse method

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
22
by: Keith MacDonald | last post by:
Hello, Is there a portable (at least for VC.Net and g++) method to convert text between wchar_t and char, using the standard library? I may have missed something obvious, but the section on...
2
by: genc_ymeri | last post by:
Hi, Well, I'm looking around for another opinion. We have two webservers, the legacy one writen in ASP and the new one in ASP.Net. Once a user logs in the ASP.Net web app, the session of the...
5
by: Nelson | last post by:
In my web form, I am converting all lower case letters to upper case when the user types the characters in the edit boxes. I am achieving that by injecting client side script (onkeyup event) for...
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
4
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc....
1
by: SLC via DBMonster.com | last post by:
Hello I'm a newbie to this and I need help, please My question is, we currently have a IDMS db and will be converting to DB2. What are the things I should do? The IDMS has not been documented very...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
21
by: py_genetic | last post by:
Hello, I'm importing large text files of data using csv. I would like to add some more auto sensing abilities. I'm considing sampling the data file and doing some fuzzy logic scoring on the...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.