PDA

View Full Version : Solved: do...loop statement



av8tordude
04-21-2011, 05:08 PM
Can some help me with a do...loop statement. The code below checks to see if internet connection is available. if not, msgbox is display asking if the user wants to try again. if the user clicks yes, it should check for internet connection. if the user clicks No, then the caption changes to "Close"

If IsConnected = False Then
If MsgBox("Unable to detect an internet connection. Would you like to try again.", vbExclamation + vbYesNo, "PerDiem Traveler") = vbNo Then
cmdBuy.Caption = "Close"
Exit Sub
'else
'Check internet connection again
End If

Paul_Hossler
04-21-2011, 07:57 PM
Not really tested


Option Explicit
Sub test()
Dim bNotConnected As Boolean
bNotConnected = True

While bNotConnected
If Not IsConnected Then
If MsgBox("Unable to detect an internet connection. Would you like to try again.", _
vbExclamation + vbYesNo, "PerDiem Traveler") = vbNo Then
cmdBuy.Caption = "Close"
bNotConnected = False
Else
DoEvents
End If
Else
bNotConnected = False
End If
Wend

End Sub


Paul

Bob Phillips
04-22-2011, 03:30 AM
Blimey Paul, While ... Wend, not seen anyone actually use one of those :)

Aussiebear
04-22-2011, 03:55 AM
Yes Wend is one of those words you think doesn't happen all that often.

BrianMH
04-22-2011, 05:38 AM
I use while..when all the time. Is the a benefit to using Do..Loop instead? Just for my own understanding.

Edit:

Never mind I just googled it. Do..Loop has better structure and more function and while..wend is only included for backward compatibility. Now just to change a habit of 4 years. This just reiterates my signature.

Paul_Hossler
04-22-2011, 07:34 AM
Well, back in the old days .....:old:


A Do While / Loop and a While / Wend construct seem to get you to the same place.

A Do / Loop of course would execute the block at least once (similar to a Repeat/Until in other languages)

Just habit

Paul