DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    293

    Understanding Open xxx For Input As #6

    I am using an Open xxx For Input As #6 to open and read in some text.
    The code I have works fine when I use it in a program where it is the only code in the program. (I did this to test it out) However when I insert it into a larger program my input is not correct. Can't say where it's comming from.

    I've checked out my path and it's good. However I do not under stand the number 6 and it's roll in this. I suspect this needs to be a number not used, and someplace in my larger program it must be used for something else. This is the only "Open xxx For Input As" I have in the program.
    My code is:

    Dim TheText As String
    Dim j As Integer, i As Integer
    Open "O:\14211\Calibration support software\ML2530\sensor CF data\Asset 54815.rtf" For Input As #6
    Line Input #6, TheText 'read in the the header info
    For i = 1 To 10
    Line Input #6, TheText 'read in the data line into a string
    MsgBox "" + TheText
    DoEvents
    Next
    Close #6

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    You got it right, that number must be unique: use the FreeFile function:

    int fileno
    fileno = FreeFile
    Open ..... As #fileno

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  3. #3
    Join Date
    Nov 2004
    Posts
    293
    you also provided me with something new

    the "int fileno", I take it thats a way of saying "Dim fileno as Interger" ?

    speeking of that, If I use "Dim sA, sB, sC as string" are all three going to be strings?

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    whoops, sorry, int fileno(;) is a C syntax, I meant dim fileno as integer

    Dim a, b, c as String

    declares c as string, and a and b as Variant. in VB every variable must be explicetly declared, otherwise is a Variant. For example,
    dim C
    is a valid syntax, that declares C and assigns to it the default type (Variant)

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  5. #5
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    What error are you getting? If you already have '6' open you would get error 55 - File already open' when you tried to open it again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links