问题描述:
在网上我找到了相关的代码,但是在我的电脑上总实现不了,说编译错误,求达人解惑!
代码全文如下:
在Form1的通用部分加入以下代码:
Option Explicit
Dim fsoTest As New FileSystemObject
Dim folder1 As Folder
并且分别在三个命令按钮的click事件输入以下代码:
Private Sub CmdCreate_Click()
' 获取 Folder 对象。
Set folder1 = fsoTest.GetFolder(“C:")
'创建文件夹
fsoTest.CreateFolder (“C:\Test")
MsgBox “folder C:\Test has created"
End Sub
Private Sub CmdDelete_Click()
' 获取 Drive 对象。
Set folder1 = fsoTest.GetFolder(“C:")
'删除文件夹
fsoTest.DeleteFolder (“C:\Test")
MsgBox“folder C:\Test has deleted"
End Sub
Private Sub CmdGetPro_Click()
'获取文件夹的有关信息
Dim sReturn As String
Set folder1 = fsoTest.GetFolder(“C:\Windows")
'sReturn = “The folder's Attributes is " &folder1.Attributes &vbCrLf
'获取最近一次访问的时间
sReturn = sReturn &“The folder's last access time is " &folder1.DateLastAccessed &vbCrLf
'获取最后一次修改的时间
sReturn = sReturn &“The folder's last modify time is " &folder1.DateLastModified &vbCrLf
'获取文件夹的大小
sReturn = sReturn &“The folder's size is " &FormatNumber(folder1.Size / 1024, 0)
sReturn = sReturn &“Kb" &vbCrLf
'判断文件或文件夹类型
sReturn = sReturn &“The type is " &folder1.Type &vbCrLf
MsgBox sReturn
End Sub
解析:
如果以上代码是楼主完全从VB里拷贝出来的话,那问题就只有一个:
Set folder1 = fsoTest.GetFolder(“C:")
VB里面所有的字符串都必须用英文双引号。而以上都是一个中文双引号开始(“),再用的英文双引号(")结束的.
把以上所有的 “ 改成 " 。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)