Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2005, 08:33 AM
Registered User
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default shell trouble

Hello everybody,

I have a funny problem that is probably caused by my ignorance.

Basically I have an executable (compiled Fortran program) and I want to launch it from VB. I'm using the Shell function but I have something strange going on that I don't understand. Please, have a look at this sample code:

************************************
Option Explicit

Private Sub cmdBrowse_Click()
With CommonDialog1
        .DialogTitle = "Select a DAT file"
        .Filter = "All files|*.*|Text Files (*.dat)|*.dat"
        .FilterIndex = 2
        .Flags = cdlOFNFileMustExist
        .ShowOpen
        txtFileName.Text = .FileName
        If Len(txtFileName.Text) Then optRun(1) = True
    End With
End Sub

Private Sub cmdRun_Click()
Dim strRunEPIC As String
Dim taskID As Long

strRunEPIC = App.Path & "\epic3050\EPIC3050.exe " & App.Path & "\epic3050\EPIC3050.DAT"

If optRun(0) Then

    taskID = Shell(strRunEPIC, vbNormalFocus)
Else
    taskID = Shell(App.Path & "\epic3050\EPIC3050.exe " & txtFileName, vbNormalFocus)

End If
End Sub

************************************************** ******************************
In the form if I click the optRun(0) the program doesn't run. If I click the optRun(1) and I browse for the file .DAT in the common dialog it works perfectly! The string inside the Shell function is exactly the same in both cases.
More.....if I go back to select the optRun(1) now it works. However, if I close the project and restart it and again I start from optRun(0) it doesn't work.

Outside VB the executable run just by double clicking the .EXE or entering EPIC3050 in the command line.

What the hell am I doing wrong?

Any help will be greatly apreciated

Alberto
 
Old July 27th, 2005, 02:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

.... what is optRun?

Marco
 
Old July 28th, 2005, 05:20 AM
Registered User
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Marco,

it's an option button.
When selecting optRun(0) shell runs with the hardcoded string
When selecting optRun(1) shell runs with a string wich is partially obtained from the common dialog

In both case the string is exactly the same. However in the first case it doesn't work, in the second it's ok. After running with optRun(1) (the one that works) if I rerun selecting optRun(0) it works.

 
Old July 28th, 2005, 11:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I do not understand your "the string is exactly the same". Does that means that in the show file dialog you select the same file as the one hardcoded?
Marco
 
Old July 29th, 2005, 01:53 AM
Registered User
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Exactly

in the hardcoded option it doesn't work...when I build the string with the common dialog filling the textbox with the selected file (the same wich is hardcoded in optRun(0)) it does work!

Alberto

 
Old July 29th, 2005, 12:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alberto, che ti devo dire...
I would stop the debugger at the statement:

If optRun(0) Then

then I would look the values of the variables. if
App.Path & "\epic3050\EPIC3050.exe " & App.Path & "\epic3050\EPIC3050.DAT"
and
App.Path & "\epic3050\EPIC3050.exe " & txtFileName
are really the same, I really do not understand why it is not working. The only whay I can see they can differ is the file path (txtFileName does not have any path specified, because is coming from the dialog box).
And BTW, what do you mean with 'doesn't work'?
Marco

PS the statement
   If Len(txtFileName.Text) Then optRun(1) = True
is incorrect, because the Len function returns an integer, not a boolean, and in case the test if false, you have to set optRun(0):

   If Len(txtFileName.Text) > 0 Then
      optRun(1) = True
   else
      optRun(0) = True
   endif

or, a little more cryptic:
   optRun(iif(len(txtFileName) > 0, 1, 0) = true





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: Shell???? Apocolypse2005 Visual Basic 2005 Basics 1 April 24th, 2008 06:31 AM
Shell seananderson Beginning VB 6 3 March 16th, 2007 05:41 AM
How to use shell-like programming in C#? RookieStar General .NET 1 March 15th, 2005 02:18 AM
Shell Script techSupport C++ Programming 0 March 10th, 2005 05:58 AM
Shell programming programmed C++ Programming 1 November 30th, 2003 07:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.