Solved

Exit Loop after User Input

Posted on 2016-09-27
4
56 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 47

Expert Comment

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

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 47

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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