试试Local $vCZ = 55
Local $aNum[6] = [23, 34, 66, 80, 88, 95]
Local $rt = _GetApproachesNum($vCZ, $aNum)
MsgBox(0, @error, $rt)
Func _GetApproachesNum($vCZ, $aNum)
If Not IsArray($aNum) Or UBound($aNum, 0) > 1 Then Return SetError(1, 0, 0)
Local $i, $vC, $iMix, $vC2, $iMix2, $vNeed, $vNeed2
For $i = 0 To UBound($aNum) - 1
$vC = $aNum[$i] - $vCZ
$vC2 = $aNum[$i] - $vCZ
If $vC2 < 0 And (Not $iMix2 Or $vC2 > $iMix2) Then Dim $vNeed2 = $aNum[$i], $iMix2 = $vC2
If $vC > 0 And (Not $iMix Or $vC < $iMix) Then Dim $vNeed = $aNum[$i], $iMix = $vC
Next
If Not $vNeed Then Return SetError(2, 0, 0)
Return $vNeed2 & ' > [' & $vCZ & '] < ' & $vNeed
EndFunc ;==>_GetApproachesNum
|