create object issue

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-05-01
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.

Question by:grenutze
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 43

Expert Comment

ID: 8026012
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
Set fils = Nothing
Set fldr = Nothing
Set fso = Nothing

Expert Comment

ID: 8027959
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.

Accepted Solution

drorga earned 90 total points
ID: 8063896
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question