vb--操作方法

0 Reply , Posted in 程序代码 on 2017 28, 2017

1.add

Sub AddNewFolder(path, folderName)

  Dim fso, f, fc, nf

  Set fso = CreateObject("Scripting.FileSystemObject")

  Set f = fso.GetFolder(path)

  Set fc = f.SubFolders

  If folderName <> "" Then

    Set nf = fc.Add(folderName)

  Else

    Set nf = fc.Add("New Folder")

  End If

End Sub

2.BuildPath

Function GetBuildPath(path)
  Dim fso, newpath
  Set fso = CreateObject("Scripting.FileSystemObject")
  newpath = fso.BuildPath(path, "Sub Folder")
  GetBuildPath = newpath
End Function

3.Close

Sub CreateAFile
  Dim fso, MyFile
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
  MyFile.WriteLine("这是一个测试。")
  MyFile.Close
End Sub

4.copy

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("这是一个测试")
MyFile.Close
Set MyFile = fso.GetFile("c:\testfile.txt")
MyFile.Copy ("c:\windows\desktop\test2.txt")

5.exits

Function KeyExistsDemo
  Dim d, msg              '创建一些变量。
  Set d = CreateObject("Scripting.Dictionary")
  d.Add "a", "Athens"     '添加一些键和项目。
  d.Add "b", "Belgrade"
  d.Add "c", "Cairo"
  If d.Exists("c") Then
    msg = "指定的键存在。"
  Else
    msg = "指定的键不存在。"
  End If
  KeyExistsDemo = msg
End Function

6. keys

 Function DicDemo
Dim a,d,i                       '创建一些变量。
Set d = CreateObject("Scripting.Dictionary")
d.Add "a","Athens"              '添加键和项目。
d.Add "b","Belgrade"
d.Add "c","Cairo"
a = d.Keys                     '获取键。
For i = 0 To d.Count -1         '循环使用数组。
s = s & a(i) & "<BR>"         '返回结果。
  Next
  DicDemo = s
End Function

 

6.readall

Function ReadAllTextFile
  Const ForReading = 1, ForWriting = 2
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
  f.Write "世界你好!"
  Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
  ReadAllTextFile =  f.ReadAll
End Function

标签:   

相关推荐

vb读取access并且显示  (2017-5-11 9:18:27)

VB 获取CPU温度示例  (2017-5-8 10:35:11)

VB程序逆向反汇编常见的函数   (2017-5-8 10:32:0)

VB内嵌汇编的模块示例  (2017-5-8 10:24:4)

内存数据的读写(PC)   (2017-3-1 17:51:40)

用VB制作外挂   (2017-3-1 16:16:53)

发表评论:



◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

                       

  鄂公网安备 42112502000156号     鄂ICP备16019550号