473,487 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Nov 21 '05 #1
4 8486
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

Nov 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

Nov 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

Nov 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

Nov 21 '05 #5

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

Similar topics

19
5134
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
8205
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...
4
2121
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 =...
5
6101
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...
11
11909
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
35437
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??
7
14022
by: andreas.lydersen | last post by:
Hi! While communicating with a monitoring unit, I get some hex values representing degrees celcius from its probes. The values can be something like '19' or '7d'. To convert it to int, I do the...
11
3702
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
3959
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
5772
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
7106
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
6967
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
7137
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,...
1
6846
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...
1
4874
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
4565
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...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.