+ Reply to Thread
Results 1 to 15 of 15

Thread: Explain This??

  1. #1
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Explain This??

    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:
    fnum = FreeFile()
        num = num2 - 1
        Open sName For Output As fnum
        For x = 1 To num
        Write #fnum, saveString(x)
        Next x
        Close #fnum
    More specifically, what does fnum represent and why use # before it?
    Please leave a message after the beep!

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,256

    Re: Explain This??

    To quote the help:
    "FreeFile Function: Returns an Integer representing the next file number available for use by the Open statement."
    This saves you having to keep track of what file numbers you may already have used.

    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

  3. #3
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Explain This??

    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!
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  4. #4
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Re: Explain This??

    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!

  5. #5
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Explain This??

    To learn what freefile does:

    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
    Most of the time I close a file that has been opened with 'Open' before I open another one.

    In that case the only code I need is:
    Sub tst()
      Open "E:\of\aa.txt" For Input As 1
        c01 = Input(LOF(1), 1)
      Close
    End Sub
    and
    Sub tst()
      Open "E:\of\aa.txt" For Output As 1
        Print 1,c01
      Close
    End Sub
    Instead of reading line by line using 'read' use Input(LOF(1),1) to read the whole filecontent in 1 go.

    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.



  6. #6
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,649

    Re: Explain This??

    Quote Originally Posted by Mordred View Post
    Thanks for that guys, if tipping your scales meant anything in the Water Cooler I would do it.
    I think this would have been good for the general programming forum... obviously with a more suitable title
    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.

  7. #7
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Re: Explain This??

    Quote Originally Posted by NBVC View Post
    I think this would have been good for the general programming forum... obviously with a more suitable title
    Well, you're a mod boss and can move it! I didn't want to start this thread anywhere else because I didn't want to get into trouble from the mods.
    Please leave a message after the beep!

  8. #8
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,649

    Re: Explain This??

    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.

  9. #9
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Re: Explain This??

    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!

  10. #10
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,649

    Re: Explain This??

    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.

  11. #11
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,581

    Re: Explain This??

    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

  12. #12
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Re: Explain This??

    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!

  13. #13
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,649

    Re: Explain This??

    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.

  14. #14
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,281

    Re: Explain This??

    @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!

  15. #15
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,649

    Re: Explain This??

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.2.0