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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick question??? 1

Status
Not open for further replies.

DazzaC

Programmer
Jun 10, 2002
209
GB
Hi guys I am relatively new to VB but need an app to quickly complete a simple task for me. I have created the app in work but have been having problems and was looking for some help?
I have a file filename.tsv that is extarcted from an application. After the file is extracted the app then checks for the existence of the file then outputs copies it to a drive. My app seems to work but not very consistently.
Can anyone help?

Step 1> check for existence of file. If the file exists then copy it to the drive
Step 2> if the file does not exist output an error message that informs the user of the error
Step> inform user that file has been moved once copie, then output message informing of the success.

At present my app outputs the message even when the file has not been copied correctly!
Any help would be much appreciated?
 
You could make a batch file tha checks that for you.its so much easier. e.g


@echo off
if not exist c:\test.exe then
copy d:\test.exe c:\test.exe /y
end if
echo.
echo The Application did not exist locally so it has been copied to your hardrive.
pause > none
 
Post your code so we can take a look.

You could try something like this:

Private Sub Command1_Click()
Dim FileToCopy As String

FileToCopy = "C:\Test2.dbf"

On Error GoTo errhandler
If Dir(FileToCopy) = "" Then
MsgBox FileToCopy & " does not exist", vbCritical
Else
FileCopy FileToCopy, "S:\" & Mid$(FileToCopy, InStrRev(FileToCopy, "\"))
End If

MsgBox "Completed Successfully!", vbInformation
Exit Sub
errhandler:
MsgBox Err.Description, vbCritical
Err.Clear
Exit Sub
End Sub

Swi
 
I looked at batch files initially but what I want the app to do I do not think that a batch file is capable of?

1. Delete the file (can do)
2. Create a script (done by VB and working)
3. Execute script (use shell command in VB)
4. Check if the file size is > 0
5. If 0 then report an error
6. Else report success of extract
7. Copy the file to drive
8. Message to report success and the file size of the copied file?

Sorry, should have explained this!
 
Thanks Swi.
I am at home at the moment and was looking for ideas to take into work tomorrow.
Relying on the internet due to a lack of manuals in work!!
 
Sorry, I forgot the Exit Subs at the end of the if conditions. Without these it will fall through the rest of the code.

Private Sub Command1_Click()
Dim FileToCopy As String

FileToCopy = "C:\Test.txt"

On Error GoTo errhandler
If Dir(FileToCopy) = "" Then
MsgBox FileToCopy & " does not exist!", vbCritical
Exit Sub
ElseIf FileLen(FileToCopy) = 0 Then
MsgBox FileToCopy & " does not contain any data!", vbCritical
Exit Sub
Else
FileCopy FileToCopy, "S:\" & Mid$(FileToCopy, InStrRev(FileToCopy, "\"))
End If

MsgBox "Completed Successfully!" & vbNewLine & _
"File Name: " & FileToCopy & vbNewLine & _
"File Size: " & FileLen(FileToCopy) & " bytes", vbInformation
Exit Sub
errhandler:
MsgBox Err.Description, vbCritical
Err.Clear
Exit Sub
End Sub

Swi
 
Can the filesize be written to a log file?
 
The code below will create a tab delimited logfile wherever you specify.

Private Sub Command1_Click()
Dim FileToCopy As String

FileToCopy = "C:\Test.txt"

On Error GoTo errhandler
If Dir(FileToCopy) = "" Then
MsgBox FileToCopy & " does not exist!", vbCritical
Exit Sub
ElseIf FileLen(FileToCopy) = 0 Then
MsgBox FileToCopy & " does not contain any data!", vbCritical
Exit Sub
Else
FileCopy FileToCopy, "S:\" & Mid$(FileToCopy, InStrRev(FileToCopy, "\"))
End If

Open "S:\Logfile.txt" For Append As #1
Print #1, FileToCopy & vbTab & FileLen(FileToCopy)
Close #1
MsgBox "Completed Successfully!" & vbNewLine & _
"File Name: " & FileToCopy & vbNewLine & _
"File Size: " & FileLen(FileToCopy) & " bytes", vbInformation
Exit Sub
errhandler:
MsgBox Err.Description, vbCritical
Err.Clear
Exit Sub
End Sub

Swi
 
Swi you have been a great help.

Many thanks for your time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top