Solved

Exit Loop after User Input

Posted on 2016-09-27
4
29 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 45

Expert Comment

by:Martin Liss
Comment Utility
Add Exit Do after Wscript.quit.
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
Hi Martin,

It works. thanks for the help.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now