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

ADIGA88

Member
Local time
Today, 10:15
Joined
Apr 5, 2020
Messages
94
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: 406
  • Screenshot 2020-10-24 150750.jpg
    Screenshot 2020-10-24 150750.jpg
    133 KB · Views: 452

Gasman

Enthusiastic Amateur
Local time
Today, 07:15
Joined
Sep 21, 2011
Messages
14,050
Mine shows as object in the Locals window?

1603542299376.png
 

ADIGA88

Member
Local time
Today, 10:15
Joined
Apr 5, 2020
Messages
94
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: 228

Isaac

Lifelong Learner
Local time
Today, 00:15
Joined
Mar 14, 2017
Messages
8,738
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.
 

Isaac

Lifelong Learner
Local time
Today, 00:15
Joined
Mar 14, 2017
Messages
8,738
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.
For the sake of posterity, I should probably add to this that I found out today that instead of TypeOf, when I switched to Late Binding, I had to use Typename(somevar)="somestring"

Maybe that actually is a good reason to use TypeName sometimes.
 

Users who are viewing this thread

Top Bottom