Weird Math problem | | |
I'm running into a very weird problem regarding subtraction.
Subtraction behaves as if it's an addition in the below sub
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
the discount mDisc was added to the total with the - operator!
Your help is greatly appreciated.
Bill
--------
Private Sub txtDiscount_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtDiscount.TextChanged
Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
If IsNumeric(txtDiscount.Text) = True Then
mDisc = txtDiscount.Text
Else
mDisc = 0
End If
If IsNumeric(txtRackCost.Text) = True Then
mRackc = txtRackCost.Text
Else
mRackc = 0
End If
If IsNumeric(txtJacoEC.Text) = True Then
mJaEc = txtJacoEC.Text
Else
mJaEc = 0
End If
If IsNumeric(txtWfEC.Text) = True Then
mWfEC = txtWfEC.Text
Else
mWfEC = 0
End If
If IsNumeric(txtFactorAdjust.Text) = True Then
mFactorAdj = txtFactorAdjust.Text
Else
mFactorAdj = 0
End If
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
End Sub | | | | re: Weird Math problem
On Oct 17, 3:55 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
I'm running into a very weird problem regarding subtraction.
>
Subtraction behaves as if it's an addition in the below sub
>
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>
the discount mDisc was added to the total with the - operator!
>
Your help is greatly appreciated.
>
Bill
>
--------
>
Private Sub txtDiscount_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtDiscount.TextChanged
>
Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
>
If IsNumeric(txtDiscount.Text) = True Then
>
mDisc = txtDiscount.Text
>
Else
>
mDisc = 0
>
End If
>
If IsNumeric(txtRackCost.Text) = True Then
>
mRackc = txtRackCost.Text
>
Else
>
mRackc = 0
>
End If
>
If IsNumeric(txtJacoEC.Text) = True Then
>
mJaEc = txtJacoEC.Text
>
Else
>
mJaEc = 0
>
End If
>
If IsNumeric(txtWfEC.Text) = True Then
>
mWfEC = txtWfEC.Text
>
Else
>
mWfEC = 0
>
End If
>
If IsNumeric(txtFactorAdjust.Text) = True Then
>
mFactorAdj = txtFactorAdjust.Text
>
Else
>
mFactorAdj = 0
>
End If
>
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>
End Sub
What was the value of mDisc? If it is a negative value, then it will
add... - a - equals a plus:
1 - -2 =
1 + +2 = 3
--
Tom Shelton | | | | re: Weird Math problem
Tom;
It's a positive value.
I tested repeatedly.
I also have a similar problem with a bit value of 1 (true) is shown as -1 in
VS2005
Thanks
Bill
-----------
Below is my VS version info:
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
Microsoft Visual Basic 2005 77626-009-0000007-41468
Microsoft Visual Basic 2005
Microsoft Visual C# 2005 77626-009-0000007-41468
Microsoft Visual C# 2005
Microsoft Visual C++ 2005 77626-009-0000007-41468
Microsoft Visual C++ 2005
Microsoft Visual J# 2005 77626-009-0000007-41468
Microsoft Visual J# 2005
Microsoft Visual Web Developer 2005 77626-009-0000007-41468
Microsoft Visual Web Developer 2005
Microsoft Web Application Projects 2005 77626-009-0000007-41468
Microsoft Web Application Projects 2005
Version 8.0.50727.762
Crystal Reports AAC60-G0CSA4B-V7000AY
Crystal Reports for Visual Studio 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1
(KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition -
ENU.
If you later install a more recent service pack, this service pack will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601
Security Update for Microsoft Visual Studio 2005 Professional Edition - ENU
(KB937061)
This Security Update is for Microsoft Visual Studio 2005 Professional
Edition - ENU.
If you later install a more recent service pack, this Security Update will
be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/937061
SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.3042.00
SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.2047.00
SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.2047.00
"Tom Shelton" <tom_shelton@comcast.netwrote in message
news:1192660685.048358.162480@t8g2000prg.googlegro ups.com... Quote:
On Oct 17, 3:55 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
>I'm running into a very weird problem regarding subtraction.
>>
>Subtraction behaves as if it's an addition in the below sub
>>
>txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>>
>txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>>
>txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>>
>the discount mDisc was added to the total with the - operator!
>>
>Your help is greatly appreciated.
>>
>Bill
>>
>--------
>>
>Private Sub txtDiscount_TextChanged(ByVal sender As System.Object, ByVal
>e
>As System.EventArgs) Handles txtDiscount.TextChanged
>>
>Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
>>
>If IsNumeric(txtDiscount.Text) = True Then
>>
>mDisc = txtDiscount.Text
>>
>Else
>>
>mDisc = 0
>>
>End If
>>
>If IsNumeric(txtRackCost.Text) = True Then
>>
>mRackc = txtRackCost.Text
>>
>Else
>>
>mRackc = 0
>>
>End If
>>
>If IsNumeric(txtJacoEC.Text) = True Then
>>
>mJaEc = txtJacoEC.Text
>>
>Else
>>
>mJaEc = 0
>>
>End If
>>
>If IsNumeric(txtWfEC.Text) = True Then
>>
>mWfEC = txtWfEC.Text
>>
>Else
>>
>mWfEC = 0
>>
>End If
>>
>If IsNumeric(txtFactorAdjust.Text) = True Then
>>
>mFactorAdj = txtFactorAdjust.Text
>>
>Else
>>
>mFactorAdj = 0
>>
>End If
>>
>txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>>
>txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>>
>txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>>
>End Sub
>
What was the value of mDisc? If it is a negative value, then it will
add... - a - equals a plus:
>
1 - -2 =
1 + +2 = 3
>
--
Tom Shelton
>
| | | | re: Weird Math problem
"Bill Nguyen" <billn_nospam_please@jaco.comschrieb Quote:
Tom;
It's a positive value.
I tested repeatedly.
Please show us the exact line where the problem occurs and all the values in
all variables in the line. Quote:
I also have a similar problem with a bit value of 1 (true) is shown
as -1 in VS2005
You should switch Option Strict On
Armin | | | | re: Weird Math problem
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
Mark Lincoln
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
I also have a similar problem with a bit value of 1 (true) is shown as -1 in
VS2005
| | | | re: Weird Math problem
In these two expressions:
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj),
"0.#####0")
you're subtracting the sum of mDisc and another value from mRackc. In
this expression:
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
you're subtracting mDisc from mRackc, then adding mWfEC to the total.
I have no data with which I can test this, but I suspect you are
either missing a couple of parentheses in the last expression, or you
have too many in the first two.
Mark Lincoln
On Oct 17, 5:55 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
I'm running into a very weird problem regarding subtraction.
>
Subtraction behaves as if it's an addition in the below sub
>
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>
the discount mDisc was added to the total with the - operator!
>
Your help is greatly appreciated.
>
Bill
>
--------
>
Private Sub txtDiscount_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtDiscount.TextChanged
>
Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
>
If IsNumeric(txtDiscount.Text) = True Then
>
mDisc = txtDiscount.Text
>
Else
>
mDisc = 0
>
End If
>
If IsNumeric(txtRackCost.Text) = True Then
>
mRackc = txtRackCost.Text
>
Else
>
mRackc = 0
>
End If
>
If IsNumeric(txtJacoEC.Text) = True Then
>
mJaEc = txtJacoEC.Text
>
Else
>
mJaEc = 0
>
End If
>
If IsNumeric(txtWfEC.Text) = True Then
>
mWfEC = txtWfEC.Text
>
Else
>
mWfEC = 0
>
End If
>
If IsNumeric(txtFactorAdjust.Text) = True Then
>
mFactorAdj = txtFactorAdjust.Text
>
Else
>
mFactorAdj = 0
>
End If
>
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>
End Sub
| | | | re: Weird Math problem
On Oct 17, 4:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
Tom;
It's a positive value.
I tested repeatedly.
I also have a similar problem with a bit value of 1 (true) is shown as -1 in
VS2005
>
Thanks
>
Bill
Bill,
First of all, I can tell you do not have option strict turned on.
Which is probably a bad idea, but that doesn't seem to be the root of
your problem:
' numbers i tested
mRackc = 100.0
mDisc = 5
mJaEc = 100.0
mWfEC = 100.0
mFactorAdj = 100.0
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
100 - (5 + 100) = 100 - 105 = -5
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
100 - 5 + 100 = 95 + 100 = 195
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj),
"0.#####0")
100 - (5 + 100) = 100 - 105 = -5
As far as I can tell, things are working correctly. What do you
expect the answers to be?
--
Tom Shelton | | | | re: Weird Math problem
"Bill Nguyen" <billn_nospam_please@jaco.comwrote in message
news:uMeHlhQEIHA.3332@TK2MSFTNGP04.phx.gbl... Quote:
I'm running into a very weird problem regarding subtraction.
>
Subtraction behaves as if it's an addition in the below sub
>
>
>
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0")
>
txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
>
txtFactorCost.Text = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
>
>
>
the discount mDisc was added to the total with the - operator!
>
Your help is greatly appreciated.
>
>
>
Bill
>
--------
In the first and the third equations, if mJaEc or mFactorAdj are greater
than mDisc, then you will end up with a negative value inside the
parenthesis. If that happens, you will end up subtracting a negative number
from mRackc - which becomes an addition operation.
As for the second equation...
If you have a typo and accidentally left the parenthesis out, then the same
will apply to mWfEC.
Todd | | | | re: Weird Math problem
Whoever told you that load of claptrap!!! It's information like that gives
people the wrong idea of how something works.
BASIC (of which VB is a derivative) defines False as 0 (zero) but True is
the result of a bitwise NOT of False (i.e, True = Not False).
It is only when you attempt to cast a Boolean to another numeric type that
you get a result of -1 for True which is demonstrated by:
Dim _boolean As Boolean = False
Dim _integer As Integer = Not Convert.ToInt32(_boolean)
Console.Writeline(_integer)
VB makes no conversions whatsover when you pass a Boolean to something
written in another .NET language.
If any conversion is required then then some form of 'middle-man' is invoked
to carry out any such conversions.
"Mark Lincoln" <mlincoln@earthlink.netwrote in message
news:1192665237.811977.160320@v29g2000prd.googlegr oups.com... Quote:
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
>
Mark Lincoln
>
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
>I also have a similar problem with a bit value of 1 (true) is shown as -1
>in
>VS2005
>
| | | | re: Weird Math problem
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
The information comes from Francisco Balena's book. I don't have it
in front of me, so I might be a bit hazy on the details. If you
really want me to, I'll quote him verbatim when I get the chance.
Mark Lincoln
On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote: Quote:
Whoever told you that load of claptrap!!! It's information like that gives
people the wrong idea of how something works.
>
BASIC (of which VB is a derivative) defines False as 0 (zero) but True is
the result of a bitwise NOT of False (i.e, True = Not False).
>
It is only when you attempt to cast a Boolean to another numeric type that
you get a result of -1 for True which is demonstrated by:
>
Dim _boolean As Boolean = False
>
Dim _integer As Integer = Not Convert.ToInt32(_boolean)
>
Console.Writeline(_integer)
>
VB makes no conversions whatsover when you pass a Boolean to something
written in another .NET language.
>
If any conversion is required then then some form of 'middle-man' is invoked
to carry out any such conversions.
>
"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>
news:1192665237.811977.160320@v29g2000prd.googlegr oups.com...
>
>
> Quote:
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
> > Quote:
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
I also have a similar problem with a bit value of 1 (true) is shown as -1
in
VS2005- Hide quoted text -
>
- Show quoted text -
| | | | re: Weird Math problem
Thanks all of you for helping me on this "weird math problem" thread.
1. It's stupid me. I put a wrong operator in a different sub and tried to
fix it in another sub! The formula is working properly.
2. Regarding the -1 as true, it has caused problem for me probably because I
did not set Strict = ON. When I did, the project gave me tons of errors that
I will have to fix line by line, so I don't know if it's a good thing to
switch it on.
Thanks again
Bill
"Mark Lincoln" <mlincoln@earthlink.netwrote in message
news:1192723584.520582.20570@t8g2000prg.googlegrou ps.com... Quote:
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
>
The information comes from Francisco Balena's book. I don't have it
in front of me, so I might be a bit hazy on the details. If you
really want me to, I'll quote him verbatim when I get the chance.
>
Mark Lincoln
>
On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote: Quote:
>Whoever told you that load of claptrap!!! It's information like that
>gives
>people the wrong idea of how something works.
>>
>BASIC (of which VB is a derivative) defines False as 0 (zero) but True is
>the result of a bitwise NOT of False (i.e, True = Not False).
>>
>It is only when you attempt to cast a Boolean to another numeric type
>that
>you get a result of -1 for True which is demonstrated by:
>>
> Dim _boolean As Boolean = False
>>
> Dim _integer As Integer = Not Convert.ToInt32(_boolean)
>>
> Console.Writeline(_integer)
>>
>VB makes no conversions whatsover when you pass a Boolean to something
>written in another .NET language.
>>
>If any conversion is required then then some form of 'middle-man' is
>invoked
>to carry out any such conversions.
>>
>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>>
>news:1192665237.811977.160320@v29g2000prd.googleg roups.com...
>>
>>
>> Quote:
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
>> >> Quote:
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote:
>I also have a similar problem with a bit value of 1 (true) is shown
>as -1
>in
>VS2005- Hide quoted text -
>>
>- Show quoted text -
>
>
| | | | re: Weird Math problem
It is an Extremely Good Thing to have STRICT ON. Yes it can be a pain
when you first turn it on, but some of those tons of errors you get
are real errors that need to be fixed.
On Thu, 18 Oct 2007 10:32:07 -0700, "Bill Nguyen"
<billn_nospam_please@jaco.comwrote: Quote:
>Thanks all of you for helping me on this "weird math problem" thread.
>
>1. It's stupid me. I put a wrong operator in a different sub and tried to
>fix it in another sub! The formula is working properly.
>
>2. Regarding the -1 as true, it has caused problem for me probably because I
>did not set Strict = ON. When I did, the project gave me tons of errors that
>I will have to fix line by line, so I don't know if it's a good thing to
>switch it on.
>
>Thanks again
>
>Bill
>
>"Mark Lincoln" <mlincoln@earthlink.netwrote in message
>news:1192723584.520582.20570@t8g2000prg.googlegro ups.com... Quote:
>Yes, you're correct: Casting a Boolean produces -1 for True in VB.
>However, .NET defines True as 1. VB passes CInt(True) as 1 to
>the .NET runtime and -1 within VB. Again, it's -1 within VB for
>compatibility with older versions.
>>
>The information comes from Francisco Balena's book. I don't have it
>in front of me, so I might be a bit hazy on the details. If you
>really want me to, I'll quote him verbatim when I get the chance.
>>
>Mark Lincoln
>>
>On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote: Quote:
>>Whoever told you that load of claptrap!!! It's information like that
>>gives
>>people the wrong idea of how something works.
>>>
>>BASIC (of which VB is a derivative) defines False as 0 (zero) but True is
>>the result of a bitwise NOT of False (i.e, True = Not False).
>>>
>>It is only when you attempt to cast a Boolean to another numeric type
>>that
>>you get a result of -1 for True which is demonstrated by:
>>>
>> Dim _boolean As Boolean = False
>>>
>> Dim _integer As Integer = Not Convert.ToInt32(_boolean)
>>>
>> Console.Writeline(_integer)
>>>
>>VB makes no conversions whatsover when you pass a Boolean to something
>>written in another .NET language.
>>>
>>If any conversion is required then then some form of 'middle-man' is
>>invoked
>>to carry out any such conversions.
>>>
>>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>>>
>>news:1192665237.811977.160320@v29g2000prd.google groups.com...
>>>
>>>
>>>
>VB uses -1 for True for compatibility with older versions of VB, but
>converts it to 1 when passing it to other .NET languages.
>>>
>Mark Lincoln
>>>
>On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
>wrote:
>>I also have a similar problem with a bit value of 1 (true) is shown
>>as -1
>>in
>>VS2005- Hide quoted text -
>>>
>>- Show quoted text -
>>
>>
>
| | | | re: Weird Math problem
I have to agree with Jack; Option Strict is the way to go. It can
keep you from making errors that result in posting to newsgroups for
answers. :)
On Oct 18, 1:32 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
Thanks all of you for helping me on this "weird math problem" thread.
>
1. It's stupid me. I put a wrong operator in a different sub and tried to
fix it in another sub! The formula is working properly.
>
2. Regarding the -1 as true, it has caused problem for me probably because I
did not set Strict = ON. When I did, the project gave me tons of errors that
I will have to fix line by line, so I don't know if it's a good thing to
switch it on.
>
Thanks again
>
Bill
>
"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>
news:1192723584.520582.20570@t8g2000prg.googlegrou ps.com...
>
>
> Quote:
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
> Quote:
The information comes from Francisco Balena's book. I don't have it
in front of me, so I might be a bit hazy on the details. If you
really want me to, I'll quote him verbatim when I get the chance.
> > Quote:
On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote: Quote:
Whoever told you that load of claptrap!!! It's information like that
gives
people the wrong idea of how something works.
> Quote: Quote:
BASIC (of which VB is a derivative) defines False as 0 (zero) but True is
the result of a bitwise NOT of False (i.e, True = Not False).
> Quote: Quote:
It is only when you attempt to cast a Boolean to another numeric type
that
you get a result of -1 for True which is demonstrated by:
> Quote: Quote:
Dim _boolean As Boolean = False
> Quote: Quote:
Dim _integer As Integer = Not Convert.ToInt32(_boolean)
> Quote: Quote:
Console.Writeline(_integer)
> Quote: Quote:
VB makes no conversions whatsover when you pass a Boolean to something
written in another .NET language.
> Quote: Quote:
If any conversion is required then then some form of 'middle-man' is
invoked
to carry out any such conversions.
> Quote: Quote:
"Mark Lincoln" <mlinc...@earthlink.netwrote in message
> Quote: Quote:
>news:1192665237.811977.160320@v29g2000prd.googleg roups.com...
> Quote: Quote:
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
> > Quote: Quote:
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote:
I also have a similar problem with a bit value of 1 (true) is shown
as -1
in
VS2005- Hide quoted text -
> Quote: Quote:
- Show quoted text -- Hide quoted text -
>
- Show quoted text -
| | | | re: Weird Math problem
Do I have to fix these errors 1 by 1 or can I have a global fix?
Thanks again
Bill
"Mark Lincoln" <mlincoln@earthlink.netwrote in message
news:1192733834.513213.307830@q3g2000prf.googlegro ups.com... Quote:
>I have to agree with Jack; Option Strict is the way to go. It can
keep you from making errors that result in posting to newsgroups for
answers. :)
>
On Oct 18, 1:32 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote: Quote:
>Thanks all of you for helping me on this "weird math problem" thread.
>>
>1. It's stupid me. I put a wrong operator in a different sub and tried to
>fix it in another sub! The formula is working properly.
>>
>2. Regarding the -1 as true, it has caused problem for me probably
>because I
>did not set Strict = ON. When I did, the project gave me tons of errors
>that
>I will have to fix line by line, so I don't know if it's a good thing to
>switch it on.
>>
>Thanks again
>>
>Bill
>>
>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>>
>news:1192723584.520582.20570@t8g2000prg.googlegro ups.com...
>>
>>
>> Quote:
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
>> Quote:
The information comes from Francisco Balena's book. I don't have it
in front of me, so I might be a bit hazy on the details. If you
really want me to, I'll quote him verbatim when I get the chance.
>> >> Quote:
On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote:
>Whoever told you that load of claptrap!!! It's information like that
>gives
>people the wrong idea of how something works.
>> Quote:
>BASIC (of which VB is a derivative) defines False as 0 (zero) but True
>is
>the result of a bitwise NOT of False (i.e, True = Not False).
>> Quote:
>It is only when you attempt to cast a Boolean to another numeric type
>that
>you get a result of -1 for True which is demonstrated by:
>> Quote:
> Dim _boolean As Boolean = False
>> Quote:
> Dim _integer As Integer = Not Convert.ToInt32(_boolean)
>> Quote:
> Console.Writeline(_integer)
>> Quote:
>VB makes no conversions whatsover when you pass a Boolean to something
>written in another .NET language.
>> Quote:
>If any conversion is required then then some form of 'middle-man' is
>invoked
>to carry out any such conversions.
>> Quote:
>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>> Quote:
>>news:1192665237.811977.160320@v29g2000prd.google groups.com...
>> Quote:
VB uses -1 for True for compatibility with older versions of VB, but
converts it to 1 when passing it to other .NET languages.
>> >> Quote:
On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
wrote:
>I also have a similar problem with a bit value of 1 (true) is shown
>as -1
>in
>VS2005- Hide quoted text -
>> Quote:
>- Show quoted text -- Hide quoted text -
>>
>- Show quoted text -
>
>
| | | | re: Weird Math problem
On Oct 18, 10:06 am, Mark Lincoln <mlinc...@earthlink.netwrote: Quote:
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
>
Yep - it was one of the stupid changes made in the Beta2 rollback
debacle. Before Beta2 VB.NET defined True = 1, but in a misguided
effort to maintain "compatability" they changed the behavior of
Boolean to the confusing mess it is today. The fact is, no one should
even care what the numeric value of a Boolean is - you should NEVER be
treating it as a number.
--
Tom Shelton | | | | re: Weird Math problem
Sometimes multiple errors can be fixed by changing the type of a
property, method argument or function return value. Other times each
one needs to be changed. Without knowing what the errors are I can't
tell.
On Thu, 18 Oct 2007 12:56:41 -0700, "Bill Nguyen"
<billn_nospam_please@jaco.comwrote: Quote:
>Do I have to fix these errors 1 by 1 or can I have a global fix?
>
>Thanks again
>
>Bill
>"Mark Lincoln" <mlincoln@earthlink.netwrote in message
>news:1192733834.513213.307830@q3g2000prf.googlegr oups.com... Quote:
>>I have to agree with Jack; Option Strict is the way to go. It can
>keep you from making errors that result in posting to newsgroups for
>answers. :)
>>
>On Oct 18, 1:32 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
>wrote: Quote:
>>Thanks all of you for helping me on this "weird math problem" thread.
>>>
>>1. It's stupid me. I put a wrong operator in a different sub and tried to
>>fix it in another sub! The formula is working properly.
>>>
>>2. Regarding the -1 as true, it has caused problem for me probably
>>because I
>>did not set Strict = ON. When I did, the project gave me tons of errors
>>that
>>I will have to fix line by line, so I don't know if it's a good thing to
>>switch it on.
>>>
>>Thanks again
>>>
>>Bill
>>>
>>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>>>
>>news:1192723584.520582.20570@t8g2000prg.googlegr oups.com...
>>>
>>>
>>>
>Yes, you're correct: Casting a Boolean produces -1 for True in VB.
>However, .NET defines True as 1. VB passes CInt(True) as 1 to
>the .NET runtime and -1 within VB. Again, it's -1 within VB for
>compatibility with older versions.
>>>
>The information comes from Francisco Balena's book. I don't have it
>in front of me, so I might be a bit hazy on the details. If you
>really want me to, I'll quote him verbatim when I get the chance.
>>>
>Mark Lincoln
>>>
>On Oct 18, 12:05 am, "Stephany Young" <noone@localhostwrote:
>>Whoever told you that load of claptrap!!! It's information like that
>>gives
>>people the wrong idea of how something works.
>>>
>>BASIC (of which VB is a derivative) defines False as 0 (zero) but True
>>is
>>the result of a bitwise NOT of False (i.e, True = Not False).
>>>
>>It is only when you attempt to cast a Boolean to another numeric type
>>that
>>you get a result of -1 for True which is demonstrated by:
>>>
>> Dim _boolean As Boolean = False
>>>
>> Dim _integer As Integer = Not Convert.ToInt32(_boolean)
>>>
>> Console.Writeline(_integer)
>>>
>>VB makes no conversions whatsover when you pass a Boolean to something
>>written in another .NET language.
>>>
>>If any conversion is required then then some form of 'middle-man' is
>>invoked
>>to carry out any such conversions.
>>>
>>"Mark Lincoln" <mlinc...@earthlink.netwrote in message
>>>
>>>news:1192665237.811977.160320@v29g2000prd.googl egroups.com...
>>>
>VB uses -1 for True for compatibility with older versions of VB, but
>converts it to 1 when passing it to other .NET languages.
>>>
>Mark Lincoln
>>>
>On Oct 17, 6:56 pm, "Bill Nguyen" <billn_nospam_ple...@jaco.com>
>wrote:
>>I also have a similar problem with a bit value of 1 (true) is shown
>>as -1
>>in
>>VS2005- Hide quoted text -
>>>
>>- Show quoted text -- Hide quoted text -
>>>
>>- Show quoted text -
>>
>>
>
| | | | re: Weird Math problem
Hear, hear! I can't remember where I first saw that sentiment, but
I've never counted on the numeric value of a Boolean ever since.
Mark Lincoln
On Oct 18, 4:25 pm, Tom Shelton <tom_shel...@comcast.netwrote: Quote:
On Oct 18, 10:06 am, Mark Lincoln <mlinc...@earthlink.netwrote:
> Quote:
Yes, you're correct: Casting a Boolean produces -1 for True in VB.
However, .NET defines True as 1. VB passes CInt(True) as 1 to
the .NET runtime and -1 within VB. Again, it's -1 within VB for
compatibility with older versions.
>
Yep - it was one of the stupid changes made in the Beta2 rollback
debacle. Before Beta2 VB.NET defined True = 1, but in a misguided
effort to maintain "compatability" they changed the behavior of
Boolean to the confusing mess it is today. The fact is, no one should
even care what the numeric value of a Boolean is - you should NEVER be
treating it as a number.
>
--
Tom Shelton
|  | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|