954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Shell Function

Hi There,
i am using the shell function to execute a program that will zip 10 big data files. so my code is something like this:

for n = 1 to 10
t=shell(zip data(n)) 'not the real code
' somewhere here, i need a code to test if the data(n) is already finished before going to the next loop

next n

can somebody show me a code to do this?. thanks in advance.

newvbguy

NewVBguy
Junior Poster in Training
71 posts since Mar 2005
Reputation Points: 13
Solved Threads: 3
 

I'm guessing zip is the external EXE file, and data(n) is the filename?
There are a ton of different method's to handle this kind of ideal. The easiest way to go about this, is to use a VbScript. There are others, with shellexecute, waitforsingleobject API's and others... but the easiest (and probably most effecient based on code readability) is as such:

dim WSH
set WSH = createobject("WScript.Shell")
WSH.Run "zip " & data(n), 0, 1


The WSH.Run method executes an external program, the first integer value, defines the visibility state of the window... 0 is hidden, so it doesn't show the DOS window, or ZIP program window to the screen. The trailing integer, set to 1, tells WSH's Run Method To Block (not return to program code execution) UNTIL the command or program being run by WSH's run method returns. It doesn't matter how it returns, either. Error, Success, or something in between. As long as it returns (the program finish's running), then it will move on. Not until then, however. Let me know how it turns for you.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

I'm guessing zip is the external EXE file, and data(n) is the filename? There are a ton of different method's to handle this kind of ideal. The easiest way to go about this, is to use a VbScript. There are others, with shellexecute, waitforsingleobject API's and others... but the easiest (and probably most effecient based on code readability) is as such:

dim WSH
set WSH = createobject("WScript.Shell")
WSH.Run "zip " & data(n), 0, 1

The WSH.Run method executes an external program, the first integer value, defines the visibility state of the window... 0 is hidden, so it doesn't show the DOS window, or ZIP program window to the screen. The trailing integer, set to 1, tells WSH's Run Method To Block (not return to program code execution) UNTIL the command or program being run by WSH's run method returns. It doesn't matter how it returns, either. Error, Success, or something in between. As long as it returns (the program finish's running), then it will move on. Not until then, however. Let me know how it turns for you.

It make sense. For sure I will let you know if I have the chance to try. Thanks again.

Newvbguy

NewVBguy
Junior Poster in Training
71 posts since Mar 2005
Reputation Points: 13
Solved Threads: 3
 

It make sense. For sure I will let you know if I have the chance to try. Thanks again.

Newvbguy

Hi Comatose,
yeah it works ok. thanks

Newvbguy

NewVBguy
Junior Poster in Training
71 posts since Mar 2005
Reputation Points: 13
Solved Threads: 3
 

I'm guessing zip is the external EXE file, and data(n) is the filename? There are a ton of different method's to handle this kind of ideal. The easiest way to go about this, is to use a VbScript. There are others, with shellexecute, waitforsingleobject API's and others... but the easiest (and probably most effecient based on code readability) is as such:

dim WSH
set WSH = createobject("WScript.Shell")
WSH.Run "zip " & data(n), 0, 1

The WSH.Run method executes an external program, the first integer value, defines the visibility state of the window... 0 is hidden, so it doesn't show the DOS window, or ZIP program window to the screen. The trailing integer, set to 1, tells WSH's Run Method To Block (not return to program code execution) UNTIL the command or program being run by WSH's run method returns. It doesn't matter how it returns, either. Error, Success, or something in between. As long as it returns (the program finish's running), then it will move on. Not until then, however. Let me know how it turns for you.

Thank you! Six google searches over six months and this finally does exactly what I want. Should add a set WSH = nothing at the end.
Thank You again.

RodneyKocot
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You