本帖最后由 happytc 于 2011-6-22 08:36 编辑
回复 3# kk_lee69
加个判断就可以了,其实这种最好用While..Wend或Do..Untile循环
因为For循环只是在第一次循环时读“步进值”和“ 停止值”,若你硬是要用For循环,也可以:
#include <Array.au3>
Local $Array[5][2] = [["張三", 85], ["李四", 51], ["王五", 65], ["劉六", 34], ["林七", 98]]
Local $ArrSize
_ArrayDisplay($Array)
$ArrSize = UBound($Array) - 1
For $i = 0 To UBound($Array) - 1
If $i > $ArrSize Then ExitLoop
If $Array[$i][1] < 60 Then
_Array2DDelete($Array, $i)
$ArrSize -= 1
EndIf
Next
_ArrayDisplay($Array)
;----------------------------------------------------------------------------------------------------------------------
; Fuction _Array2DDelete(ByRef $ARRAY, $iDEL, $bCOL=False)
;
; Description Delete one row on a given index in an 1D/2D -Array
;
; Parameter $ARRAY the array, where one row will deleted
; $iDEL Row(Column)-Index to delete
; $bCOL If True, delete column instead of row (default False)
;
; Return Succes 0 ByRef $ARRAY
; Failure 1 set @error = 1; given array are not array
; set @error = 2; want delete column, but not 2D-array
; set @error = 3; index is out of range
;
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DDelete(ByRef $ARRAY, $iDEL, $bCOL=False)
If ( Not IsArray($ARRAY) ) Then Return SetError(1,0,1)
Local $UBound2nd = UBound($ARRAY,2), $k
If $bCOL Then
If $UBound2nd = 0 Then Return SetError(2,0,1)
If ( $iDEL < 0 ) Or ( $iDEL > $UBound2nd-1 ) Then Return SetError(3,0,1)
Else
If ( $iDEL < 0 ) Or ( $iDEL > UBound($ARRAY)-1 ) Then Return SetError(3,0,1)
EndIf
If $UBound2nd = 0 Then
Local $arTmp[UBound($ARRAY)-1]
$k = 0
For $i = 0 To UBound($ARRAY)-1
If $i <> $iDEL Then
$arTmp[$k] = $ARRAY[$i]
$k += 1
EndIf
Next
Else
If $bCOL Then
Local $arTmp[UBound($ARRAY)][$UBound2nd-1]
For $i = 0 To UBound($ARRAY)-1
$k = 0
For $l = 0 To $UBound2nd-1
If $l <> $iDEL Then
$arTmp[$i][$k] = $ARRAY[$i][$l]
$k += 1
EndIf
Next
Next
Else
Local $arTmp[UBound($ARRAY)-1][$UBound2nd]
$k = 0
For $i = 0 To UBound($ARRAY)-1
If $i <> $iDEL Then
For $l = 0 To $UBound2nd-1
$arTmp[$k][$l] = $ARRAY[$i][$l]
Next
$k += 1
EndIf
Next
EndIf
EndIf
$ARRAY = $arTmp
Return 0
EndFunc ;==>_Array2DDelete
用_ArrayDelete()为
#include <Array.au3>
Local $Array[5][2] = [["張三", 85], ["李四", 51], ["王五", 65], ["劉六", 34], ["林七", 98]]
Local $ArrSize
_ArrayDisplay($Array)
$ArrSize = UBound($Array) - 1
For $i = 0 To UBound($Array) - 1
If $i > $ArrSize Then ExitLoop
If $Array[$i][1] < 60 Then
_ArrayDelete($Array, $i)
$ArrSize -= 1
EndIf
Next
_ArrayDisplay($Array)
|