2012-08-30 41 views
79

我正在使用While ... Wend循環的VBA。分手了...... Wend循環

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 

我不想使用條件等`雖然計數< = 10 ... WEND

回答

141

While/Wend只能與一個或GOTO通過從外部塊退出(Exit sub過早退出/ function/another exitable loop

更改爲Do loop intead;

Do While True 
    count = count + 1 

    If count = 10 Then 
     Exit Do 
    End If 
Loop 

(或用於與一組循環遞增控制變量)

for count = 1 to 10 
    msgbox count 
next