Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch File (XL97;SR2)

    I recently changed my OS from W95 to W2K and have found an issue with running the following code:

    Sub Start()
    MyApp = Shell("E:Comb.Bat",1)
    AppActivate MyApp Code errors here!
    SendKeys "%{F4}", True
    End Sub

    Any advice would be appreciated.

    Thanks,
    John

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Specifically, what is the error?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Kevin,

    The error message reads as follows: "Invalid procedure call or argument".

    John

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    What's the Task ID returned from Shell?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Kevin,

    I'm not quite sure what you mean by Task ID being returned from Shell. If I F8 through the code MyApp = 1444

    John

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    The task id is what Shell returns to your MyApp var; and what you pass to AppActivate using the same var.

    You might try passing the window Title instead just to see what happens (even though the task id technique you are using should work).


    If you step through the code, do you get the error? If no, consider this too: (from the help):

    "The Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed."

    It could be that AppActivate is being executed before the Shell statement returns. Therefore MyApp is null -- no such task id.

    You may have to Sleep after the Shell. This is untested psuedo code:

    MyApp = Shell ("e:comb.bat",1)
    do

    loop until MyApp not Null (<> 0?)
    AppActivate MyApp
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Kevin,

    I'm still encountering issues...the command box seems to be hung up. Your suggestion to loop until MyApp not null did not work. However I could see the command box. Do you have any other suggestions? Other than trying to bring back DOS...

    John

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Whatever you do, don't even try to bring back DOS. Microsoft has enough problems
    just trying to keep Windows working! <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

    First, try putting DoEvents in the loop

    do
    DoEvents
    Loop until MyApp <> 0

    Next, try the Sleep command instead of the do loop.

    Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

    Keep in mind your thread (the calling app) freezes for the entire
    duration indicated by dwMilliseconds.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Kevin,

    Still no progress. So far I've tried:

    Sub Start()
    MyApp = shell("e:comb.bat",1)
    Do
    DoEvents
    Loop until MyApp <>0
    AppActivate MyApp
    End Sub

    and

    Sub Start()
    MyApp = shell("e:comb.bat",1)
    Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) 'This encounters a compile error: Only comments may appear after End Sub, End Function, or End Property
    AppActivate MyApp
    End Sub

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Batch File (XL97;SR2)

    Declare statements must be placed before all procedure and function definitions, not within a Sub ... End Sub.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    As Hans has point out, that line of code is a declare statement. Put it in the declarations section of the module.
    You need a brief tutorial on using the API.
    Try here. Download the API-guide.

    Your sub would look like this using the Sleep function:
    Sub Start()
    MyApp = shell("e:comb.bat",1)
    Sleep 5000 'Sleep for 5 seconds. Adjust this to give your .bat file the time it needs to complete in milliseconds.
    AppActivate MyApp
    End Sub


    p.s. Since you are now running this on a W2k PC, you may be encountering a permissions issue. What does that
    bat file do? If it tries to write to a folder for which you do not have access rights, it may never finish no matter
    what you put in your calling sub. Just a thought...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    I've corrected the code and placed the declare statement in the declarations section of the module and actually see the 10 second delay (changed it to 10 sec delay; as it only takes 3 seconds to create a new file) taking place. Unfortunately I'm coming up with the same issue of the "AppActivate MyApp".

    The batch file "Comb.Bat" simply combines a number of text files into one large one in a subdirectory on my laptop. There is nothing wrong with the batch file as I can use WExplorer, click on the batch file and the net result is a new text file.

    John <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Thanks for the API-Guide resource.

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Are you just trying to make sure the comb.bat window closes when it's finished?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    The new text file never does get created. I'm not sure why other than the error message received (as stated at the beginning of this thread).

    I'm going to set the sleep to 30 seconds and see what happens.

    John

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch File (XL97;SR2)

    Sometimes if a DOS box loses focus, it stops executing.
    So, it makes sense that you want to Activate it -- to allow it
    to continue executing. Does the batch file DOS window
    stay open? If the text file never gets created then the batch
    file is not running -- it may start, but it does not complete.

    Put some debug echo and pause statements in the batch
    file to check it's progress. How far does it get?

    Another way to start a DOS session is with the Start command.
    It's far more elegant and gives you some control over how
    the app runs. Try

    MyApp = shell( "cmd /c start /B /w e:comb.bat")
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •