Solved Problem When Instantiate a Folder Object From Scripting.FileSystemObject (1 Viewer)

ADIGA88

Member
Local time
Today, 19:08
Joined
Apr 5, 2020
Messages
32
I am trying to instantiate a folder object to list the files inside a specified folder through GetFolder Menod of "Scripting.FileSystemObject" object, and it's returning a string instead of a Folder object!

Attached:
1. a screenshot of the code and its debugging output.
2. a screenshot of the MS Access doc page for Scripting.FileSystemObject object.

The link to MS Access doc:


The Code I am running that shoud retrun a Folder object:
Code:
Option Compare Database
Option Explicit


Dim fs As Object ' File system object
Dim f As Object  ' Folder Object
Dim s As Object  ' For later user

Sub ShowFolderInfo()
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    Set f = fs.GetFolder(fs.GetAbsolutePathName("C:\Dell"))
    Debug.Print "VarType fs is " & VarType(fs)
    Debug.Print "VarType f is " & VarType(f)
    Set fs = Nothing
    Set f = Nothing
    
    's = f.DateCreated
    'MsgBox s
End Sub
 

Attachments

  • Screenshot 2020-10-24 150122.jpg
    Screenshot 2020-10-24 150122.jpg
    70.5 KB · Views: 10
  • Screenshot 2020-10-24 150750.jpg
    Screenshot 2020-10-24 150750.jpg
    133 KB · Views: 12

Gasman

Enthusiastic Amateur
Local time
Today, 16:08
Joined
Sep 21, 2011
Messages
7,114
Mine shows as object in the Locals window?

1603542299376.png
 

ADIGA88

Member
Local time
Today, 19:08
Joined
Apr 5, 2020
Messages
32
Mine shows as object in the Locals window?
mmmm, I think I understood what happed, Debug.Print "VarType f is " & VarType(f) return the type of the defult property, not the variable type, I didn't think to use the watch windows to verify the type of the object.
Thanks.
 

Attachments

  • Screenshot 2020-10-24 153739.jpg
    Screenshot 2020-10-24 153739.jpg
    37 KB · Views: 9

Isaac

Lifelong Learner
Local time
Today, 08:08
Joined
Mar 14, 2017
Messages
2,697
mmmm, I think I understood what happed, Debug.Print "VarType f is " & VarType(f) return the type of the defult property, not the variable type, I didn't think to use the watch windows to verify the type of the object.
Thanks.
Yes, "Returns an Integer indicating the subtype of a variable, or the type of an object's default property."

Addition, if you run that same code and instead of VarType, use TypeName(f), you get Folder

TypeName is probably useful a lot more often than VarType is, because TypeName will always only describe the variable itself.
 

Users who are viewing this thread

Top Bottom