views:

1807

answers:

3

I can do this:

Dim fso As New FileSystemObject

or I can do this:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

How do I know what string to use for CreateObject? For example, how would I know to use the "Scripting." part of "Scripting.FileSystemObject"? Where do you go to look that up?

+12  A: 

It is the ProgID of the component which is registered in Windows registry under HKCR key:

HKEY_CLASSES_ROOT\Scripting.FileSystemObject

ProgID's are human readable identifiers for COM objects. They point to the actual CLSIDs, which in this case is:

HKEY_CLASSES_ROOT\CLSID{0D43FE01-F093-11CF-8940-00A0C9054228}

This is the place where you can find the actual COM .dll that includes the implementation of the component.

In the first sample code you have provided you are doing an early-binding, and in the second one you are doing a late-binding.

huseyint
A: 

I would start by searching for FileSystemObject in the MSDN library at http://msdn.microsoft.com/library

The site is chock full of documentation, including the details of how to call CreateObject.

Ed
+1  A: 

Using the VB6 IDE, choose Project, References, then to pick the reference 'Microsoft Scripting Runtime'.

If you didn't know what the reference is called, you could use the References dialog's Browse button to pick the file /system 32/scrrun.dll.

With the reference chosen, close the References dialog then open the Object Browser (View menu). Change the dropdown to the most likely candidate, being 'Scripting'. This will reveal the library's classes, one of which is 'FileSystemObject'. Hence, you will have discovered the the string required for CreateObject is 'Scripting.FileSystemObject'.

If you didn't know the Reference name or the file name but you did know the class name then you could search the registry for "FileSystemObject" and it should soon be revealed that the fully-qualified name you require is 'Scripting.FileSystemObject'.

onedaywhen