Results 1 to 2 of 2

Thread: Else statement

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    W.Lafayette, In USA
    Posts
    37
    For the code below where would I put an Else statement if the file was not found.

    Private Sub Command1_Click()
    Set m_objFSO = New Scripting.FileSystemObject
    Screen.MousePointer = vbHourglass
    Call CheckFolder("C:\")
    Screen.MousePointer = vbDefault
    End Sub

    Public Sub CheckFolder(sPath As String)
    Dim objFolder As Scripting.Folder
    Dim objSubDirs As Scripting.Folders
    Dim objLoopFolder As Scripting.Folder
    Dim myItem As String
    Dim res As String
    m_objFSO.FileExists = False
    Set objFolder = m_objFSO.GetFolder(sPath)

    'Does the sPath string require an extra back-slash?
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"

    If (m_objFSO.FileExists(sPath & "AcroRd32.exe")) Then
    ShellExecute 0&, "OPEN, App.Path & "P:\EngineModelProject\16CM32HFO\16CM32HFOManHours.pdf", "", "", 1
    End If
    Set objSubDirs = objFolder.SubFolders

    'Repeat this Sub for each sub directory in
    'the SubFolders collection
    For Each objLoopFolder In objSubDirs
    CheckFolder objLoopFolder.Path
    Next objLoopFolder

    'Free up memory
    Set objSubDirs = Nothing
    Set objFolder = Nothing
    End Sub

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Just before your End If put an Exit Sub Command, then just before you destroy your scripting objects put the code for not finding the file, Like this

    Code:
    Private Sub Command1_Click() 
    Set m_objFSO = New Scripting.FileSystemObject 
    Screen.MousePointer = vbHourglass 
    Call CheckFolder("C:\") 
    Screen.MousePointer = vbDefault 
    End Sub 
    
    Public Sub CheckFolder(sPath As String) 
    Dim objFolder As Scripting.Folder 
    Dim objSubDirs As Scripting.Folders 
    Dim objLoopFolder As Scripting.Folder 
    Dim myItem As String 
    Dim res As String 
    m_objFSO.FileExists = False 
    Set objFolder = m_objFSO.GetFolder(sPath) 
    
    'Does the sPath string require an extra back-slash? 
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\" 
    
    If (m_objFSO.FileExists(sPath & "AcroRd32.exe")) Then 
    ShellExecute 0&, "OPEN, App.Path & "P:\EngineModelProject\16CM32HFO\16CM32HFOManHours.pdf", "", "", 1 
             '    *
             '  *
    Exit Sub '******************  LOOK
             '  *
             '    *
    End If 
    Set objSubDirs = objFolder.SubFolders 
    
    'Repeat this Sub for each sub directory in 
    'the SubFolders collection 
    For Each objLoopFolder In objSubDirs 
    CheckFolder objLoopFolder.Path 
    Next objLoopFolder 
    
    '            ******************************
    '            *Put File not found code Here*
    '            ******************************
    
    'Free up memory 
    Set objSubDirs = Nothing 
    Set objFolder = Nothing 
    End Sub
    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width