PDA

Click to See Complete Forum and Search --> : What's wrong with Open "filename" for input as #1 ?


Al Smith
Jan 15th, 2000, 03:24 AM
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:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

r0ach
Jan 15th, 2000, 03:31 AM
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)

Juan Carlos Rey
Jan 15th, 2000, 09:12 AM
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).]

r0ach
Jan 15th, 2000, 09:20 AM
freefile sux anyway. I just opened 2 files with freefile, and both files were assigned a 1!

So i got an error :(

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

Jan 15th, 2000, 08:20 PM
freefile works every time, you must have been doing it wrong.

this is the proper way of using freefile...


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: wossnamex@talk21.com :)


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

Al Smith
Jan 15th, 2000, 09:57 PM
Ok. How would I use FreeFile in the following:

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.

Jan 16th, 2000, 12:51 AM
Al, Like this.....



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: wossnamex@talk21.com :)

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

Al Smith
Jan 16th, 2000, 01:19 AM
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:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

Juan Carlos Rey
Jan 16th, 2000, 09:51 AM
And nobody mention GoTo!

Al Smith
Jan 16th, 2000, 10:28 AM
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:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

Gumppy
Jan 16th, 2000, 10:47 AM
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.

chrisjk
Jan 16th, 2000, 11:23 AM
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
chris.kilhams@btinternet.com
If it ain't broke - don't fix it :)

Maartin
Jan 16th, 2000, 04:15 PM
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
dinamite@onwe.co.za
-----------------------

ivyl
Jan 17th, 2000, 05:54 PM
What's wrong with sloppy programming??? ;-)