OpenMode enumeration

N

Nate

This has probably already been addressed (but I can't find a reference
to it in the groups). Tracking down a bug, I found that the OpenMode
Enumeration in both the local and on-line MSDN is incorrect. It's a
problem in .NET 2003; not sure if it has changed since then.

According to the MSDN:

OpenMode.Input specifies file opened for write access
OpenMode.Output specifies file opened for read access

but using this gives an exception: "Valid values for Output mode are
'OpenAccess.Write' and 'OpenAccess.Default'."


To test this, run the following code:

Public Enum FileMode
Write
Read
End Enum

Public Sub OpenFile(ByVal filename As String, ByRef type As
FileMode)
Dim mode As OpenMode
Dim access As OpenAccess
Select Case type
Case FileMode.Read
mode = OpenMode.Input
access = OpenAccess.Read
Case FileMode.Write
mode = OpenMode.Output
access = OpenAccess.Write
End Select

iFileNum = FreeFile()
sFileName = filename
FileSystem.FileOpen(iFileNum, filename, mode, access)
End Sub


I just wanted to get this out there in case it's confused anyone else.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Nate said:
This has probably already been addressed (but I can't find a reference
to it in the groups). Tracking down a bug, I found that the OpenMode
Enumeration in both the local and on-line MSDN is incorrect. It's a
problem in .NET 2003; not sure if it has changed since then.

According to the MSDN:

OpenMode.Input specifies file opened for write access
OpenMode.Output specifies file opened for read access

but using this gives an exception: "Valid values for Output mode are
'OpenAccess.Write' and 'OpenAccess.Default'."


To test this, run the following code:

Public Enum FileMode
Write
Read
End Enum

Public Sub OpenFile(ByVal filename As String, ByRef type As
FileMode)
Dim mode As OpenMode
Dim access As OpenAccess
Select Case type
Case FileMode.Read
mode = OpenMode.Input
access = OpenAccess.Read
Case FileMode.Write
mode = OpenMode.Output
access = OpenAccess.Write
End Select

iFileNum = FreeFile()
sFileName = filename
FileSystem.FileOpen(iFileNum, filename, mode, access)
End Sub


I just wanted to get this out there in case it's confused anyone else.

Yes, the documentation is of course wrong. Input is read and output is
write.

Why are you using the Micosoft.VisualBasic namespace anyway?
 
G

Guest

Göran,

How can you write a Visual Basic program without the Micosoft.VisualBasic
namespace?

Note that I am NOT asking about the Micosoft.VisualBasic.Compatibility
namespace.

Kerry Moorman
 
G

Guest

Perhaps the compiler uses some classes in the dll, but you don't have
to. I am not sure, but it should be able to write a VB.NET program
without even referencing the Microsoft.VisualBasic dll.

There are a few methods in the namespace that may be useful sometimes,
but mostly they are just wrappers around classes in the System
namespace. I recommend that you use the equivalent classes in the System
namespace when available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top