File system error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    File system error

    Hi

    I am getting the 'User defined type not defined' on the line;

    Dim fso As Scripting.FileS ystemObject.

    What am I doing wrong? What reference do I need to add? Do I need to
    install/enable scripting on the win xp sp2 machine?

    Thanks

    Regards



  • RoyVidar

    #2
    Re: File system error

    John wrote in message <OLGolxdGGHA.27 08@TK2MSFTNGP11 .phx.gbl> :[color=blue]
    > Hi
    >
    > I am getting the 'User defined type not defined' on the line;
    >
    > Dim fso As Scripting.FileS ystemObject.
    >
    > What am I doing wrong? What reference do I need to add? Do I need to
    > install/enable scripting on the win xp sp2 machine?
    >
    > Thanks
    >
    > Regards[/color]

    The reference, I think, is Microsoft Scripting Runtime (in VBE - Tools
    |
    References), or try late binding.

    --
    Roy-Vidar


    Comment

    • Douglas J. Steele

      #3
      Re: File system error

      "RoyVidar" <roy_vidarNOSPA M@yahoo.no> wrote in message
      news:mn.7b907d6 173c7027c.33955 @yahoo.no...[color=blue]
      > John wrote in message <OLGolxdGGHA.27 08@TK2MSFTNGP11 .phx.gbl> :[color=green]
      >> Hi
      >>
      >> I am getting the 'User defined type not defined' on the line;
      >>
      >> Dim fso As Scripting.FileS ystemObject.
      >>
      >> What am I doing wrong? What reference do I need to add? Do I need to
      >> install/enable scripting on the win xp sp2 machine?
      >>
      >> Thanks
      >>
      >> Regards[/color]
      >
      > The reference, I think, is Microsoft Scripting Runtime (in VBE - Tools |
      > References), or try late binding.[/color]

      To use Late Binding (which would be my vote if you have to use FSO), you'd
      use

      Dim fso As Object

      Set fso = CreateObject("S cripting.FileSy stemObject")

      Note that when you use Late Binding, any intrinsic constants defined by the
      Scripting library are unavailable to you: you either need to define the
      constants yourself, or replace them by the actual value of the constant. For
      example, you couldn't use:

      Dim fso As Object
      Dim f As Object
      Dim ts As Object

      Set fso = CreateObject("S cripting.FileSy stemObject")
      Set f = fso.GetFile("te st1.txt")
      Set ts = f.OpenAsTextStr eam(ForWriting, TristateUseDefa ult)

      You'd either have to include a line:

      Const ForWriting = 2, TristateUseDefa ult = -2

      or rewrite the code as

      Dim fso As Object
      Dim f As Object
      Dim ts As Object

      Set fso = CreateObject("S cripting.FileSy stemObject")
      Set f = fso.GetFile("te st1.txt")
      Set ts = f.OpenAsTextStr eam(2, -2)

      Are you sure, though, that you need FSO? There's extremely little that FSO
      can do that you can't already do in VBA.


      --
      Doug Steele, Microsoft Access MVP

      (no private e-mails, please)



      Comment

      • John

        #4
        Re: File system error

        I am just trying to read an html file from disk.

        Thanks

        Regards

        "Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message
        news:%2368ka%23 dGGHA.1332@TK2M SFTNGP10.phx.gb l...[color=blue]
        > "RoyVidar" <roy_vidarNOSPA M@yahoo.no> wrote in message
        > news:mn.7b907d6 173c7027c.33955 @yahoo.no...[color=green]
        >> John wrote in message <OLGolxdGGHA.27 08@TK2MSFTNGP11 .phx.gbl> :[color=darkred]
        >>> Hi
        >>>
        >>> I am getting the 'User defined type not defined' on the line;
        >>>
        >>> Dim fso As Scripting.FileS ystemObject.
        >>>
        >>> What am I doing wrong? What reference do I need to add? Do I need to
        >>> install/enable scripting on the win xp sp2 machine?
        >>>
        >>> Thanks
        >>>
        >>> Regards[/color]
        >>
        >> The reference, I think, is Microsoft Scripting Runtime (in VBE - Tools |
        >> References), or try late binding.[/color]
        >
        > To use Late Binding (which would be my vote if you have to use FSO), you'd
        > use
        >
        > Dim fso As Object
        >
        > Set fso = CreateObject("S cripting.FileSy stemObject")
        >
        > Note that when you use Late Binding, any intrinsic constants defined by
        > the Scripting library are unavailable to you: you either need to define
        > the constants yourself, or replace them by the actual value of the
        > constant. For example, you couldn't use:
        >
        > Dim fso As Object
        > Dim f As Object
        > Dim ts As Object
        >
        > Set fso = CreateObject("S cripting.FileSy stemObject")
        > Set f = fso.GetFile("te st1.txt")
        > Set ts = f.OpenAsTextStr eam(ForWriting, TristateUseDefa ult)
        >
        > You'd either have to include a line:
        >
        > Const ForWriting = 2, TristateUseDefa ult = -2
        >
        > or rewrite the code as
        >
        > Dim fso As Object
        > Dim f As Object
        > Dim ts As Object
        >
        > Set fso = CreateObject("S cripting.FileSy stemObject")
        > Set f = fso.GetFile("te st1.txt")
        > Set ts = f.OpenAsTextStr eam(2, -2)
        >
        > Are you sure, though, that you need FSO? There's extremely little that FSO
        > can do that you can't already do in VBA.
        >
        >
        > --
        > Doug Steele, Microsoft Access MVP
        > http://I.Am/DougSteele
        > (no private e-mails, please)
        >
        >
        >[/color]


        Comment

        • Douglas J. Steele

          #5
          Re: File system error

          No reason for FSO then. The following VBA code will read a file line by line
          into variable strBuffer.

          Dim intFile As Integer
          Dim strBuffer As String
          Dim strFile As String

          strFile = "C:\My Folder\MyFile.h tml"

          intFile = FreeFile()
          Open strFile for Input As #intFile
          Do While Not EOF(intFile)
          Line Input #intFile, strBuffer
          ' strBuffer now contains a line of data: work with it

          Loop

          Close #intFile

          --
          Doug Steele, Microsoft Access MVP

          (no private e-mails, please)


          "John" <John@nospam.in fovis.co.uk> wrote in message
          news:WaCdnWvLDP 5V4VfeRVny1A@pi pex.net...[color=blue]
          >I am just trying to read an html file from disk.
          >
          > Thanks
          >
          > Regards
          >
          > "Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message
          > news:%2368ka%23 dGGHA.1332@TK2M SFTNGP10.phx.gb l...[color=green]
          >> "RoyVidar" <roy_vidarNOSPA M@yahoo.no> wrote in message
          >> news:mn.7b907d6 173c7027c.33955 @yahoo.no...[color=darkred]
          >>> John wrote in message <OLGolxdGGHA.27 08@TK2MSFTNGP11 .phx.gbl> :
          >>>> Hi
          >>>>
          >>>> I am getting the 'User defined type not defined' on the line;
          >>>>
          >>>> Dim fso As Scripting.FileS ystemObject.
          >>>>
          >>>> What am I doing wrong? What reference do I need to add? Do I need to
          >>>> install/enable scripting on the win xp sp2 machine?
          >>>>
          >>>> Thanks
          >>>>
          >>>> Regards
          >>>
          >>> The reference, I think, is Microsoft Scripting Runtime (in VBE - Tools |
          >>> References), or try late binding.[/color]
          >>
          >> To use Late Binding (which would be my vote if you have to use FSO),
          >> you'd use
          >>
          >> Dim fso As Object
          >>
          >> Set fso = CreateObject("S cripting.FileSy stemObject")
          >>
          >> Note that when you use Late Binding, any intrinsic constants defined by
          >> the Scripting library are unavailable to you: you either need to define
          >> the constants yourself, or replace them by the actual value of the
          >> constant. For example, you couldn't use:
          >>
          >> Dim fso As Object
          >> Dim f As Object
          >> Dim ts As Object
          >>
          >> Set fso = CreateObject("S cripting.FileSy stemObject")
          >> Set f = fso.GetFile("te st1.txt")
          >> Set ts = f.OpenAsTextStr eam(ForWriting, TristateUseDefa ult)
          >>
          >> You'd either have to include a line:
          >>
          >> Const ForWriting = 2, TristateUseDefa ult = -2
          >>
          >> or rewrite the code as
          >>
          >> Dim fso As Object
          >> Dim f As Object
          >> Dim ts As Object
          >>
          >> Set fso = CreateObject("S cripting.FileSy stemObject")
          >> Set f = fso.GetFile("te st1.txt")
          >> Set ts = f.OpenAsTextStr eam(2, -2)
          >>
          >> Are you sure, though, that you need FSO? There's extremely little that
          >> FSO can do that you can't already do in VBA.
          >>
          >>
          >> --
          >> Doug Steele, Microsoft Access MVP
          >> http://I.Am/DougSteele
          >> (no private e-mails, please)
          >>
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...