Results 1 to 14 of 14

Thread: [Resolved]FileCopy Wierdness...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    [Resolved]FileCopy Wierdness...

    VB Code:
    1. Public Sub Install_Program(Optional Path_ As String, Optional EXEName_ As String, Optional Program_Name As String, Optional Company_ As String, Optional Replace_File_ As Boolean = True, Optional Debug_Mode As Boolean = False)
    2.  
    3. On Error Resume Next
    4.  
    5. Dim Drive_Let As String
    6.  
    7. Drive_Let = Find_Drive_Letter
    8.  
    9. DoEvents
    10.  
    11. MkDir Drive_Let & ":\Program Files\" & Company_
    12. MkDir Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name
    13.  
    14. DoEvents
    15.  
    16. If Replace_File_ = True Then Kill Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
    17.  
    18. DoEvents
    19.  
    20. [B]FileCopy FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_[/B]
    21.  
    22. DoEvents
    23.  
    24. If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
    25.  
    26. End Sub

    When i try to compile the bolded line gives me this error:

    "Compile Error"
    "Expected Procedure not variable."

    When i type up FileCopy the Popup text doesn't come up like it should.
    Infact FileCopy doesn't work anywhere in the module, but if i copy this code & place it somewhere else, it works fine. I don't want to rearrange my entire program... does anyone know what could be causing this?
    Last edited by Slyke; Aug 24th, 2006 at 03:00 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: FileCopy Wierdness...

    Where is the FixPathFile procedure located and what is its declaration (Public or Private, in a Module or Class or Form)?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: FileCopy Wierdness...

    VB Code:
    1. Public Function FixPathFile(ByVal Path As String, File As String) As String
    2.  
    3. On Error Resume Next
    4.  
    5. If Right$(Path, 1) <> "\" Then
    6. FixPathFile = Path & "\" & File
    7. Else
    8. FixPathFile = Path & File
    9. End If
    10.  
    11. If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
    12.  
    13. End Function

    Same Module. But it still doesn't work even if FixPathFile is not in there.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: FileCopy Wierdness...

    Are you using Option Explicit in that module? also, remove: On Error Resume Next, and run your code with CTRL-F5. Also, ensure VB is configured to "Break on all errors" and not "Break on Class module Errors".
    Also, if you want those parameters to be Optional assign a default value to them, else remove optional, as they are always used inside the sub.
    Last edited by jcis; Aug 24th, 2006 at 01:55 AM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: FileCopy Wierdness...

    I've done that, tried with and without Option Explicit in that module. I removed On Error Resume Next and i set it to "Break on all errors" in the options. When i run that sub, no errors come up and no errors are reported in the Debug.Print screen.

    I uncommented On Error Reume Next and saved it this way (so i won't forget later on).

    VB Code:
    1. Public Sub Install_Program(Optional Path_ As String = "", Optional EXEName_ As String = "", Optional Program_Name As String = "", Optional Company_ As String = "", Optional Replace_File_ As Boolean = True, Optional Debug_Mode As Boolean = False)
    2.  
    3. On Error Resume Next
    4.  
    5. Dim Drive_Let As String
    6.  
    7. Drive_Let = Find_Drive_Letter
    8.  
    9. If Path_ = "" Then Path_ = App.Path
    10. If EXEName_ = "" Then EXEName_ = App.EXEName
    11. If Program_Name = "" Then Program_Name = App.EXEName
    12. If Company_ = "" Then Company_ = App.CompanyName
    13.  
    14. DoEvents
    15.  
    16. MkDir Drive_Let & ":\Program Files\" & Company_
    17. MkDir Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name
    18.  
    19. DoEvents
    20.  
    21. If Replace_File_ = True Then Kill Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
    22.  
    23. DoEvents
    24.  
    25. FileCopy FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
    26.  
    27. DoEvents
    28.  
    29. If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
    30.  
    31. End Sub
    Last edited by Slyke; Aug 24th, 2006 at 02:01 AM.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: FileCopy Wierdness...

    Stop your code in the filecopy line, when it gets there, pause your code execution and paste this in the inmediate window (CTRL-G) to check the whole String thats being passed as parameter (? symbol included)
    VB Code:
    1. ?FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: FileCopy Wierdness...

    You should not use Resume Next as a main error handler mechanism.

    You should switch back and add in an error handling procedure to got to.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: FileCopy Wierdness...

    It wouldn't allow that way, it came up with the same error as if i tried to compile it, instead i did this:

    VB Code:
    1. Debug.Print FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_

    Which gave the result:
    "C:\Program Files\Microsoft Visual Studio\VB98\Screen Shooter\ScreenShooter c:\Program Files\MyCompany\MyProgram\ScreenShooter"

    When ever this type of wierd error happens, it's usually another sub's fault, however all of the subs work fine. Which explains why this works in another module. I don't get why.

    When i remove that & place it in another module, everything works fine and t compiles. There's nothing else called FileCopy either, so it is wierd.

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: FileCopy Wierdness...

    If Path_ is optional in Install_Program... why is it mandatory in FixFilePath????

    That will not work....

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: FileCopy Wierdness...

    You overuse and use incorrectly On Error Resume Next. You willl have all kinds of problems...

  11. #11
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: FileCopy Wierdness...

    Quote Originally Posted by jcis
    VB Code:
    1. ?FixPathFile(Path_, EXEName_), Drive_Let & "[SIZE=5][COLOR=Red]:[/COLOR][/SIZE]\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
    You can't use a colon as part of a file name or path.

  12. #12
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: FileCopy Wierdness...

    schoolbusdriver,

    Then how is it supposed to copy to the destination on a different drive?

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: FileCopy Wierdness...

    Lol, well thanks for all the constructive critisism XD.

    "If Path_ is optional in Install_Program... why is it mandatory in FixFilePath????"
    If they don't enter a path in then it automatically goes to App.Path

    Yeah, On error resume next is because this module is the same used for about 5 different programs. Usually it's perfect and the only error is when the file doesn't exist etc, which is why the Debug.Print is there. Any way i found the error.

    There was a public FileCopy in const in another module and it was set to 0. For some reason it didn't show up when i searched the first time.

    Thanks any ways... and sorry for all the confusion, lol. Lessoned learned: search and then research the search.

  14. #14
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: FileCopy Wierdness...

    Quote Originally Posted by randem
    schoolbusdriver,

    Then how is it supposed to copy to the destination on a different drive?
    lol... missed that - I wasn't thinking of the root

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