Results 1 to 8 of 8

Thread: FSO need help really badly

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    I've been at this for ages and can't seem to get it to work.
    Code:
    Private Function MakeFolder(NewDir As String)
    Dim dirname As String
    dirname = "C:\TestOrator\"
    NewDir = dirname & NewDir
    MkDir NewDir
    End Function
    
    Private Sub Archive_Click()
    today = Format(Now, "dd mmmm yyyy")
    MakeFolder (today)
    Call CopyA
    End Sub
    
    Public Sub CopyA()
    Dim FSO As Object
    On Error GoTo NOFSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    today = Format(Now, "dd mmmm yyyy")
    
    On Error Resume Next
    FSO.CopyFile "C:\TestOrator\Outgone\*.gen", Makefolder(today), True
    FSO.DeleteFile "C:\TestOrator\Outgone\*.gen"
    Set FSO = Nothing
    Exit Sub
    NOFSO:
    MsgBox "FSO CreateObject Failed, Copying of files"
    End Sub
    The error I get is a byref argument type mismatch. I'm not sure if it is possible to use FileCopy in this manner. The destination Folder is being generated daily for archiving purposes so the name is different every day. Can someone please help, I'm really stuck with this problem. Thanks

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    'you should also use Option Expicit function
    'you should implement a check to see if the dir exist
    'before your create it..possibility of error if it
    'does exist.

    Code:
    Option Explicit
    
    Private Function MakeFolder(NewDir As String)
    Dim dirname As String
    dirname = "C:\TestOrator\"
    
    'changed it here get to the root dir and then add subdir
    ChDir dirname
    
      If Dir(newdir, vbDirectory) <> "" Then
        MsgBox "Exist Already"
      Else
        
    MkDir NewDir
       endif
    
    End Function
    
    Private Sub Archive_Click()
    today = Format(Now, "dd mmmm yyyy")
    MakeFolder (today)
    Call CopyA
    End Sub
    
    Public Sub CopyA()
    
    'add this:  you referenced a string in function and 
    'then you passed a date
    
    Dim today As String
    
    Dim FSO As Object
    On Error GoTo NOFSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    today = Format(Now, "dd mmmm yyyy")
    
    On Error Resume Next
    FSO.CopyFile "C:\TestOrator\Outgone\*.gen", MakeFolder(today), True
    FSO.DeleteFile "C:\TestOrator\Outgone\*.gen"
    Set FSO = Nothing
    Exit Sub
    NOFSO:
    MsgBox "FSO CreateObject Failed, Copying of files"
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks for the help. I just tried that and I get a Compile error that Variable is not defined and it points to this part of code
    Code:
    Private Sub Archive_Click()
    today = Format(Now, "dd mmmm yyyy")
    MakeFolder (today)
    Call CopyA
    End Sub
    Have I left something out?? Thanks again your help is really valued

  4. #4
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    you haven't declared today in the sub:
    Code:
    Private Sub Archive_Click()
    Dim today as String 'missed out
    today = Format(Now, "dd mmmm yyyy")
    MakeFolder (today)
    Call CopyA
    End Sub
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    As S@NSIS pointed out..failure to declare.

    That is what Option Explict does.
    It forces you to declare your variables.
    Very good practice if you are working with a lot
    of variables..no dupes permitted and you must declare
    all so your code will be cleaner.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks a lot once again. I've gotten rid of the error messages now, but the FileCopy isn't copying any files over at all. Is there something wrong with the way that I am way I using FileCopy.

    Thanks guys

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'added a public var for your dirname
    Public MyNewDir As String
    
    Option Explicit
    
    Private Function MakeFolder(NewDir As String)
    
        Dim dirname As String
        dirname = "C:\TestOrator\"
        
        ChDir dirname
        
          If Dir(NewDir, vbDirectory) <> "" Then
            MsgBox "Exist Already"
          Else
            
        MkDir NewDir
        MyNewDir = NewDir
           End If
    
    End Function
    
    Private Sub Archive_Click()
        Dim today As String
        today = Format(Now, "dd mmmm yyyy")
        MakeFolder (today)
    
    Call CopyA
    End Sub
    
    Public Sub CopyA()
    
        'add this:  you referenced a string in function and
        'then you passed a date
        
        Dim today As String
        
        Dim FSO As Object
        On Error GoTo NOFSO
        Set FSO = CreateObject("Scripting.FileSystemObject")
        today = Format(Now, "dd mmmm yyyy")
        
        On Error Resume Next
        
        'copy it to MyNewDir as the dir is already created
        
        FSO.CopyFile "C:\TestOrator\Outgone\*.txt", MyNewDir, True
        FSO.DeleteFile "C:\TestOrator\Outgone\*.txt"
        Set FSO = Nothing
        Exit Sub
    NOFSO:
        MsgBox "FSO CreateObject Failed, Copying of files"
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks a lot HeSaidJoe, your a champion. I got it to transfer the files. The only part I couldn't get to work was that check at the top:

    Code:
    Private Function MakeFolder(NewDir As String)
    
        Dim dirname As String
        dirname = "C:\TestOrator\"
        
        ChDir dirname
        
          If Dir(NewDir, vbDirectory) <> "" Then
            MsgBox "Exist Already"
          Else
            
        MkDir NewDir
        MyNewDir = NewDir
           End If
    
    End Function
    It transfers the files when I leave this part as:

    Code:
    Private Function MakeFolder(NewDir As String)
    
        Dim dirname As String
        dirname = "C:\TestOrator\"
        NewDir = dirname & NewDir
        MkDir NewDir
        MyNewDir = NewDir
    End Function
    Thanks a million for your help, I reall appreciate it

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