Bharti Pandita
Bharti Pandita

Reputation: 291

Is there any way to compare the absolute values obtained from a field?

Is there any way to compare the absolute values obtained from a field?

Example.

Mitigated Risk = 24.50 Business Risk = -10.00

( it should not take into account -ve sign)

I tried this, But it is not working

Imports System.Math

If (((Math.Abs(Me.txt_mitigated_risk.Text)) > (Math.Abs(Me.txt_business_revenue_risk.Text))) Then

    Me.lbl_conf_message.Text = "Mitigated Risk value cannot be greater than Project Value."              

Upvotes: 0

Views: 174

Answers (1)

Styxxy
Styxxy

Reputation: 7517

Math.Abs() requires a numeric parameter, while you are providing Strings. First convert the text of your textbox to the appropriate (numeric) type (it can be Decimal, Double, Int16, Int32, Int64, SByte or Single).

Dim mitigatedRisk As Decimal
Dim businessRisk As Decimal

If Decimal.TryParse(Me.txt_mitigated_risk.Text, mitigatedRisk) AndAlso Decimal.TryParse(Me.txt_business_revenue_risk.Text, businessRisk) Then
    If Math.Abs(mitigatedRisk) > Math.Abs(businessRisk) Then
        Me.lbl_conf_message.Text = "Mitigated Risk value cannot be greater than Project Value."
    End If
Else
    ' The values in the textboxes are not valid decimals
End If

Upvotes: 1

Related Questions