Vbscript “VBscsript”;“设置”;问题

Vbscript “VBscsript”;“设置”;问题,vbscript,Vbscript,我知道VBScript中的set用于将对象引用指定给变量。我只想了解为什么有必要: Set fso = CreateObject("Scripting.FileSystemObject") what about: dim fso fso = CreateObject("Scripting.FileSystemObject") //would not it create the object directly and assign to the variable? 谢

我知道VBScript中的set用于将对象引用指定给变量。我只想了解为什么有必要:

     Set fso = CreateObject("Scripting.FileSystemObject")
what about:
    dim fso
     fso = CreateObject("Scripting.FileSystemObject") //would not it create the object directly and assign to the variable?
谢谢,我想这只是“因为”。语言是这样定义的。 对于CreateObject和新类,您需要它

所以这就是正常变量和对象之间的区别


同样的原因是为什么IsNothing,IsNull。。。存在。

它们是不同的。如果您使用
Dim
分配一个变量,那就是它,一个变量。但是如果你使用set,你实际上是在“初始化”一个对象对一个变量的引用,这样你就可以调用对象的“方法”

Set objFS=CreateObject(“Scripting.FileSystemObject”)

因为现在
objFS
是一个参考,所以您可以执行以下操作

使用
objFS.CreateFolder
创建文件夹,或删除文件夹:
objFS.DeleteFolder
。使用
objFS.FileExists
检查文件是否存在,或者使用
objFS.GetExtensionName
获取文件扩展名


这个概念非常类似于实例化一个类,并在Java/Python等语言中使用它的方法。

Um,如果FSO是实际对象,我也应该能够这样做。顺便问一下,你为什么写“objFS”而不是fso?我认为这些方法将是fso.CreateFolder等。