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

Open is not declared error

Status
Not open for further replies.

manguilla

Programmer
Jul 20, 2004
52
US
Hello again everyone. I am writing a .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
 
Here's how you add the reference:


[red]Imports System.IO[/red]

Module Module1
'your code...
End Module

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
I tried to add the refernce and Microsoft.VisualBasic but I'm still getting the same error. Is there something else I need to add? Thanks again.

manguilla
 
try using Microsoft.VisualBasic.FileOpen and Microsoft.VisualBasic.FileClose.
 
.. or try rewriting using modern VB.NET syntax instead of using the old VB syntax.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top