Sub OpenTextFileTest Const ForReading = 1, ForWriting = 2, ForAppending = 3 Dim fs, f Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse) f.Write "Hello world!" f.Close End Sub
或者引用 microsoft scripting runtimeOption ExplicitPrivate Sub Form_Load() Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fs As New FileSystemObject Dim f As TextStream Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending, True, TristateFalse) f.Write "Hello world!" f.Close End Sub
Class blogfso dim fso Private Sub Class_Initialize set fso=createobject("scripting.filesystemobject") end sub function fsocreatetextfile(filename) set fsocreatetext=fso.CreateTextFile(filename, true, false) end function function fsowrite(blogtitlevalue,blogcontentvalue,filename) set fsofile=fso.getfile(filename) set fsoopentextfile=fsofile.OpenAsTextStream(8, false) xmlstr="<?xml version='1.0'?>" xmlstr=xmlstr&"<blog>" xmlstr=xmlstr&"<blogtitle>" xmlstr=xmlstr&blogtitlevalue xmlstr=xmlstr&"</blogtitle>" xmlstr=xmlstr&"<blogcontent>" xmlstr=xmlstr&blogcontentvalue xmlstr=xmlstr&"</blogcontent>" xmlstr=xmlstr&"</blog>" fsoopentextfile.write xmlstr end function Private Sub Class_Terminate set fso=nothing End Sub End Classvbs 写的
Option ExplicitPrivate Sub Form_Load() Dim oFSO As FileSystemObject Dim oTextStream As TextStream Dim oFirstLine As String Dim i, LineNum As Integer Set oFSO = CreateObject("scripting.filesystemobject") Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForAppending, False, TristateFalse) oTextStream.Write (vbCrLf & "这是一个新增的测试行")'以下为删除某一行,如第二行 oTextStream.Close Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForReading, False, TristateFalse) Dim str(1000) As String '这里根据实际情况可增大或缩小数组的维数 i = 0 Do While oTextStream.AtEndOfLine <> True str(i) = oTextStream.ReadLine i = i + 1 Loop LineNum = i oTextStream.Close Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForWriting, False, TristateFalse) oTextStream.Write str(0) For i = 1 To LineNum - 1 If i <> 1 Then oTextStream.Write vbCrLf & str(i) End If Next i oTextStream.Close Set oFSO = Nothing End Sub
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse)
f.Write "Hello world!"
f.Close
End Sub
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs As New FileSystemObject
Dim f As TextStream
Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending, True, TristateFalse)
f.Write "Hello world!"
f.Close
End Sub
dim fso
Private Sub Class_Initialize
set fso=createobject("scripting.filesystemobject")
end sub
function fsocreatetextfile(filename)
set fsocreatetext=fso.CreateTextFile(filename, true, false)
end function
function fsowrite(blogtitlevalue,blogcontentvalue,filename)
set fsofile=fso.getfile(filename)
set fsoopentextfile=fsofile.OpenAsTextStream(8, false)
xmlstr="<?xml version='1.0'?>"
xmlstr=xmlstr&"<blog>"
xmlstr=xmlstr&"<blogtitle>"
xmlstr=xmlstr&blogtitlevalue
xmlstr=xmlstr&"</blogtitle>"
xmlstr=xmlstr&"<blogcontent>"
xmlstr=xmlstr&blogcontentvalue
xmlstr=xmlstr&"</blogcontent>"
xmlstr=xmlstr&"</blog>"
fsoopentextfile.write xmlstr
end function
Private Sub Class_Terminate
set fso=nothing
End Sub
End Classvbs 写的
Dim oFSO As FileSystemObject
Dim oTextStream As TextStream
Dim oFirstLine As String
Dim i, LineNum As Integer
Set oFSO = CreateObject("scripting.filesystemobject")
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForAppending, False, TristateFalse)
oTextStream.Write (vbCrLf & "这是一个新增的测试行")'以下为删除某一行,如第二行
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForReading, False, TristateFalse)
Dim str(1000) As String '这里根据实际情况可增大或缩小数组的维数
i = 0
Do While oTextStream.AtEndOfLine <> True
str(i) = oTextStream.ReadLine
i = i + 1
Loop
LineNum = i
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForWriting, False, TristateFalse)
oTextStream.Write str(0)
For i = 1 To LineNum - 1
If i <> 1 Then
oTextStream.Write vbCrLf & str(i)
End If
Next i
oTextStream.Close
Set oFSO = Nothing
End Sub
好象以上的代码中并没有出现vbscript控件的代码,如scriptcontrol1.addcode或scriptcontrol1.ExecuteStatement等代码哦。。
Dim evals As New ScriptControl
evals.Language = "VBScript"
MsgBox evals.Eval("(2+3)+3*4")
End Sub
不是吧??
有vbscript控件又没文件操作了??
如果实在实现不了,有没有什么办法用vbscript控件在picture或form中画线呢?