Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Exit Loop after User Input

Posted on 2016-09-27
4
Medium Priority
?
74 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 49

Expert Comment

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

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Integration Management Part 2

971 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