Hi all,
I don't want to bloat the water cooler anymore than what it is but I thought this may be a cool thread to start for those of us that like to learn and understand what we are learning. Hence the title Explain This??!
To start, can someone explain this:
More specifically, what does fnum represent and why use # before it?fnum = FreeFile() num = num2 - 1 Open sName For Output As fnum For x = 1 To num Write #fnum, saveString(x) Next x Close #fnum
Please leave a message after the beep!
To quote the help:This saves you having to keep track of what file numbers you may already have used."FreeFile Function: Returns an Integer representing the next file number available for use by the Open statement."
In this case:
fnum = FreeFile()
The next free file number is assigned to the variable fnum which is then used to open the file to write to it.
I'm not sure why the # is there, I suspect it is just to indicate an integer variable.
Regards
In file I/O, files are represented by Integer types. FreeFile() is a function which returns the next available file number (between 1 to 511) which can be used with the Open statement.
The # convention is inherited from older versions of basic. Note that in this case it does not represent a Double!
Thanks for that guys, if tipping your scales meant anything in the Water Cooler I would do it.
Please leave a message after the beep!
To learn what freefile does:
Most of the time I close a file that has been opened with 'Open' before I open another one.Sub tst() MsgBox FreeFile MsgBox FreeFile Open "E:\of\aa.txt" For Input As 1 MsgBox FreeFile c01 = Input(LOF(1), 1) Close End Sub
In that case the only code I need is:
andSub tst() Open "E:\of\aa.txt" For Input As 1 c01 = Input(LOF(1), 1) Close End Sub
Instead of reading line by line using 'read' use Input(LOF(1),1) to read the whole filecontent in 1 go.Sub tst() Open "E:\of\aa.txt" For Output As 1 Print 1,c01 Close End Sub
Instead of writing line by line using 'write' use Print to write the whole content into the file in 1 go.
PS. I wouldn't object seeing this kind of question in the Excel programming subforum. (seems even more appropriate to me)
Last edited by snb; 06-03-2011 at 09:43 AM.
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
Other than the title, what would have gotten you into trouble?
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
LoL, I don't know but so far I haven't received any infractions from you good people and I don't want any! Also, the title is allowed in the water cooler so....
Please leave a message after the beep!
Well.. there is a rule about posting in the relevant forum...could get you there![]()
anyways... just kidding....
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
At least for me, maybe the title is allowed, but a proper title would give those surfers a glimpse into what's in the thread
Thoughts to consider...
HTH
Regards, Jeff
If you like the answer(s) provided, why not add some reputation by clicking the * below
Please use [ Code ] tags when posting [ /Code ]
Please view/read the Forum rules --- How to mark a thread as solved
What is the definition of a Sticky thread? I see those in the regular forums, do scale taps count there?
Please leave a message after the beep!
See: Sticky Threads
It's usually used for threads that mods and admin want not to get lost in the haystack and are considered very useful or important threads.
I think scales works there... but not 100% sure.. RoyUK should be able to answer that...
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
@NBVC We can test the scales in sticky threads. submit something in the sticky thread in the Programming part of the forum and I'll tap your scales.
Please leave a message after the beep!
There is a sticky thread there called "Thanks for all the help". Tip the original OP's scales on the very first post.... and then let me know when done, and I can check if he got the points.
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks