• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

用TextBox读入TXT文件/写入TXT文件

发布: 2007-6-17 21:38 | 作者:   | 来源:   | 查看: 259次 | 进入软件测试论坛讨论

领测软件测试网

   
  Public Function LoadFileToTB(TxtBox As Object, FilePath As _
   String, Optional Append As Boolean = False) As Boolean
   
`PURPOSE: Loads file specified by FilePath into textcontrol

`(e.g., Text Box, Rich Text Box) specified by TxtBox

`If Append = true, then loaded text is appended to existing
` contents else existing contents are overwritten

`Returns: True if Successful, false otherwise

Dim iFile As Integer
Dim s As String

If Dir(FilePath) = "" Then Exit Function

On Error GoTo ErrorHandler:
s = TxtBox.Text

iFile = FreeFile
Open FilePath For Input As #iFile
s = Input(LOF(iFile), #iFile)
If Append Then
    TxtBox.Text = TxtBox.Text & s
Else
    TxtBox.Text = s
End If

LoadFileToTB = True

ErrorHandler:
If iFile > 0 Then Close #iFile

End Function

Public Function SaveFileFromTB(TxtBox As Object, _
   FilePath As String, Optional Append As Boolean = False) _
   As Boolean
  
`PURPOSE: Saves contents of text control (e.g., Text Box,
`Rich Text Box) specified by TxtBox to file specified by FilePath

`If Append = true, then TxtBox`s contents are
`appended to existing file contents
`else existing file is overwritten

`Returns: True if Successful, false otherwise

Dim iFile As Integer

iFile = FreeFile
If Append Then
    Open FilePath For Append As #iFile
Else
    Open FilePath For Output As #iFile
End If

Print #iFile, TxtBox.Text
SaveFileFromTB = True

ErrorHandler:

Close #iFile
End Function

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网