Weird Math problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Nguyen

    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.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")

    txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")

    txtFactorCost.T ext = 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_Tex tChanged(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles txtDiscount.Tex tChanged

    Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double

    If IsNumeric(txtDi scount.Text) = True Then

    mDisc = txtDiscount.Tex t

    Else

    mDisc = 0

    End If

    If IsNumeric(txtRa ckCost.Text) = True Then

    mRackc = txtRackCost.Tex t

    Else

    mRackc = 0

    End If

    If IsNumeric(txtJa coEC.Text) = True Then

    mJaEc = txtJacoEC.Text

    Else

    mJaEc = 0

    End If

    If IsNumeric(txtWf EC.Text) = True Then

    mWfEC = txtWfEC.Text

    Else

    mWfEC = 0

    End If

    If IsNumeric(txtFa ctorAdjust.Text ) = True Then

    mFactorAdj = txtFactorAdjust .Text

    Else

    mFactorAdj = 0

    End If

    txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")

    txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")

    txtFactorCost.T ext = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")



    End Sub


  • Tom Shelton

    #2
    Re: Weird Math problem

    On Oct 17, 3:55 pm, "Bill Nguyen" <billn_nospam_p le...@jaco.com>
    wrote:
    I'm running into a very weird problem regarding subtraction.
    >
    Subtraction behaves as if it's an addition in the below sub
    >
    txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
    >
    txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
    >
    txtFactorCost.T ext = 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_Tex tChanged(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles txtDiscount.Tex tChanged
    >
    Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
    >
    If IsNumeric(txtDi scount.Text) = True Then
    >
    mDisc = txtDiscount.Tex t
    >
    Else
    >
    mDisc = 0
    >
    End If
    >
    If IsNumeric(txtRa ckCost.Text) = True Then
    >
    mRackc = txtRackCost.Tex t
    >
    Else
    >
    mRackc = 0
    >
    End If
    >
    If IsNumeric(txtJa coEC.Text) = True Then
    >
    mJaEc = txtJacoEC.Text
    >
    Else
    >
    mJaEc = 0
    >
    End If
    >
    If IsNumeric(txtWf EC.Text) = True Then
    >
    mWfEC = txtWfEC.Text
    >
    Else
    >
    mWfEC = 0
    >
    End If
    >
    If IsNumeric(txtFa ctorAdjust.Text ) = True Then
    >
    mFactorAdj = txtFactorAdjust .Text
    >
    Else
    >
    mFactorAdj = 0
    >
    End If
    >
    txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
    >
    txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
    >
    txtFactorCost.T ext = 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

    Comment

    • Bill Nguyen

      #3
      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@co mcast.netwrote in message
      news:1192660685 .048358.162480@ t8g2000prg.goog legroups.com...
      On Oct 17, 3:55 pm, "Bill Nguyen" <billn_nospam_p le...@jaco.com>
      wrote:
      >I'm running into a very weird problem regarding subtraction.
      >>
      >Subtraction behaves as if it's an addition in the below sub
      >>
      >txtJacoCost.Te xt = Format(mRackc - (mDisc + mJaEc), "0.#####0")
      >>
      >txtWfCost.Te xt = 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_Tex tChanged(ByVal sender As System.Object, ByVal
      >e
      >As System.EventArg s) Handles txtDiscount.Tex tChanged
      >>
      >Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
      >>
      >If IsNumeric(txtDi scount.Text) = True Then
      >>
      >mDisc = txtDiscount.Tex t
      >>
      >Else
      >>
      >mDisc = 0
      >>
      >End If
      >>
      >If IsNumeric(txtRa ckCost.Text) = True Then
      >>
      >mRackc = txtRackCost.Tex t
      >>
      >Else
      >>
      >mRackc = 0
      >>
      >End If
      >>
      >If IsNumeric(txtJa coEC.Text) = True Then
      >>
      >mJaEc = txtJacoEC.Text
      >>
      >Else
      >>
      >mJaEc = 0
      >>
      >End If
      >>
      >If IsNumeric(txtWf EC.Text) = True Then
      >>
      >mWfEC = txtWfEC.Text
      >>
      >Else
      >>
      >mWfEC = 0
      >>
      >End If
      >>
      >If IsNumeric(txtFa ctorAdjust.Text ) = True Then
      >>
      >mFactorAdj = txtFactorAdjust .Text
      >>
      >Else
      >>
      >mFactorAdj = 0
      >>
      >End If
      >>
      >txtJacoCost.Te xt = Format(mRackc - (mDisc + mJaEc), "0.#####0")
      >>
      >txtWfCost.Te xt = 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
      >

      Comment

      • Armin Zingler

        #4
        Re: Weird Math problem

        "Bill Nguyen" <billn_nospam_p lease@jaco.coms chrieb
        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.
        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

        Comment

        • Mark Lincoln

          #5
          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_p le...@jaco.com>
          wrote:
          I also have a similar problem with a bit value of 1 (true) is shown as -1 in
          VS2005

          Comment

          • Mark Lincoln

            #6
            Re: Weird Math problem

            In these two expressions:

            txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
            txtFactorCost.T ext = 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_p le...@jaco.com>
            wrote:
            I'm running into a very weird problem regarding subtraction.
            >
            Subtraction behaves as if it's an addition in the below sub
            >
            txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
            >
            txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
            >
            txtFactorCost.T ext = 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_Tex tChanged(ByVal sender As System.Object, ByVal e
            As System.EventArg s) Handles txtDiscount.Tex tChanged
            >
            Dim mDisc, mRackc, mJaEc, mWfEC, mFactorAdj As Double
            >
            If IsNumeric(txtDi scount.Text) = True Then
            >
            mDisc = txtDiscount.Tex t
            >
            Else
            >
            mDisc = 0
            >
            End If
            >
            If IsNumeric(txtRa ckCost.Text) = True Then
            >
            mRackc = txtRackCost.Tex t
            >
            Else
            >
            mRackc = 0
            >
            End If
            >
            If IsNumeric(txtJa coEC.Text) = True Then
            >
            mJaEc = txtJacoEC.Text
            >
            Else
            >
            mJaEc = 0
            >
            End If
            >
            If IsNumeric(txtWf EC.Text) = True Then
            >
            mWfEC = txtWfEC.Text
            >
            Else
            >
            mWfEC = 0
            >
            End If
            >
            If IsNumeric(txtFa ctorAdjust.Text ) = True Then
            >
            mFactorAdj = txtFactorAdjust .Text
            >
            Else
            >
            mFactorAdj = 0
            >
            End If
            >
            txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
            >
            txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
            >
            txtFactorCost.T ext = Format(mRackc - (mDisc + mFactorAdj), "0.#####0")
            >
            End Sub

            Comment

            • Tom Shelton

              #7
              Re: Weird Math problem

              On Oct 17, 4:56 pm, "Bill Nguyen" <billn_nospam_p le...@jaco.com>
              wrote:
              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.Tex t = 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.T ext = 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

              Comment

              • Todd Carnes

                #8
                Re: Weird Math problem

                "Bill Nguyen" <billn_nospam_p lease@jaco.comw rote in message
                news:uMeHlhQEIH A.3332@TK2MSFTN GP04.phx.gbl...
                I'm running into a very weird problem regarding subtraction.
                >
                Subtraction behaves as if it's an addition in the below sub
                >
                >
                >
                txtJacoCost.Tex t = Format(mRackc - (mDisc + mJaEc), "0.#####0")
                >
                txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
                >
                txtFactorCost.T ext = 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

                Comment

                • Stephany Young

                  #9
                  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.Writeli ne(_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@earth link.netwrote in message
                  news:1192665237 .811977.160320@ v29g2000prd.goo glegroups.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_p le...@jaco.com>
                  wrote:
                  >I also have a similar problem with a bit value of 1 (true) is shown as -1
                  >in
                  >VS2005
                  >

                  Comment

                  • Mark Lincoln

                    #10
                    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@localhos twrote:
                    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.Writeli ne(_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...@earth link.netwrote in message
                    >
                    news:1192665237 .811977.160320@ v29g2000prd.goo glegroups.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_p le...@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 -

                    Comment

                    • Bill Nguyen

                      #11
                      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@earth link.netwrote in message
                      news:1192723584 .520582.20570@t 8g2000prg.googl egroups.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@localhos twrote:
                      >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.Writeli ne(_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...@earth link.netwrote in message
                      >>
                      >news:119266523 7.811977.160320 @v29g2000prd.go oglegroups.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_p le...@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 -
                      >
                      >

                      Comment

                      • Jack Jackson

                        #12
                        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_p lease@jaco.comw rote:
                        >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@earth link.netwrote in message
                        >news:119272358 4.520582.20570@ t8g2000prg.goog legroups.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
                        >compatibilit y 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@localhos twrote:
                        >>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.Writeli ne(_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...@earth link.netwrote in message
                        >>>
                        >>news:11926652 37.811977.16032 0@v29g2000prd.g ooglegroups.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_p le...@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 -
                        >>
                        >>
                        >

                        Comment

                        • Mark Lincoln

                          #13
                          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_p le...@jaco.com>
                          wrote:
                          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...@earth link.netwrote in message
                          >
                          news:1192723584 .520582.20570@t 8g2000prg.googl egroups.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@localhos twrote:
                          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.Writeli ne(_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...@earth link.netwrote in message
                          >
                          >news:119266523 7.811977.160320 @v29g2000prd.go oglegroups.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_p le...@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 -

                          Comment

                          • Bill Nguyen

                            #14
                            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@earth link.netwrote in message
                            news:1192733834 .513213.307830@ q3g2000prf.goog legroups.com...
                            >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_p le...@jaco.com>
                            wrote:
                            >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...@earth link.netwrote in message
                            >>
                            >news:119272358 4.520582.20570@ t8g2000prg.goog legroups.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@localhos twrote:
                            >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.Writeli ne(_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...@earth link.netwrote in message
                            >>
                            >>news:11926652 37.811977.16032 0@v29g2000prd.g ooglegroups.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_p le...@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 -
                            >
                            >

                            Comment

                            • Tom Shelton

                              #15
                              Re: Weird Math problem

                              On Oct 18, 10:06 am, Mark Lincoln <mlinc...@earth link.netwrote:
                              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 "compatabil ity" 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

                              Comment

                              Working...