Hello again everyone. I am writing a vb .exe app in .NET 2003 and I am having a problem with an error. The error says, "'Open is not declared. File I/O functionality is available in the 'Microsoft.VisualBasic' namespace." I think that I need add a reference to the System.IO object but I cannot find it listed un the .NET tab in the Add Reference window. Is this my problem or is it something else???? Here is my code. I am just using 1 module and the program is for moving files and seeing if a file is already opened. Thanks again everyone in advance.
Manguilla
Module Module1
Sub Main()
Dim strDir As String
Dim strSource As String
Dim strNew As String
Dim strDest As String
Dim strFile As String
Dim I As Integer
Dim currFile As String
Dim compFile As String
Dim txt As String
Dim strNum As String
Dim currNum As String
Dim finNum As Integer
Dim N As Integer
Dim pos As Integer
strDir = "C:\Win2000\"
strDest = "C:\Captures\"
txt = "Capture"
currFile = Dir(strDest & "*.*")
If currFile <> "" Then
Do While currFile <> ""
strNum = Mid$(currFile, 1, 2)
currNum = Int(strNum)
If finNum < currNum Then
finNum = currNum
End If
currFile = Dir()
Loop
End If
If finNum = 0 Then
finNum = 10
Else
finNum = finNum + 1
End If
strFile = Dir(strDir & "*.*")
Do While strFile <> ""
pos = InStr(strFile, txt)
If pos > 0 Then
I = I + 1
strSource = strDir & strFile
strNew = strDest & finNum & "capture_" & I & ".log"
If Not IsFileLocked(strSource) Then
FileCopy(strSource, strNew)
System.IO.File.Delete(strSource)
strSource = strNew
End If
End If
strFile = Dir()
Loop
End Sub
Private Function IsFileLocked(ByVal filePath As String) As Boolean
On Error Resume Next
If Dir(filePath) <> "" Then
Dim fileHandle As Integer
fileHandle = FreeFile()
Open filePath For Input Lock Read As #fileHandle
If Err.Number = 0 Then
Close #fileHandle
IsFileLocked = False
ElseIf Err.Number = 70 Then
IsFileLocked = True
End If
Else
IsFileLocked = False
End If
End Function
End Module
Manguilla
Module Module1
Sub Main()
Dim strDir As String
Dim strSource As String
Dim strNew As String
Dim strDest As String
Dim strFile As String
Dim I As Integer
Dim currFile As String
Dim compFile As String
Dim txt As String
Dim strNum As String
Dim currNum As String
Dim finNum As Integer
Dim N As Integer
Dim pos As Integer
strDir = "C:\Win2000\"
strDest = "C:\Captures\"
txt = "Capture"
currFile = Dir(strDest & "*.*")
If currFile <> "" Then
Do While currFile <> ""
strNum = Mid$(currFile, 1, 2)
currNum = Int(strNum)
If finNum < currNum Then
finNum = currNum
End If
currFile = Dir()
Loop
End If
If finNum = 0 Then
finNum = 10
Else
finNum = finNum + 1
End If
strFile = Dir(strDir & "*.*")
Do While strFile <> ""
pos = InStr(strFile, txt)
If pos > 0 Then
I = I + 1
strSource = strDir & strFile
strNew = strDest & finNum & "capture_" & I & ".log"
If Not IsFileLocked(strSource) Then
FileCopy(strSource, strNew)
System.IO.File.Delete(strSource)
strSource = strNew
End If
End If
strFile = Dir()
Loop
End Sub
Private Function IsFileLocked(ByVal filePath As String) As Boolean
On Error Resume Next
If Dir(filePath) <> "" Then
Dim fileHandle As Integer
fileHandle = FreeFile()
Open filePath For Input Lock Read As #fileHandle
If Err.Number = 0 Then
Close #fileHandle
IsFileLocked = False
ElseIf Err.Number = 70 Then
IsFileLocked = True
End If
Else
IsFileLocked = False
End If
End Function
End Module