读书人

VB怎么写入TXT文本

发布时间: 2012-04-04 16:38:51 作者: rapoo

VB如何写入TXT文本
想弄个记流水帐的程序,!主程序只有一个TXT文本输入框加一个确定按钮!
比如输入,"今天去逛街花了2元钱!" 按确定,就写入D:/记帐本.txt
各位给点提示吧!

[解决办法]
Private Function SaveFile (FilePath As String,AMode As Long,aValue As String) As String

Dim FileNu As Long
FileNu = Freefile '获取一个可用的文件号

Select Case AMode
Case "Append" '追加方式
Open FilePath For Append As FreeFile
Print #Freefile,AValue & vbcrlf
Close FreeFile
Case "Output" '更新方式
Open FilePath For output As FreeFile
Print #Freefile,AValue & vbcrlf
Close FreeFile
Case "Input" '读取

If Dir(FilePath) = "" Then SaveFile = "Error"
Exit Function
End If

Open FilePath For Input As FreeFile
Dim FileData As String
Input #Freefile,FileData
SaveFile = FileData
Close FreeFile

End Select

End Sub

读书人网 >VB

热点推荐