Share via

How Do I make a Positive Number Into A Negative Number

Gary Simpson 471 Reputation points
2023-06-17T15:49:09.1333333+00:00

Hi Good People

On My Form I have Three Textboxes ( TxtTotalEarned, TxtVHMoneyTotalDed, TxtSubTotal, )

When The Form Loads And I Select A Name from a Drop Down Box Then my Textbox TxtTotalEarned, is loaded with currency data. Also The Textbox TxtVHMoneyTotalDed is also Loaded with Currency Data.

It is here where I want to change the Data in the TxtVHMoneyTotalDed to a negative Currency Data.

At the Moment My Data Shows £40.00. where I want it to show -£40.00.

then show the result in the textbox ,TxtSubTotal.

Is there a way this can be done. I have done some research and tried different code, (WinForms VB)

Kind Regards

Gary

    If GetDec(TxtVHMoneyTotal.Text) > "0.00" Then
        TxtVHMoneyTotalDed.Show()
        LbVHMoneyTotalCaption.Show()
        TxtSubTotal.Show()
        LbSubTotal.Show()

        Dim Sum1 As Decimal = GetDec(TxtTotalEarned.Text)
        Dim Sum2 As Decimal = GetDec(TxtVHMoneyTotal.Text) * -1

        TxtSubTotal.Text = FormatCurrency(Sum1 - Sum2)


    End If


End Sub
Developer technologies | VB

Answer accepted by question author
  1. Jiachen Li-MSFT 34,241 Reputation points Microsoft External Staff
    2023-06-21T07:49:30.7566667+00:00

    Hi @Gary Simpson ,

    Please check if the following code helps.

            Dim value As Decimal
            Decimal.TryParse(TxtVHMoneyTotal.Text.Replace("£", ""), value)
            TxtVHMoneyTotalDed.Text = String.Format("-£{0:N2}", Math.Abs(value))
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.