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

Negative Numbers?

Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text)
TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value
is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be
added together.

Thanks,
Chuck
Jul 21 '05 #1
4 2108
It is displayed as "(46)" beacuse that is what your format specifier
("#,##0.00;(#,##0.00);0.00") is asking it to do for negative numbers.

Since the Convert.ToDouble function does not recognize this format, you
could check for the format you're looking for and change it appropriately:

For example:

string sText = TextBox3.Text
if (sText.StartsWith("("))
sText = "-" + sText.Remove("(").Remove(")")
end if

TextBox5.text = Convert.ToDouble(sText) + Convert.ToDouble(Textbox4.text)

Or, probably the better way to do this is to just use the result in AString
which is already a double and stores the value that you're looking for
anyways.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #2
Hi Charles,

First of all, you're not doing addition; you're doing subtraction. Then,
when you fill textbox5, you'r trying to convert a string to a double. Try
debugging, set a few breakpoints, and follow the values.

HTH,

Bernie Yaeger

"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #3
Don't save the number in the text box, save it in a variable. Just use the
textbox for displaying the results.

--
Jonathan Allen
"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #4
Charles,
In addition to the other comments.

Use the Double.Parse overload (instead of Convert.ToDouble) that allows you
to specify the number style to use when converting, something like:
AString = Double.Parse(TextBox1.Text, NumberStyles.Currency) -
Double.Parse(DoubleTextBox2.Text, NumberStyles.Currency)
Read the help on NumberStyles enum to see what the various options allowed
are.

Hope this helps
Jay
"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl... Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) -
Convert.To(DoubleTextBox2.Text)
TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the
value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can
be added together.

Thanks,
Chuck

Jul 21 '05 #5

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

Similar topics

19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
4
by: Charles A. Lackman | last post by:
Hello, I have some textboxes that are doing addition: Dim AString As Double AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text =...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.