I’m converting an old VB6 app that’s been chugging along for years, but has a server name hard-coded into it. We want to convert it to a C# app, and I’m doing OK reading most of the VB6 code, except I’m not 100% sure I’m reading the code right when it comes to some basic File IO operations.
Several lines of code call the FreeFile function. I see that VB.NET has the function, and I’ve read the documentation but it’s still not making sense to me.
Remarks
Use FreeFile to supply a file number that is not already in use.
Question 1: All of my searching is not telling me what a “file number” is or what it’s used for. Is this some way of referring to a file, but not by file name?
Question 2: I’m also not sure about the Dir function. To me it looks like it’s equivalent to System.IO.File.Exists(), is that right?
Example code:
If Not Dir(My.Application.Info.DirectoryPath & "\path.txt") = "path.txt" Then
End
Else
iFile = FreeFile
FileOpen(iFile, My.Application.Info.DirectoryPath & "\path.txt", OpenMode.Input)
Input(iFile, lsDataIn)
FileClose()
End If
FreeFileis not needed in C#, since it has been completely abstracted away. Just open your files in C# using the standard File I/O.As far as
Dirfunction goes, it was very versatile in VB6 and did a number of things. In this context, yes, you are correct, it can be replaced withFile.Exists.So your code in C# could look like this: