Solved

Exit Loop after User Input

Posted on 2016-09-27
4
52 Views
Last Modified: 2016-09-28
Hi Experts,
Im trying to loop the user input until they gave me a valid folder path or choose to exit the program by chosing "No" option. However, it keeps looping eventhough i have insert the correct path. The "yes" and 'no" option works. How do i exit the loop and move on to the next code. Appreciate your time on reading my question. Thanks in advance. Any help is welcome.

'Set Folders to Compare
folderLoop = True
Do While folderLoop

strFolder1 = InputBox("Enter Source Folder 1 Path :")
strFolder2 = InputBox("Enter Source Folder 2 Path :")


'Check if Folders Exist
If Not (objFSO.FolderExists(strFolder1 & "\") and objFSO.FolderExists(strFolder2 & "\")) Then
  MsgBox("Failed")

reply = msgbox("Enter folder again?", vbYesNo)
   if reply = vbYes Then
   folderLoop = True
   end if

   if reply = vbNo Then
   folderLoop = False
      Wscript.Echo "Quitting Script!"
    Wscript.quit
   end if

End if

Loop

On Error Resume Next

'rest of the code
0
Comment
Question by:Adrian Raj
  • 3
4 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41818222
Add Exit Do after Wscript.quit.
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41818261
Or perhaps add lines 24 and 25.
'Set Folders to Compare
folderLoop = True
Do While folderLoop

strFolder1 = InputBox("Enter Source Folder 1 Path :")
strFolder2 = InputBox("Enter Source Folder 2 Path :")


'Check if Folders Exist
If Not (objFSO.FolderExists(strFolder1 & "\") and objFSO.FolderExists(strFolder2 & "\")) Then
  MsgBox("Failed")

reply = msgbox("Enter folder again?", vbYesNo)
   if reply = vbYes Then
   folderLoop = True
   end if

   if reply = vbNo Then
   folderLoop = False
      Wscript.Echo "Quitting Script!"
    Wscript.quit
   end if

Else
    folderLoop = False
End if

Loop

On Error Resume Next

'rest of the code

Open in new window

0
 

Author Closing Comment

by:Adrian Raj
ID: 41819190
Hi Martin,

It works. thanks for the help.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41820112
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question