[Resolved]FileCopy Wierdness...
VB Code:
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)
On Error Resume Next
Dim Drive_Let As String
Drive_Let = Find_Drive_Letter
DoEvents
MkDir Drive_Let & ":\Program Files\" & Company_
MkDir Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name
DoEvents
If Replace_File_ = True Then Kill Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
DoEvents
[B]FileCopy FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_[/B]
DoEvents
If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
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?
Re: FileCopy Wierdness...
Where is the FixPathFile procedure located and what is its declaration (Public or Private, in a Module or Class or Form)?
Re: FileCopy Wierdness...
VB Code:
Public Function FixPathFile(ByVal Path As String, File As String) As String
On Error Resume Next
If Right$(Path, 1) <> "\" Then
FixPathFile = Path & "\" & File
Else
FixPathFile = Path & File
End If
If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
End Function
Same Module. But it still doesn't work even if FixPathFile is not in there.
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.
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:
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)
On Error Resume Next
Dim Drive_Let As String
Drive_Let = Find_Drive_Letter
If Path_ = "" Then Path_ = App.Path
If EXEName_ = "" Then EXEName_ = App.EXEName
If Program_Name = "" Then Program_Name = App.EXEName
If Company_ = "" Then Company_ = App.CompanyName
DoEvents
MkDir Drive_Let & ":\Program Files\" & Company_
MkDir Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name
DoEvents
If Replace_File_ = True Then Kill Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
DoEvents
FileCopy FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
DoEvents
If Error <> 0 Then Debug.Print Err.Number, Err.Description, "Source: " & Err.Source
End Sub
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:
?FixPathFile(Path_, EXEName_), Drive_Let & ":\Program Files\" & Company_ & "\" & Program_Name & "\" & EXEName_
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.
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:
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.
Re: FileCopy Wierdness...
If Path_ is optional in Install_Program... why is it mandatory in FixFilePath????
That will not work....
Re: FileCopy Wierdness...
You overuse and use incorrectly On Error Resume Next. You willl have all kinds of problems...
Re: FileCopy Wierdness...
Quote:
Originally Posted by jcis
VB Code:
?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.
Re: FileCopy Wierdness...
schoolbusdriver,
Then how is it supposed to copy to the destination on a different drive?
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.
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 :thumb: