Consulting

Results 1 to 6 of 6

Thread: Solved: do...loop statement

  1. #1

    Solved: do...loop statement

    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"

    [VBA]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
    [/VBA]

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    7,275
    Location
    Not really tested

    [VBA]
    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
    [/VBA]

    Paul

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,247
    Location
    Blimey Paul, While ... Wend, not seen anyone actually use one of those
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    3,862
    Location
    Yes Wend is one of those words you think doesn't happen all that often.
    Remember To Do the Following....
    Use tags when posting code to the thread,
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  6. #6
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    7,275
    Location
    Well, back in the old days .....


    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •