Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Visual Basic Sequential File IO

Visual Basic Sequential File IO

Scheduled Pinned Locked Moved Visual Basic
questioncomhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Red Sunday
    wrote on last edited by
    #1

    First off, I have found some articles on the MSDN website that have pointed me in the right direction but don't have all the answers. Also, I am using Visual Basic 6.0. I need to be able to access a file and do a couple of things with it: 1) I need to find out if it exists and if not, then create it. I found System.IO.File.Exists("c:\ExistingFileName") but I get an error. I believe this error is due to the fact that I have not told the compiler I am using the system namespace. How do you signal the compiler you are using the System namespace in Basic? In C it would be using System.IO.File, but I have no clue in Basic.:confused: 2) What is the command to create a sequential file in Basic and what variable will I have access to? 3) How do I add to it/ close it when I am done? Thank you, Zach Calvert ----------------- http://www.zachcalvert.com

    A 1 Reply Last reply
    0
    • R Red Sunday

      First off, I have found some articles on the MSDN website that have pointed me in the right direction but don't have all the answers. Also, I am using Visual Basic 6.0. I need to be able to access a file and do a couple of things with it: 1) I need to find out if it exists and if not, then create it. I found System.IO.File.Exists("c:\ExistingFileName") but I get an error. I believe this error is due to the fact that I have not told the compiler I am using the system namespace. How do you signal the compiler you are using the System namespace in Basic? In C it would be using System.IO.File, but I have no clue in Basic.:confused: 2) What is the command to create a sequential file in Basic and what variable will I have access to? 3) How do I add to it/ close it when I am done? Thank you, Zach Calvert ----------------- http://www.zachcalvert.com

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      here a sample http://www.andreavb.com/forum/news/viewtopic.php?TopicID=1485

      R 1 Reply Last reply
      0
      • A Anonymous

        here a sample http://www.andreavb.com/forum/news/viewtopic.php?TopicID=1485

        R Offline
        R Offline
        Red Sunday
        wrote on last edited by
        #3

        it doesn't use the system namespace. I am using this for a school project and I must use the system namespace. Also, it only reports error codes. I need to be able to check to see if it exists, not catch errors. ----------------- http://www.zachcalvert.com

        D 1 Reply Last reply
        0
        • R Red Sunday

          it doesn't use the system namespace. I am using this for a school project and I must use the system namespace. Also, it only reports error codes. I need to be able to check to see if it exists, not catch errors. ----------------- http://www.zachcalvert.com

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          The System.IO namespace contains the File class. This class contains the shared .Exists method you use to check to see if the filename exists, prefferable using the FULL PATH to the file. .Exists isn't documented to throw any exceptions. It just returns True or False. In a normal installation of Visual Studio .NET or Visual Basic.NET, the System namespace is automatically imported into your project. You don't have to use the Imports System statement at the top of your code because it's already done behind the scenes. You DO, on the other hand, have to put in the Imports System.IO yourself, again, at the top of your code.

          Imports System.IO
           
          Public Class Form1
          .
          .
          .
          Private Sub WhatEver()
          ' You don't nedd to specify the System.IO namespace prefix because you
          ' already Imported it at the top of your code.
          If File.Exists("C:\myTestFile.txt") Then
          .
          .
          .

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          R 1 Reply Last reply
          0
          • D Dave Kreskowiak

            The System.IO namespace contains the File class. This class contains the shared .Exists method you use to check to see if the filename exists, prefferable using the FULL PATH to the file. .Exists isn't documented to throw any exceptions. It just returns True or False. In a normal installation of Visual Studio .NET or Visual Basic.NET, the System namespace is automatically imported into your project. You don't have to use the Imports System statement at the top of your code because it's already done behind the scenes. You DO, on the other hand, have to put in the Imports System.IO yourself, again, at the top of your code.

            Imports System.IO
             
            Public Class Form1
            .
            .
            .
            Private Sub WhatEver()
            ' You don't nedd to specify the System.IO namespace prefix because you
            ' already Imported it at the top of your code.
            If File.Exists("C:\myTestFile.txt") Then
            .
            .
            .

            RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            R Offline
            R Offline
            Red Sunday
            wrote on last edited by
            #5

            I'm using VB 6.0, and it doesn't let me do Imports System.IO What do I do now? ----------------- http://www.zachcalvert.com

            D 1 Reply Last reply
            0
            • R Red Sunday

              I'm using VB 6.0, and it doesn't let me do Imports System.IO What do I do now? ----------------- http://www.zachcalvert.com

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              OK. Then throw out EVERYTHING about namespaces and System, System.IO, File.Exists... EVERYTHING. VB.NET is a VERY different language from VB6 and none of this stuff applies to VB6. Now, you'll have to use the FileSystemObject to see if the specified file exists. This will return either True or False, it doesn't throw any errors.

              Set fs = CreateObject("Scripting.FileSystemObject")
              If fs.FileExists("C:\\myTestFile.txt") Then
                  .
                  . ' The file exists...
                  .
              Else
                  .
                  . ' The file doesn't exist...
                  .
              End If
              

              To open a text file for sequential write, you'll use the Open statement (docs here[^]):

              Open "C:\\myTestFile.txt" For Output As #1
              Print #1, "This is line 1"
              Print #1, "This is line 2..."
              Print #1, "This is line 3..."
              Close #1
              

              RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups