Results 1 to 11 of 11
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileSystemObject first step... (2000 sr 1)

    Long code fragment (over 5000 characters) moved to attachment by HansV

    I have this macro it import a value from a txt file and put it in sheet and in MDB. (Tks great Hans for this!)
    I would wont to import the same value to use the file systemobject and not:

    vFile = ("C:EPFL0785.EPF")
    Open vFile For Input As #1

    is possible?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSystemObject first step... (2000 sr 1)

    Yes, it is possible, but the "old" instructions are generally a lot faster than using FileSystemObject, so why do you want to change?

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSystemObject first step... (2000 sr 1)

    Hi, Hans...
    2 reason.

    1) to undestand how the file system object work
    2) Because i would want to transform theis macro in to a ASP script for server apllication.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSystemObject first step... (2000 sr 1)

    The basic idea is like this. I declared fso and fil as Objects, so that you don't have to set a reference to the Scripting Runtime library. (You can't set a reference in ASP)

    ' Declare object variables
    Dim fso As Object
    Dim fil As Object

    ' Create the filesystemobject and open the text file
    Set fso = CreateObject("Scripting.FileSystemObject")
    vFile = "C:EPFL0785.EPF"
    Set fil = fso.OpenTextFile(vFile)

    ' Loop through the lines of the text file
    Do While Not fil.AtEndOfStream
    ' Read a line into RIGA
    RIGA = fil.ReadLine
    ' Code to process the line goes here
    ...
    Loop

    ' Close the text file and clear the variables
    fil.Close
    Set fil = Nothing
    Set fso = Nothing

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSystemObject first step... (2000 sr 1)

    Great Hans, but in old macro i use this instruction:

    If Not EOF(1) Then

    Line Input #1, RIGA

    With trhe new FSO instruction wath the correspondent?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSystemObject first step... (2000 sr 1)

    <table border=1><td>Old</td><td>New</td><td>While Not EOF(1)</td><td>Do While Not fil.AtEndOfStream</td><td>Line Input #1, RIGA</td><td>RIGA = fil.ReadLine</td></table>

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please read ALL!!!!!!

    NATURALLY IT WORK EXACLTY FOR ME...

    Official Tks to Hans, for me the wizard of www.!!!!:-)
    I have visited for 1 month the solution on the web, believe me, Hans have make for me a solution in one minute, no have error with the first test!

    only a dubt:
    This isntruction --- Line Input #1, RIGA --- in my old macro skip the line and go to the next is the same for FSO RIGA.skip
    or i am confused about FSO?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Please read ALL!!!!!!

    The instructions

    Line Input #1, RIGA

    and

    RIGA = fil.ReadLine

    both read one line of the text file into the variable RIGA and move to the next line of the text file, so that if you execute the instruction again, you will read the next line, not the same line. You would only need fil.SkipLine if you want to move to the next line without reading it.

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please read ALL!!!!!!

    CLEAR....!

    A stupid request.
    I have tell me abiut the speed import and wath is the difference from 2 metod to import a value from a txt file...
    But is possible to show a msbox with a time of elaboration after the macro is finished, in this mode i compare a time of work.

    Remember is only a stupid request

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Please read ALL!!!!!!

    In the first place, you will only notice the difference if you process VERY large files, or if you process very MANY files. For many applications, the speed difference will be negligeable.

    If you would like to measure execution time, you could do it like this:

    Dim t As Single
    t = Timer
    ' code to import a text file goes here
    ...
    t = Timer - t
    MsgBox "Execution took " & t & " seconds

    In the last post in the thread starting at <post#=451205>post 451205</post#>, you'll find a speed comparison for a VERY large file.

  11. #11
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please read ALL!!!!!!

    Yes. i have see the post you suggest me, you must know, i import a txt file of 86mb(!) every day...
    I compare tomorrow (with you test time) the difference, when the external procedure make a new file...
    Tks for all.

Posting Permissions

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