长沙飞泰国机票价格:用vb创建文件

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 02:17:13
我想知道怎么用VB做这些:
1.在指定位置创建文件夹
2.在指定位置创建txt文件
3.读取txt的第2排数据,写入txt第2排数据,(如果比较难的话可以不写)
4,判断指定位置有没有存在某个文件,如果存在就开打!
在线等待!先谢谢各位高手咯!小第刚刚学VB的,我不会看MSDN啊看不懂,你们能讲讲吗?

1、以下代码可以建立多级文件夹:
Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
'创建指定的目录(可以是多级目录)

Private Function CreateDirectory(ByVal sDirectory As String) As Boolean
'创建指定的目录(可以是多级目录),sDirectory:要创建的文件夹
On Error GoTo ErrHandle
Dim lngResult As Long
sDirectory = checkpath(sDirectory)
lngResult = MakeSureDirectoryPathExists(sDirectory)
CreateDirectory = IIf(lngResult = 0, False, True)
ErrHandle:
If Err <> 0 Then
CreateDirectory = False
End If
End Function

Private Function checkpath(ByVal sPath As String) As String
If Right$(sPath, 1) = "\" Then
checkpath = sPath
Else
checkpath = sPath & "\"
End If
End Function

Private Sub Command1_Click()
CreateDirectory "c:\abc\def\ghi"
End Sub

2~4、主要是文件的“打开”、“读取”、“保存”,多练习一下。下面的仅供参考,实际内容是很多的:
Open "D:\xxx.txt for append As #1
Print #1,"1234"
Print #1,"ABCD"
Close #1
'append 是以追加的方式操作的 还可以换成input,output等等 比如
Open "D:\xxx.txt for input As #1
do while not eof(1)
input #1,a
...
loop
Close #1
'上面的是打开和读取

5、一个判断
If Dir("c:\test.txt") = "" Then
MsgBox "指定文件不存在"
Else
MsgBox "指定文件存在"
End If

用windows自带的filesystemobject可以实现(在microsoft scripting runtime中)详见MSDN,查找FSO