Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminate multiple message boxes...

Status
Not open for further replies.

junebuggie

Programmer
Aug 23, 2003
4
0
0
US
I am attempting to create a vbscript which will enable user to right-click on files and copy them to another directory. The code below works, but a message box pops up for each file that is copied. How can I change it to only display one message box even if several files are copied?

Any help would be very appreciated!
--June

----------------------------------

set collArgs = WScript.Arguments
if collArgs(0) <> &quot;&quot; then
set fso = createobject(&quot;scripting.filesystemobject&quot;)
fso.CopyFile collArgs(0), &quot;c:\Temp\&quot;

msg = &quot;File Copied!&quot; & vbcrlf & vbcrlf
msg = msg & &quot;Don't forget to restart any&quot; & vbcrlf
msg = msg & &quot;currently running applications.&quot;
msgbox msg, VBInformation, &quot;Right Click Copier&quot;
end if

----------------------------------
 
Hello junebuggie,

Try something like:
Code:
'---
Set collArgs=WScript.Arugments
Set fso=WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
For Each Args In collArgs
	If Args<>&quot;&quot; Then fso.CopyFile Args, &quot;C:\temps\&quot;
Next
Set fso=Nothing
If collArgs.Count<>0 Then
	msg = &quot;File Copied!&quot; & vbcrlf & vbcrlf
	msg = msg & &quot;Don't forget to restart any&quot; & vbcrlf
	msg = msg & &quot;currently running applications.&quot;
Else
	msg = &quot;No file copied.&quot;
End If
msgbox msg, VBInformation, &quot;Right Click Copier&quot;
'-----

Even though individual non empty argument might still not be a valid file, plus other circumstances (?) which might defeat the copyfile, it would treat them as success. If you want to trap unexpected down, you have to do more validation. But, you get the general idea from the above.

regards - tsuji
 
Thanks for taking the time to respond tsuji, I appreciate it. But I'm still getting multiple boxes...

--June

 
junebuggie,

If that is the right-click on a block of file pre-selected with shift-up/down/left/right in explorer, then it proves that each file gets a separation attention from the action script. In that case, only one member exists in the collArgs, and the script gets multiple execution each for a file selection. Hence, msgbox comes _once_ on each execution. In that case, you can't do anything about it along the line of thinking you are working with.

-tsuji
 
Forget to add that the best way is to take out the msgbox. No need to echo anything back at all. Users know what they are doing.

-tsuji
 
Nope. Need a message box for what I'm doing with it.

How about if I have it open another vbscript that handles the message box but also kills any more than 1 instance of that vbscript. That way there is never more than one message box on the screen.

Impossible?

--June
 
junebuggie,

[1] There will be a timing problem : N instances are checking out and out-guessing N-1 instances. I do not think this operation deserves such.

[2] The whole idea is single batch & one message box, ie, populate collArgs with the batch job you want the script to perform. I would suggest a scheme. (I know you and other can always come up with an alternative.)

[2.1] Right-click menu adding two entries instead of one. One is to add file selected to the copy-queue. Second is the batch execution of the copy-queue then empty. This second entry is awkward though as it does not take any paramter (%1) with it. (You can alternatively make the vbs with a shortcut sent to the desktop. In this way, you spare the second awkward right-click menu entry.)

[2.2] The adding is just handled by appending the file with full path to a fixed text file (if not existing, creates it.)

[2.3] The executing is the vbs
-parsing the designated text file (copy queue) for files to copy;
-copying them;
-echo the message;
-delete the text (copy-queue) file.

[3] The block of file being selected will be right-clicked to all be sent to copy-queue.

[4] At a suitable time, users then can decide that it is time to do the batch copy job. Right click on any file or making a shortcut on the desktop & double-click on it.

This is the cheapest rational scheme I can think of.

-tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top