Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: BlazingKnight on November 02, 2003, 11:24 PM

Title: Opening other files
Post by: BlazingKnight on November 02, 2003, 11:24 PM
How do you open another .exe file through a vb program?
Title: Re:Opening other files
Post by: Newby on November 02, 2003, 11:59 PM
Correct me if I'm wrong.

Shell filename

8)
Title: Re:Opening other files
Post by: AzN on January 04, 2004, 09:38 PM
        On Error GoTo ssfdsfds
       Shell "C:\Program Files\Starcraft\starcraft.exe"
       GoTo theend
ssfdsfds:
       MsgBox "Error on loading file"
theend:
Title: Re:Opening other files
Post by: Adron on January 04, 2004, 10:16 PM
I recommend you insert a "Resume theend" right before theend:. If you don't finish error processing with a resume, any future error won't be handled right.
Title: Re:Opening other files
Post by: drivehappy on January 04, 2004, 11:46 PM
Wouldn't a Exit Sub/Function be better than another Goto?
Title: Re:Opening other files
Post by: Puzzle on January 05, 2004, 09:02 AM
Quote from: drivehappy on January 04, 2004, 11:46 PM
Wouldn't a Exit Sub/Function be better than another Goto?
Not unless that's the end of the sub or function which is most likely not the case.
Title: Re:Opening other files
Post by: drivehappy on January 05, 2004, 11:38 AM
Well, just put the error label at the end:


Public Sub Blah
 On Error GoTo ssfdsfds
 Shell "C:\Program Files\Starcraft\starcraft.exe"
 MoreCrap()
 Exit Sub
ssfdsfds:
 MsgBox "Error on loading file"
End Sub

Title: Re:Opening other files
Post by: Grok on January 05, 2004, 02:41 PM
My standard invocation is as follows:

Private Sub WhateverTask()
   
   On Error Goto WhateverTaskErr
   
   'do stuff
   
WhateverTaskExit:
   Exit Sub
   
WhateverTaskErr:
   Dim lErr As Long, sErr As String, lLine As Long
   lErr = Err.Number : sErr = Err.Description : lLine = Erl
   Resume WhateverTaskExit
   
End Sub


There's a little more to it than that, depending on what the procedure is doing.  I might put a Select..Case in the Error Handler, possibly a MsgBox and offer to Retry, Ignore or Cancel, depending on the error and what is appropriate.  If they choose Cancel, you'd resume WhateverTaskExit.  If they Retry, you Resume, and if they choose Ignore, you do Resume Next.

What you get tired of write all those error handlers, you'll be practiced enough to start writing general error handlers, which requires a little advance maintenance in each procedure you want to take advantage of it.
Title: Re:Opening other files
Post by: Banana fanna fo fanna on January 10, 2004, 10:30 PM
*sigh* VB error handling.
Title: Re:Opening other files
Post by: Adron on January 11, 2004, 08:13 AM
Quote from: St0rm.iD on January 10, 2004, 10:30 PM
*sigh* VB error handling.

I've done that too. But vbdump.dll helps a lot!
Title: Re:Opening other files
Post by: Mesiah / haiseM on January 17, 2004, 01:44 PM
Are you just trying to open another application, or are you trying to open it as a child, and set your form as the parent? A long time ago, when i first got into programming, I was in open tech support, and skywing told me it was impossible, but it isn't :P

Just wondering, reply if you need code for this technique.
Title: Re:Opening other files
Post by: K on January 17, 2004, 02:47 PM
Quote from: MesiaH on January 17, 2004, 01:44 PM
Are you just trying to open another application, or are you trying to open it as a child, and set your form as the parent? A long time ago, when i first got into programming, I was in open tech support, and skywing told me it was impossible, but it isn't :P

Just wondering, reply if you need code for this technique.

You mean using the SetParent function?
Title: Re:Opening other files
Post by: Mesiah / haiseM on January 18, 2004, 01:37 PM
yes, amungst a few others.