Results 1 to 14 of 14

Thread: What's wrong with Open "filename" for input as #1 ?

  1. #1

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Opening files as #1, #2, etc. is a habit I have from Dos Basic days, but I see a lot of mention against doing this.
    Why?

    Thanks,
    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    You know Al, I also use #1, #2, etc. all the time, but i just got moaned at for doing that, so i now use freefile in the forum, until someone can tell ME why it should be different!

    ------------------
    r0ach(tm)

  3. #3
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    By the way, what's wrong with "Go To"?
    Bad habits are hard to extirpate!
    I personally don't think it to be bad if you open a file as #1, read or write
    and close it right before any damage can be done.

    [This message has been edited by Juan Carlos Rey (edited 01-15-2000).]

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    freefile sux anyway. I just opened 2 files with freefile, and both files were assigned a 1!

    So i got an error

    ------------------
    r0ach(tm)

  5. #5
    Guest

    Post

    freefile works every time, you must have been doing it wrong.

    this is the proper way of using freefile...

    Code:
    dim MyFile as byte
    MyFile = freefile
    open "AnyFile.txt" for output as #Myfile
    'do your stuff here
    close #Myfile
    Freefile is a safeguard against damaging files opened in another app.

    the thing to remember is that every time you try to open another file (i.e. 2 at once) you need to change the name of the variable to something else, and then make it equal to freefile. The internal freefile value increments by one every time you open a file. and decrements every time a file closes.

    you cannot say that it "sux" simply because you lack the programming ability to make it work. if you dont know what your talking about, why are you deliberately misleading people?

    ------------------

    Wossname,
    Email me: [email protected]


    [This message has been edited by wossname (edited 01-16-2000).]

  6. #6

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Ok. How would I use FreeFile in the following:

    Code:
    Open"c:\Daily Transactions" for input as #1
    Open"c:\Warehouse Transfers" for Append as #2
    Open"c:\Warehouse Scrapped" for Append as #3
    While Not EOF(1)
    Line Input#1,strTransaction
    If Left(strTransaction,8) = "Transfer" then
    Print#2,strTransaction
    ElseIf Left(strTransaction,8) = "Scrapped" then
    Print#3,strTransaction
    end If
    Wend
    Close
    Thanks,
    Al.


  7. #7
    Guest

    Post

    Al, Like this.....

    Code:
    dim MyTransacts as byte
    dim MyTransfers as byte
    dim MyScrapped as byte
    
    MyTransacts = Freefile
    Open "c:\Daily Transactions" for input as #MyTransacts
    
    MyTransfers = freefile
    Open "c:\Warehouse Transfers" for Append as #MyTransfers
    
    MyScrapped = freefile
    Open "c:\Warehouse Scrapped" for Append as #MyScrapped
    
    While Not EOF(MyTransacts)
    Line Input #MyTransact, strTransactionIf Left(strTransaction, 8) = "Transfer" then
    Print #MyTransfers, strTransaction
    ElseIf Left(strTransaction, 8) = "Scrapped" then
    Print #MyScrapped, strTransaction
    end If
    Wend
    Close #MyTransacts, #MyTransfers, #MyScrapped
    PS. always name the files that you want to CLOSE like i did above


    Hows that?

    ------------------

    Wossname,
    Email me: [email protected]

    [This message has been edited by wossname (edited 01-16-2000).]

  8. #8

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Ok. I'll accept that. I do see the benifit of FreeFile considering the number of files that VB will allow you to open.
    Just for the heck of it, I popped into my old QB program and, Lo and Behold, FreeFile was a function in QB. I didn't know this.
    Thanks,
    Al.



    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  9. #9
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    And nobody mention GoTo!

  10. #10

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    I do remember that goto was frowned upon in Dos Basic circles. The theory was that it was the result of sloppy program structure.
    Unless someone cares to differ, I think that it is now an accepted way to branch to another part of a program.
    e.g. On Error GoTo...

    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  11. #11
    Member
    Join Date
    Nov 1999
    Posts
    33

    Post

    I agree, that goto is a form of sloppy programming and for a loops u should use either a do or a for loop. Just some programming etticut i guess.

  12. #12
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    It may be sloppy programming Gumppy, but what about your sloppy spelling ?...

    "Etiquette..."

    I use GoTo whenever I feel like it. Sod style - if it works who cares!

    Amused regards,

    ------------------
    - Chris
    [email protected]
    If it ain't broke - don't fix it

  13. #13
    Lively Member Maartin's Avatar
    Join Date
    Jan 2000
    Location
    Benoni, Gauteng, South-Africa
    Posts
    99

    Post

    Well surprise for all of you try and read somebody’s code that was done in QBasic, gwBasic or VB and it is a nightmare with keeping the current code functionality in mind and then have to jump to 10 different places in code and still trying to keep track of what this person was trying to achieve. Believe me, what makes it even worse if they used really stupid names for
    Variables etc. I have been there and it is hell.

    You might not feel it because you wrote the code and know what you were trying to do where. But the other people who have to find errors and bugs in your program will be cursing
    for the next 3 hours solid.

    Yes to an extend I agree, I use goto on error handlers and I use gosub’s but only when there is now way out of the situation.


    ------------------
    -----------------------
    Maartin
    [email protected]
    -----------------------

  14. #14
    Junior Member
    Join Date
    Jan 2000
    Posts
    21

    Post

    What's wrong with sloppy programming??? ;-)

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