Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

create object issue

I am using FileSystemObject , Folder, File , Folders , Files classes.
when i try to make instance of all of those class execpt FileSystemObject V.B 6 make a error.
I don't want to use the Refences - Microsoft Scripting Runtime.
Should i declare of those classes as object or variant ?
Should i use :
  set folder_x = FileSystemObject_x.GetFolder(x)
  set files_x = folder_x.files
  SET files_x = Nothing

Can you tell me how do I use it ? .

Thank you for your time.


0
grenutze
Asked:
grenutze
1 Solution
 
TimCotteeCommented:
FileSystemObject is the only object that can be directly instantiated. If you are trying to use this without setting a reference then you should use this methodology:

Dim fso As Object
Dim fldr As Object
Dim fils As Object
Dim fil As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("c:\")
Set fils = fldr.Files
For Each fil In fils
  Msgbox fil.Name
Next
Set fils = Nothing
Set fldr = Nothing
Set fso = Nothing
0
 
merphieCommented:
You can make a reference to the FileScripting object and this will give you the option of declaring the variables directly.  Or you can use the object declaration.    If you use a reference just don't included the FileSystem DLL in the setup package.
0
 
drorgaCommented:
The reason CreateObject isn't being used for file,files,folder,folders class is that CreateObject  function creates and returns a reference to a COM object.
CreateObject cannnot be useed to create instance of classes in Visual Basic unless those classes are explicitly exposed as COM components.

In order to know if you create the object in the right way you can make a reference to the FileScripting object, and then you are only exposed to the permitted used of the object.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now