Results 1 to 9 of 9

Thread: [RESOLVED] File Open Modes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Resolved [RESOLVED] File Open Modes

    Hi all,

    Can someone point me in the right direction? I am trying to find out the 5 modes a file can be opened in.

    I can only think of Input, Read and Shared. What are the other two?

    Thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: File Open Modes

    Input, Output, Random, Append, Binary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Re: File Open Modes

    Thanks - I'll take a look at them

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] File Open Modes

    The answer to your question depends on exactly what it is you are asking. Paul has listed the members of the OpenMode enumeration, which you can provide to control how the FileOpen function opens a file. Is that what you want? If so then Paul's answer is accurate but I would suggest that it's information that is not really of any use to a VB.NET developer anyway.

    The FileOpen function should never be used in new VB.NET code. It should really only ever be used in projects that have been upgraded from VB6 and already contained the equivalent function in VB6. In VB.NET you should be using the members of the System.IO namespace to perform file I/O and those OpenMode values aren't relevant there. System.IO contains various classes and you would use a different one for each different task, e.g. StreamReader for reading text files and StreamWriter for writing text files.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Re: [RESOLVED] File Open Modes

    It was more to do with an assigment and one of the questions was to define the five modes a file can be opened. Given that it is a VB.NET course, and from what I understand from your comments, I should be looking at the System.IO namespace rather than the VB6 equivalent. Is my understanding correct?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] File Open Modes

    Quote Originally Posted by Brent Burgess View Post
    It was more to do with an assigment and one of the questions was to define the five modes a file can be opened. Given that it is a VB.NET course, and from what I understand from your comments, I should be looking at the System.IO namespace rather than the VB6 equivalent. Is my understanding correct?
    It really depends on what the person who wrote the question is looking for. Unless the question actually mentions the FileOpen function, it's a very poor assignment question. I would suggest that you seek clarification from whoever wrote it because, without that specific reference to FileOpen the question is pretty much meaningless. For instance, if you were to call the System.IO.File.Open method then you could specify one of six possible FileMode values, so to say that there are specifically five modes a file can be opened in is simply false... unless you are SPECIFICALLY referring to opening a file with the FileOpen function, which should never be used in VB.NET if it can be avoided and should absolutely, under no circumstances whatsoever, be being taught to students who have no intention of upgrading existing VB6 code. I've been coding in VB.NET since 2003 and I've never once used FileOpen and I intend to never use it. Anyone who is teaching its use to beginners should be ashamed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Re: [RESOLVED] File Open Modes

    Thanks for the info. I'll start digging to find out what he wants.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] File Open Modes

    Sorry to rag on your teacher a bit but I really does bother me when beginners get taught things that they should never be using. Functions like FileOpen have their place but that place is so niche that there really is no point teaching them when there are so many preferable options. Noone who doesn't already know VB6 will ever likely need to use FileOpen so why would it get taught before things like the StreaReader, FileStream and File classes? The fifth version of VB.NET is about to be released and some are still teaching it like it's VB6.1.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Re: [RESOLVED] File Open Modes

    No need to apologise. I would rather get taught something the way it should be, than the way someone used to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width