i want to create a system that will trigger alert based on few condition, my condition is:

the alert will trigger if there is a negative value for 2 consecutive years.

example:
1)negative amount for 2005
2)negative amount for 2006

here is the code that i have for now
and the result only can trigger alert for one year only.... .

<code>
Protected Sub GridViewYCR_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewYCR.RowDataBound
' Check if row is data row
If e.Row.RowType = DataControlRowType.DataRow Then

Dim CellValue As Decimal = Convert.ToDecimal(e.Row.Cells(2).Text)
Dim CellValue2 As String = Convert.ToString(e.Row.Cells(3).Text) = "2005"
Dim CellValue3 As String = Convert.ToString(e.Row.Cells(3).Text) = "2006"

If ((CellValue2 AndAlso (CellValue < 0.0))) Then
e.Row.Cells(2).BackColor = Drawing.Color.Red
Else
e.Row.Cells(2).BackColor = Drawing.Color.Empty
End If

End If
End Sub
</code>

Recommended Answers

All 6 Replies

Member Avatar for P0lT10n

AndAlso ?? never heard that... i only know And...

@P0IT10n: The And logical operator evaluates all the compares, then 'Ands' the results. If only one of them is False, then the And operator returns false.
The AndAlso operator evaluates the first. If the result is true, then compares the second and so on. This way, the very first false, cuts the evalutaion of the others compares saving CPU cicles.

AndAlso ?? never heard that... i only know And...

it is the same:

and=andalso

@zulhimi89:
Lets A = 1, B = 2, C = 3, D = 3
If A=B And C=D Then

First (Evaluate A=B) to False
Then (Evaluate C=D) to True
Then (evaluate False And True) to False
Return False

If A = B AndAlso C = D Then

First (evaluate A=B) to False
Return False

If C = D AndAlso A = B Then
First (evaluate C=D) to True
Then (evaluate A=B) to False
Return False

Example:

Dim A As Object = Nothing
If ( Not A Is Nothing ) And A.tostring = "3"

Will fail to evaluate and launch an exception because is trying to evaluate A.Tostring and the object is not instantiated while

If ( Not A Is Nothing ) AndAlso A.tostring = "3"

will not fail because (Not A Is Nothing) is false and does not continues to evaluate the rest of conditions.

Hope this helps

About your original question, you are comparing two cells of the same row, so there is info only about one year (2005 or 2006) in the e.Row.Cells(3).Text.

On CellValue2 and CellValue3 you will have the text "True" on one of them, and "False" on the other.

Maybe is easier to:

Dim CellValue2 As Boolean = e.Row.Cells(3).Text) = "2005"
Dim CellValue3 As Boolean = Not Cellvalue2

in order to use it in

If CellValue2 AndAlso CellValue < 0.0 Then

Where do you have the info for the two consecutive years?

thanks to all,

@lolafuertes,
if you don't mind, can you explain more detail about your answer?
i can't understand it. I'm sorry, I'm still new in using vb.net.

thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.