Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21835

shell execute works until I run another subroutine

$
0
0
Hi All - First Post

I am working on a test application whereby I open multiple files - populate a listbox - then run a batch file [to test shellexecute]
If I run the batch file right away - it works, if I open multiple files first and Cancel - it works, if I actually select two or more files - then try to run the batch file - it fails
It is writing the batch files correctly - and if I doubleclick on them - they work as expected.
I'm wondering if there is some sort of conflict between the two functions:ShellExecute and GetFiles? or a problem using CommonDialogControl then trying to use ShellExecute?

Any help is appreciated

Code:

Private Declare Function ShellExecute Lib _
    "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation _
    As String, ByVal lpFile As String, ByVal _
    lpParameters As String, ByVal lpDirectory _
    As String, ByVal nShowCmd As Long) As Long
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_NORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_MAXIMIZE = 3
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOW = 5
Const SW_MINIMIZE = 6
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_RESTORE = 9
Const SW_SHOWDEFAULT = 10
Const SW_MAX = 10

Public Function GetFiles(Optional ByVal sTitle As String = "Open files...") As String
  ' sTitle: Optional Title of Dialog
  Dim sFilenames As String
  Dim cdlOpen As Object
  On Error GoTo ProcError
  ' Get the desired name using the common dialog
  Set cdlOpen = CreateObject("MSComDlg.CommonDialog")
  ' set up the file open dialog file types
  With cdlOpen
    ' setting CancelError means the control will
    ' raise an error if the user clicks Cancel
    .CancelError = True
    .Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.*.txt|INI Files (*.ini)|*.ini|Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif"
    .FilterIndex = 1
    .DialogTitle = sTitle
    .MaxFileSize = &H7FFF ' 32KB filename buffer
    ' set up Common Dialog flags
    ' same as .Flags = cdlOFNHideReadOnly Or cdlOFNPathMustExist Or cdlOFNLongNames Or cdlOFNAllowMultiselect or cdlOFNExplorer
    .Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
    .ShowOpen
    ' get the selected name
    sFilenames = .Filename
  End With
ProcExit:
  GetFiles = sFilenames
  Set cdlOpen = Nothing
  Exit Function
ProcError:
  If Err.Number = &H7FF3 Then Resume Next 'Cancel selected - Ignore
  MsgBox Err.Description & "(" & Err.Number & ")", vbExclamation, "Open error"
  sFilenames = ""
  Resume ProcExit
End Function
'
' change directory to location of batch file
Private Sub command1_Click()
Dim doit
ChDir ("C:\Users\UNOIT\Desktop\FSO\")
doit = "media2.bat"
ShellExecute 0&, vbNullString, doit, vbNullString, vbNullString, SW_SHOWDEFAULT
End Sub
'
Private Sub cmdOpen_Click()
  Dim Shell, strFileNames, objFSO, filesys, Filename, path, wholename, i
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Set filesys = CreateObject("Scripting.FileSystemObject")
  strFileNames = Split(GetFiles, Chr(0))
  With List1
    If UBound(strFileNames) > 0 Then
      .Clear
      For i = 1 To UBound(strFileNames)
        .AddItem strFileNames(0) & strFileNames(i)
      Next
    Else
      .AddItem "(No files selected)"
    End If
  End With
 For i = 1 To UBound(strFileNames)
  MsgBox "Writing media info file"
  Filename = "Media" & i & ".bat"
  path = "C:\Users\UNOIT\Desktop\FSO\"
  wholename = path & Filename
  MsgBox "mymedia.bat=" & Filename
  Set filetxt = filesys.OpenTextFile(wholename, ForWriting, True)
  filetxt.WriteLine "MediaInfo.Exe" + " --Inform=file://Template1.txt " + strFileNames(0) & "\" & strFileNames(i) + " >> " & strFileNames(i) + ".txt"
  filetxt.Close
 Next
End Sub

TIA
wiseant

Viewing all articles
Browse latest Browse all 21835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>