# Lowest value just above zero and highest value just below zero.

### Question

• The below code provide the lowest value of PPPP(J,I) (Just above zero) and the corresponding values of Mxxx(J,I) & Myyy(I,J) as well as the Highest value of PPPP(i,j) (just below zero) and the corresponding values of Mxxx(l,j) & Myyy(i,j)

But the code provide zero values for all values and I dont know the mistake even the values of PPPP(I,J) and Mxxx(I,J) and Myyy(I,J) are non zero within the range

Dim PlusValue1(17) As Double

Dim MinusValue1(17) As Double
Dim MxPlusValue1(17) As Double
Dim MxMinusValue1(17) As Double
Dim MyPlusValue1(17) As Double
Dim MyMinusValue1(17) As Double
For K = 0 To 17
PlusValue1(K) = 0.0
PlusValue2(K) = 0.0
MinusValue1(K) = 0.0
MinusValue2(K) = 0.0
Next
For J = 0 To 17
For I = 21 To 27
If PPPP(J, I) > 0.0 Then
If PlusValue1(J) > PPPP(J, I) Then
PlusValue1(J) = PPPP(J, I)
MxPlusValue1(J) = Mxxx(J, I)
MyPlusValue1(J) = Myyy(J, I)
End If
ElseIf PPPP(J, I) < 0 Then
If MinusValue1(J) < PPPP(J, I) Then
MinusValue1(J) = PPPP(J, I)
MxMinusValue1(J) = Mxxx(J, I)
MyMinusValue1(J) = Myyy(J, I)
End If
End If
Next
Next

Kind Regards,

Hany Metry

Hany Metry

Saturday, April 16, 2016 8:19 AM

• The correct code as follow:

Dim PlusValue1(17) As Double

Dim PlusValue2(17) As Double
Dim MinusValue1(17) As Double
Dim MinusValue2(17) As Double
Dim MxPlusValue1(17) As Double
Dim MxPlusValue2(17) As Double
Dim MxMinusValue1(17) As Double
Dim MxMinusValue2(17) As Double
Dim MyPlusValue1(17) As Double
Dim MyPlusValue2(17) As Double
Dim MyMinusValue1(17) As Double
Dim MyMinusValue2(17) As Double
For K = 0 To 17
PlusValue1(K) = 100000000000000000
PlusValue2(K) = 100000000000000000
MinusValue1(K) = -100000000000000000
MinusValue2(K) = -100000000000000000
Next
For J = 0 To 17
For I = 21 To 27
If PPPP(J, I) > 0.0 Then
If PlusValue1(J) > PPPP(J, I) Then
PlusValue1(J) = PPPP(J, I)
MxPlusValue1(J) = Mxxx(J, I)
MyPlusValue1(J) = Myyy(J, I)
End If
ElseIf PPPP(J, I) < 0 Then
If MinusValue1(J) < PPPP(J, I) Then
MinusValue1(J) = PPPP(J, I)
MxMinusValue1(J) = Mxxx(J, I)
MyMinusValue1(J) = Myyy(J, I)
End If
End If
Next
Next
For J = 1 To 17
For I = 73 To 79
If PPPP(J, I) > 0.0 Then
If PlusValue2(J) > PPPP(J, I) Then
PlusValue2(J) = PPPP(J, I)
MxPlusValue2(J) = Mxxx(J, I)
MyPlusValue2(J) = Myyy(J, I)
End If
ElseIf PPPP(J, I) < 0 Then
If MinusValue2(J) < PPPP(J, I) Then
MinusValue2(J) = PPPP(J, I)
MxMinusValue2(J) = Mxxx(J, I)
MyMinusValue2(J) = Myyy(J, I)
End If
End If
Next
Next

Hany Metry

• Marked as answer by Saturday, April 16, 2016 9:58 AM
Saturday, April 16, 2016 9:58 AM

### All replies

• The code is wrong and I dont know the correct.

Hany Metry

Saturday, April 16, 2016 9:48 AM
• The correct code as follow:

Dim PlusValue1(17) As Double

Dim PlusValue2(17) As Double
Dim MinusValue1(17) As Double
Dim MinusValue2(17) As Double
Dim MxPlusValue1(17) As Double
Dim MxPlusValue2(17) As Double
Dim MxMinusValue1(17) As Double
Dim MxMinusValue2(17) As Double
Dim MyPlusValue1(17) As Double
Dim MyPlusValue2(17) As Double
Dim MyMinusValue1(17) As Double
Dim MyMinusValue2(17) As Double
For K = 0 To 17
PlusValue1(K) = 100000000000000000
PlusValue2(K) = 100000000000000000
MinusValue1(K) = -100000000000000000
MinusValue2(K) = -100000000000000000
Next
For J = 0 To 17
For I = 21 To 27
If PPPP(J, I) > 0.0 Then
If PlusValue1(J) > PPPP(J, I) Then
PlusValue1(J) = PPPP(J, I)
MxPlusValue1(J) = Mxxx(J, I)
MyPlusValue1(J) = Myyy(J, I)
End If
ElseIf PPPP(J, I) < 0 Then
If MinusValue1(J) < PPPP(J, I) Then
MinusValue1(J) = PPPP(J, I)
MxMinusValue1(J) = Mxxx(J, I)
MyMinusValue1(J) = Myyy(J, I)
End If
End If
Next
Next
For J = 1 To 17
For I = 73 To 79
If PPPP(J, I) > 0.0 Then
If PlusValue2(J) > PPPP(J, I) Then
PlusValue2(J) = PPPP(J, I)
MxPlusValue2(J) = Mxxx(J, I)
MyPlusValue2(J) = Myyy(J, I)
End If
ElseIf PPPP(J, I) < 0 Then
If MinusValue2(J) < PPPP(J, I) Then
MinusValue2(J) = PPPP(J, I)
MxMinusValue2(J) = Mxxx(J, I)
MyMinusValue2(J) = Myyy(J, I)
End If
End If
Next
Next

Hany Metry

• Marked as answer by Saturday, April 16, 2016 9:58 AM
Saturday, April 16, 2016 9:58 AM