Running external programs in VB6

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 6954 Views - Last Post: 14 June 2011 - 08:12 AM Rate Topic: -----

#1 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Running external programs in VB6

Posted 13 June 2011 - 01:57 AM

Hello everyone.

I'm not very experienced in programming in VB6, but no one else seems interested in developing our 3D editor, so I'm going to have a go, with your forums help. :)

I'm part of a group working on a very old Flight Sim called European Air Wars, and a long time ago, one of our group wrote several utilities, and an editor, but I only have the code for the editor in VB6, so I want the editor to work with stand alone programs, and import text information from the created results.

What I would like to do first is add a button to the form, which I know how to do, but the next bit I need help with. I have a copy of Microsoft VB Studio 6 to compile the code with. I've tried to convert up to VB8 or newer but everytime I try, the program fails, so I will compile in VB6, as I know it works.

I want the button to operate an external program called "RSC.exe".

RSC requires a full file name to be entered, which is the file being currently used in the studio, like PSP2AF.3DZ, but I do not want the user to have to put in the file name, just I would like it to be automatic on clicking the button to run RSC.exe.

How do I do this? Please remember I'm no coder, so please keep replies simple.

:)

Is This A Good Question/Topic? 0
  • +

Replies To: Running external programs in VB6

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 13 June 2011 - 02:31 AM

Take a look at this link and it may give you what you need.
Was This Post Helpful? 0
  • +
  • -

#3 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 13 June 2011 - 03:45 AM

Thanks, yes that would seem to do the trick. I'll try this evening to code the button and see if I can get RSC to open from the button.
:)
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 13 June 2011 - 04:44 AM

If you've any problems, post back the code you've added to the button and the error you get and we'll take it from there.

Good luck.
Was This Post Helpful? 0
  • +
  • -

#5 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 13 June 2011 - 04:59 AM

Thank Maj.

Nice to meet such a friendly forum.
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Running external programs in VB6

Posted 13 June 2011 - 07:58 AM

By the way, the reason that your code doesn't work with "VB 8" is that everything past VB6 is a version of VB.Net, which only looks rather like VB6 but is not backward compatible.
Was This Post Helpful? 0
  • +
  • -

#7 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 13 June 2011 - 08:35 AM

I'm doing something wrong.


Private Sub mnu_v_rs_Click()
    mnu_v_rs.Checked = Not mnu_v_rs.Checked
    If mnu_v_rs.Checked Then
        tlb_main.Buttons("RS").Shell "c:\RSC.exe", vbNormalFocus 
'old code value = tbrPressed
    'Else
        'tlb_main.Buttons("RS").value = tbrUnpressed
    End If
End Sub



        Case "RS"
            mnu_v_rs.Checked = Not mnu_v_rs.Checked


Posted Image
Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 13 June 2011 - 09:57 AM

You've tried to execute the Shell command as a property of the button by using the ., so it will give you a compile/syntax error.

The code needs to be under the event that is raised when you press the button, not sure if you're on a toolbar thought with what you've pasted.

As a simple test so you understand how it works, create a new project and just add a button onto the form. Double click on the button and the code window will appear with the button click event handler. You just add your code into there (Shell "c:\RSC.exe", vbNormalFocus).

There is a tutorial hereto help understand how the toolbar works.
Was This Post Helpful? 0
  • +
  • -

#9 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 13 June 2011 - 10:29 AM

OK Maj cracked that and the button is working just fine.

Now to stage two, and I have no idea how to do this.

This is the RSC.exe working from the studio.

What I'd like to do now is feed it the current file name, as I have manually inputted on my screen.

Posted Image

Is it possible to do this?
Was This Post Helpful? 0
  • +
  • -

#10 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 14 June 2011 - 01:00 AM

Good, then at least you're moving forward! :)

You can pass arguments to the program using Shell, something like below should work.

Shell "RSC.exe filename"", vbNormalFocus


Give that a try.
Was This Post Helpful? 0
  • +
  • -

#11 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 14 June 2011 - 01:28 AM

Hi maj.

I've just destroyed my project file!

All the other files are OK but I can't load the project anymore and all I have is a very Old one which does not have any of the new functions.

Is there anyway to recover, without redoing everything?
Was This Post Helpful? 0
  • +
  • -

#12 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 14 June 2011 - 02:47 AM

OK I've recovered to a point where I have yesterdays button working.

I'll add all the buttons back again later.

Posted Image

In the studio, [picture above] the current file name, which is what I want to send to RSC.exe, is displayed at the top of the studio. I've searched through the code and found several bits of code regarding saved models, but which section of code would be best to use?

I'm trying to click RSC button, and at that time open RSC.exe, and sent the current open file name to RSC.exe, so it can do it's thing.

Private Sub mnu_f_save_Click()
    ' Save the model
    Studio.LoadedModel.Save "ONE"
End Sub


Private Sub mnu_f_saveas_Click()
On Error GoTo ErrHandler

    ' Find Filename
    cmdiag.DialogTitle = "Save Model"
    cmdiag.Filter = "3DZ Model|*.3dz|3DB Model|*.3db"
    cmdiag.FilterIndex = 1
    cmdiag.Filename = ""
    cmdiag.ShowSave
    
    ' Save the model
    Studio.LoadedModel.Save cmdiag.Filename
    
ErrHandler:
End Sub


Private Sub mnu_f_load_Click()
On Error GoTo ErrHandler

    ' Find filename
    cmdiag.DialogTitle = "Load Model"
    cmdiag.Filter = "3DZ Model|*.3dz|3DB Model|*.3db"
    cmdiag.FilterIndex = 1
    cmdiag.ShowOpen
    
    ' Load the model
    If cmdiag.Filename <> "" Then
        Set Studio.LoadedModel = Nothing
        Set Studio.LoadedModel = New model
        Studio.LoadedModel.Load cmdiag.Filename
    End If

ErrHandler:
End Sub

Was This Post Helpful? 0
  • +
  • -

#13 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 14 June 2011 - 03:15 AM

Firstly, I'm glad you recovered your project, but i'll add my disclaimer here that it wasn't my fault! :)

I would guess that there is a variable somewhere that holds the name of the file, so it can be displayed in the title bar.

I would suggest that you do a search for form.caption but replace form with the name of the form, as I would think it is being set somewhere.

Obviously, it's difficult for me to advise exactly where to put it as I don't have full visiblity of the project and not likely to.

Do a search for what I've said and see if anything comes to light, so then you know the variable to pass in to the Shell function.

Just bare in mind the shell call will change to something like

Quote

Shell "RSC.exe " & strFilenameVariable
.
Was This Post Helpful? 0
  • +
  • -

#14 Col. Gibbon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-June 11

Re: Running external programs in VB6

Posted 14 June 2011 - 04:09 AM

It seems to be linked to
cmdiag.Filename

but I tried your search without a result.

I could send you a copy of my project so you'll be able to advise me better what to do.

I'm sure it's very simple, but I'm a 56 year old, 3D model man, for our old flight Sim, not a VB6 coder! :)

I'm on a host of anti depressants and other heart tablets to keep me going, and it was my pure sleepiness this morning that made wreck my studio project update.

Nothing to blame yourself for. :)
Was This Post Helpful? 0
  • +
  • -

#15 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Running external programs in VB6

Posted 14 June 2011 - 04:33 AM

The cmdialog.filename does hold the filename, but I would think it's being stored somewhere to appear in the title....

I was only joking about the mess up earlier....we all make mistakes, so don't beat yourself up about it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2