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