Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Object constants (2002 SP3)

    According to the help, there are various defined constants for File Objects, but when I tried to use them I kept getting told that I was incorrectly calling the function. I eventually traced it to the fact that the constants did not seem to have any values.

    For example

    in Set ts = fs.OpenTextFile(temp_file, ForReading, False)

    ForReading has no value.

    Isthere something special that I am supposed to do to ensure that these constants (ForReading, ForAppending, TristateUseDefault, TristateTrue, TristateFalse), get populated?

    TIA

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: File Object constants (2002 SP3)

    Hi Paul,
    Have you set a reference to the relevant scripting library (e.g the Scripting Runtime)? If not, then you cannot use these constants as they are not defined in other libraries.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Object constants (2002 SP3)

    Thanks, that's the sort of information I was looking for.

    But if I didn't have the reference (which I didn't) how come the objects and methods worked?

    And where should I have looked to tell me that I needed to include this reference?

    TIA

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: File Object constants (2002 SP3)

    If you declared the objects as Object and created them using CreateObject (late binding) then it will work without the reference. If you tried to use Dim fs as FileSystemObject that should not have worked. I would also imagine you did not get the Intellisense help for properties and methods? If you look up Late vs Early binding in a good VBA book, it will explain the differences. In this case, you could have carried on the way you were but you would have to substitute the constant names for actual values - e.g. -2 instead of TriStateMixed.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Object constants (2002 SP3)

    Thanks Rory, that's exactly what I needed to know.

    Pity the help doesn't mention this.

    I'm deeply in your debt.

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: File Object constants (2002 SP3)

    What is the value of TriStateFalse?

    I am getting a compile error now after I changed a reference. I cannot remember the reference. Help.

  7. #7
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: File Object constants (2002 SP3)

    Based on Googling tristatefalse value and just glancing at the page of hits, I'd say it's 0.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: File Object constants (2002 SP3)

    Thanks for that, I had already found out from one of Rory's posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •