opening a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manontheedge
    New Member
    • Oct 2006
    • 175

    opening a file

    how do you open a file in VB6?

    I understand how to write to a file and read a file, but I just want the file to open for viewing.

    (I'd like to be able to choose the file from within the code, so a list box won't work for what I'm wanting to do)
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by manontheedge
    how do you open a file in VB6?
    I understand how to write to a file and read a file, but I just want the file to open for viewing.
    (I'd like to be able to choose the file from within the code, so a list box won't work for what I'm wanting to do)
    That depends on what you mean by "open for viewing". There's no magic "view file" statement. If you want to get the contents of the file on-screen, you need to put them there. A couple of relatively simple ways that come to mind are:
    • Use Shell statement to open Notepad to display it
    • Open it for reading and copy the contents into a TextBox control (make sure you set Multiline property to True)
    • Open it for reading and copy the contents into a RichTextBox control
    • Come up with your own variation

    Not sure what you mean about the list box.

    Comment

    • manontheedge
      New Member
      • Oct 2006
      • 175

      #3
      by "list box" I meant a box that displays files that are on your computer. ...I've had to learn a lot of Visual Basic in a short period of time, so whenever I get stuck I flip through this book I have, and that's the only way it showed to open files ...it basically lists what files exist, and you select the file you want, but the way that's done in the book won't work for what I'm trying to do. (hopefully that makes sense)

      anyway, I'm not exactly sure what type of file I'll need to be opening. It could be Access files or text files or some other form of data file.

      I believe I've written code in C++ that opens an existing text file and displays it on the screen. (I could be wrong...now I'm not so sure)

      but, anyway, it's not data that needs to be changed or appended to. I just need to open the files. It seems like there should be a way to do it. I actually have done it with excel files, but that was specifically for opening excel sheets.

      what I have is a program with a lot of data. The file names are contained at various places in the data. So, I want to put all of that data together, and basically say, "open this file".

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by manontheedge
        ...what I have is a program with a lot of data. The file names are contained at various places in the data. So, I want to put all of that data together, and basically say, "open this file".
        Yes, but the question still remains - what, precisely, do you mean by "open" in this context. The word can mean quite different things.

        In Visual Basic, to "open" a file means to set up various pointers and buffers so that your program can access and/or modify the data contained in the file and, depending on the options specified, prevent others from accessing and/or modifying the file. This is achieved by use of the Open statement. These options remain in effect until you close the file.

        If you mean something else, then please be precise.

        Comment

        • manontheedge
          New Member
          • Oct 2006
          • 175

          #5
          Sorry for the confusion.

          Okay, I want to be able to insert into my code something like...

          "example.tx t" or "example.da t"

          as a file to be opened.

          I don't want visual basic to do ANYTHING other than open the file. Basically, I'm looking to write some code that will keep me from having to go through file directories looking for a file.

          for example, if I'm looking for "example.tx t", I would have to go to "C:" then "C\Document s and Settings" ...and so on.

          I want a program that will find this file (I will have the exact location of the file determined in the program), and I want this file to simply open on the screen.

          So, this program (in VB) will simply locate a file on my computer and open it. Once the file is opened, VB will be done. Then the user can do whatever they want with the file that was opened.

          hopefull this makes sense. Thanks for bearing with me.

          Comment

          • frherndon
            New Member
            • Aug 2006
            • 1

            #6
            Hello on regards to Opening a File.

            I have created (from VB inside ACCESS) a tblDir that Displays in a MS-ACCESS table. I would also like to click on a line item of the items displayed and then open the associated program to display (read/write, etc) the file. E.g., ADOBE for PDF, MSWord for *.DOC, viewer for *.TIF and so on. Any suggestions or help. I'm up through the tblDir display in an ACCESS form.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              I believe both of you should do a search for information on the FindExecutable API.

              Comment

              Working...