2012-08-30 12 views
79

Używam pętli Wend ... VBA.Breakout of a While ... Wend loop

Dim count as Integer 

While True 
    count=count+1 

    If count = 10 Then 
     ''What should be the statement to break the While...Wend loop? 
     ''Break or Exit While not working 
    EndIf 
Wend 

Nie chcę używać warunku jak `Podczas liczyć < = 10 ... WEND

Odpowiedz

141

While/Wend można opuścić tylko przedwcześnie z GOTO lub wychodzenia z zewnętrznej bloku (Exit sub/function/another exitable loop)

Zmiana na intruz pętli Do;

Do While True 
    count = count + 1 

    If count = 10 Then 
     Exit Do 
    End If 
Loop 

(albo dla pętli z zestawem inkrementacja zmiennej sterowania)

for count = 1 to 10 
    msgbox count 
next