Solved

Exit Loop after User Input

Posted on 2016-09-27
4
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 48

Expert Comment

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

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 48

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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