Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to copy a file in vb app

Status
Not open for further replies.

baltog

Programmer
Dec 19, 2002
22
0
0
US
hi all,

Anyone can help me how to copy a file in my vb app? I've tried to use FileCopy Function having parameters source and destination. I have variables which handle the source and the destination path. I'm sure i missed something in my code.

Thanks
 
Hi,

Here's the code:

***********
Dim strSource, strDest as string

strSource = "C:\Source\samplefile.txt"
strDest = "C:\Destination"
FileCopy(strSource, strDest)
***********

With that, the line 'FileCopy(strSource, strDest)' is expecting "=". So i placed a to test the.
a = FileCopy(strSource, strDest)
With this code the FileCopy function still has error.
Please help. No familiar with this.

Tnx so much

 
Hi,

Here's the code:

***********
Dim strSource, strDest as string

strSource = "C:\Source\samplefile.txt"
strDest = "C:\Destination"
FileCopy(strSource, strDest)
***********

With that, the line 'FileCopy(strSource, strDest)' is expecting "=". So i placed a to trap the error.
a = FileCopy(strSource, strDest)
With this code the FileCopy function still has error.
Please help. Not familiar with this.

Tnx so much

 
Hi there all you need to do is remove the brackets from your statement

FileCopy strSource, strDest


Transcend
[gorgeous]
 

Transcend, shouldn't baltog also specify the destination file name also?
[tt]
strSource = "C:\Source\samplefile.txt"
strDest = "C:\Destination\samplefile.txt"
FileCopy strSource, strDest
[/tt]

Good Luck

 
Ah yes of course sorry, I didnt' read the top part of the code properly >:) Just saw the brackets and commented.

Thanks vb5prgrmr

Transcend
[gorgeous]
 
baltog,

Just as a final thought,
Code:
Dim strSource, strDest as string
defines strSource as variant and strDest as string
You need to specify each variable with a type!

Code:
Dim strSource as string, strDest as string

if probably what you mean ( it shouldn't affect this routine to leave it as it is, but IMHO it is better practice to type each variable unless you have good reason not to!)

If, of course, you did intend to define strSource as variant, then I apologise!

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top