问题描述:
在网上我找到了相关的代码,但是在我的电脑上总实现不了,说编译错误,求达人解惑!
代码全文如下:
在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里面所有的字符串都必须用英文双引号。而以上亩庆都是一个中文双引号开始(“),再用的英文双引号(")结束的.
把以上所有的 “ 改成 " 。
使用系统API函数ShellExecute实现打开文件。执行后会调用与要打开文件扩展名关联的程序打开这个文件。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Form_click()
ShellExecute(Me.hwnd, "open", "z:\test.txt", "", "", 1)
End sub
函数参数及意义:
ShellExecute(
hWnd: HWND {指定父窗口句柄}
Operation: PChar 前尺{指定动作, 譬如: open、runas、print、edit、explore、find[2] }
FileName: PChar {指定要打开的文件或程序}
Parameters: PChar {给要打开的程序指定参数 如果打开的是文件这里应该是 nil}
Directory: PChar {缺省目录}
ShowCmd: Integer {打开选项}
): HINST
ShowCmd 参数可选值:SW_HIDE = 0 {隐藏}
SW_SHOWNORMAL = 1 {用最近的大小和位置显示, 激活}
SW_NORMAL = 1 {同 SW_SHOWNORMAL}
SW_SHOWMINIMIZED = 2 {最缺竖小化, 激活}
SW_SHOWMAXIMIZED = 3 {最大化, 激活}
SW_MAXIMIZE = 3 {同 SW_SHOWMAXIMIZED}
SW_SHOWNOACTIVATE = 4 {用最近的大小和位置显示, 不激活}
SW_SHOW = 5 {同 SW_SHOWNORMAL}
SW_MINIMIZE = 6 {最小化, 不激活}
SW_SHOWMINNOACTIVE = 7 {同 SW_MINIMIZE}
SW_SHOWNA = 8 {同 SW_SHOWNOACTIVATE}
SW_RESTORE = 9 {同 SW_SHOWNORMAL}
SW_SHOWDEFAULT = 10 {同 SW_SHOWNORMAL}
SW_MAX = 10 {同 SW_SHOWNORMAL}
WIN8系统调用此函数慧扮高打开文件无效。
VBweb保存代码如下:Private Sub mnusave_Click() '保存
Set fs = CreateObject("Scripting.FileSystemObject")
CommonDialog1.InitDir = "c:\"
CommonDialog1.Filter = "文握旅歼本镇猜文件|*.txt"
If fs.fileexists(FileName) = False Then
CommonDialog1.ShowSave
End If
FileName = CommonDialog1.FileName
RichTextBox1.SaveFile FileName, rtfText
Me.Caption = "段冲Easy Notebook -" &FileName
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)