VBA While Wend循環


While...Wend循環中,如果條件為True,則會執行所有語句,直到遇到Wend關鍵字。

如果條件為false,則退出循環,然后控件跳轉到Wend關鍵字后面的下一個語句。

語法

以下是VBA中While..Wend循環的語法。

While condition(s)
   [statements 1]
   [statements 2]
   ...
   [statements n]
Wend

流程圖

示例

參考以下示例代碼的實現 -

Private Sub Constant_demo_Click()
   Dim Counter :  Counter = 10   

   While Counter < 15     ' Test value of Counter.
      Counter = Counter + 1   ' Increment Counter.
      msgbox "The Current Value of the Counter is : " & Counter
   Wend   ' While loop exits if Counter Value becomes 15.
End Sub

當上面的代碼被執行時,它會在消息框中打印以下內容。

The Current Value of the Counter is : 11 

The Current Value of the Counter is : 12 

The Current Value of the Counter is : 13 

The Current Value of the Counter is : 14 

The Current Value of the Counter is : 15

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM