• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

How can I run an exe script file multiple times in vb6?

Hi, I use some scripts to automate the editing of my database (the scripts are .exe files). Whenever I add an item to my database, I put the item into the system, (its a database file so I use excel to edit the database) but when I enter the info in, to save time I just the item name.  Then every week or so I edit all the recent items I added (theres like 20 fields which have to be modified per entry). So I made a script which automates this process. My question is I was wondering is there an easy way to specify how many times an exe file with a time delay between each time it runs.

Since I add anywhere from 0-200 items to the database every week, each week the number of times the script is ran changes.  

I wish there was an option to say run this script 148 times and it will loop itself 148 times. Currently I edit the script and use Copy and paste then save the script file and compile it to an exe file and run it. The only times I have problems are when I lose count  if I accidentally paste an extra script in it will mess up a record (if I need it to revise 50 items and its pasted 51 times, the 51st item will be messed up). And if I miss a paste and paste 49 times lets say, then I need to edit the script to only run once, save and run it.

I know how to use visual basic 6 a little, so it would be cool if I can load a script in vb6 and type in a value- and have it run that script that many times. For example I can press a button and browse to the directory on my computer c:/scripts and select the script I need, then in another box type in 50 for example, and press ok and have that script run 50 times.

A problem is that if it ran like that, a timer would need to be involved because if I said to run a script 50 times, all the scripts may load at once. It would be important that the second script launches after the first script has ran and the process has been completed.

I made a sample of what the program looks like, see it below

Does anyone have any advice on the coding? It looks like it should be easy, but I havent used VB in an advanced way like this since high school a few years ago. Any help would be appreciated.

2 Solutions
It might be overkill a little, but I have just written a class (will nicked bits off the web and stuck it together) that will do the job.

Paste the code snippet  into a new class and call it CPROC

Then this code would work

Sub Form_Load
  LaunchApp "c:\windows\notepad.exe", 5
End Sub

Sub LaunchApp (ByVal path as String, optional byval numtimes as Integer)
  Dim MyObj as CPROC, n as Integer
  Set MyObj=New CPROC
  For n = 1 To numtimes
    MyObj.Application = path
    MyObj.Initialise IDLE_PRIORITY_CLASS, False, SW_MAXIMIZE, True  
  Next n
  Set MyObj=Nothing
End Sub

as an example
  SW_SHOWDEFAULT = 10    ' Sets the show state based on the SW_ value specified in the STARTUPINFO
  SW_SHOWMAXIMIZED = 3   ' Activates the window and displays it as a maximized window.
  SW_SHOWMINIMIZED = 2   ' Activates the window and displays it as a minimized window.
' Windows 2000/XP: Minimizes a window, even if the thread that owns
' the window is not responding. This flag should only be used when
' minimizing windows from a different thread.
' Hides the window and activates another window.
  SW_HIDE = 0
' Maximizes the specified window.
' Minimizes the specified window and activates the next top-level window in the Z order.
' Activates and displays the window. If the window is minimized or maximized,
' the system restores it to its original size and position.
' An application should specify this flag when restoring a minimized window.
' Activates the window and displays it in its current size and position.
  SW_SHOW = 5
' Displays the window as a minimized window. This value is
' similar to SW_SHOWMINIMIZED, except the window is not activated.
' Displays the window in its current size and position. This value
' is similar to SW_SHOW, except the window is not activated.
' Displays a window in its most recent size and position.
' This value is similar to SW_SHOWNORMAL, except the window is not actived.
' Activates and displays a window. If the window is minimized or maximized,
' the system restores it to its original size and position. An application should
' specify this flag when displaying the window for the first time.
End Enum

Open in new window

check this out.


just change the filename on Form_Load to your filename and add a loop on Command1_Click on how many times you want the exe to execute. you will not have problems with the timing here because it will wait for the exe to finish processing (end) before calling the next exe.
mds332200Author Commented:
Thanks for the help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now