国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
vb6 對文件的寫入、替換、刪除和插入某行操作

最近用vb在寫一個軟件,用到了對文件的寫入、替換、刪除操作,對網(wǎng)友的代碼進(jìn)行了修改,寫入模塊和函數(shù),能夠?qū)崿F(xiàn)上述功能。


有5個文本框,以前四個文本框的內(nèi)容為判別條件,即:如果保存的文件中某行前四項(以空格為區(qū)分)與文本框中的Text1、Text2、Text3、Text4相同,點擊“替換某行”按鈕可以將Text1-Text5中的內(nèi)容替換到原文件中。點擊“刪除某行”則刪除文件中與Text1-Text4相同的那一行。插入某行還沒有用到,沒有測試。

  1. Dim MonitorSetFile As String '文件名
  2. Private Sub Command1_Click()
  3. MonitorSetFile = App.Path + "\InstMonitorSet.dat"
  4. Dim ThisInst As String
  5. ThisInst = Text1.Text + " " + Text2.Text + " " + Text3.Text + " " + Text4.Text + Text5.Text
  6. Open MonitorSetFile For Append As #1 '以追加方式打開文件
  7. 'Print #1, '為防止原文件末尾沒有換行,而加入的換行
  8. Print #1, ThisInst '加入一個空行,為新加入內(nèi)容的加入時間,若不需要可刪除或注釋它
  9. 'Print #1, Text1.Text
  10. Close #1
  11. End Sub
  12. Private Sub Command2_Click()
  13. '替換
  14. MonitorSetFile = App.Path + "\InstMonitorSet.dat"
  15. Dim RowNumber As Long
  16. Call FindRow(RowNumber)
  17. Call ModifyInstSet(MonitorSetFile, MonitorSetFile, RowNumber, "替換")
  18. End Sub
  19. Function FindRow(ByRef FindTheRow As Long)
  20. Dim SmText As String
  21. Dim ThisYqSetInfo() As String
  22. Dim SearchHang As Long '查找待替換信息所在行
  23. Open MonitorSetFile For Input As #1
  24. Do While Not EOF(1)
  25. Line Input #1, SmText
  26. 'Form1.Print SmText
  27. SearchHang = SearchHang + 1
  28. ThisYqSetInfo = Split(SmText, " ") '將行文本內(nèi)容以空格為區(qū)分讀進(jìn)數(shù)組
  29. '判斷文本中是否與4個文本框的內(nèi)容一致,如果一致
  30. If ThisYqSetInfo(0) = Text1.Text And ThisYqSetInfo(1) = Text2.Text And ThisYqSetInfo(2) = Text3.Text And ThisYqSetInfo(3) = Text4.Text Then
  31. FindTheRow = SearchHang
  32. End If
  33. Loop
  34. Close #1
  35. 'Dim FileNumber As Integer '文件號
  36. 'Dim FiInfo() As String
  37. '計算源文件行數(shù)
  38. 'Dim FileHangSum As Integer '文件行數(shù)
  39. 'Dim FileHangText As String '文件某行文本
  40. 'Open MonitorSetFile For Input As #2
  41. ' Do While Not EOF(2)
  42. ' Line Input #2, FileHangText
  43. ' FileHangSum = FileHangSum + 1
  44. 'Loop
  45. 'Close #2
  46. 'Print "a文件中共有:" & FileHangSum & "行"
  47. End Function
  48. Private Sub Command3_Click()
  49. Dim DeleHang As String
  50. MonitorSetFile = App.Path + "\InstMonitorSet.dat"
  51. Dim RowNumber As Long
  52. '調(diào)用4個文本框所在行函數(shù)
  53. Call FindRow(RowNumber)
  54. Call ModifyInstSet(MonitorSetFile, MonitorSetFile, RowNumber, "刪除")
  55. End Sub
  56. Private Sub Command4_Click()
  57. '插入
  58. MonitorSetFile = App.Path + "\InstMonitorSet.dat"
  59. Dim RowNumber As Long
  60. Call FindRow(RowNumber)
  61. Call ModifyInstSet(MonitorSetFile, MonitorSetFile, RowNumber, "插入")
  62. End Sub
  63. Private Sub Form_Load()
  64. Command1.Caption = "寫入文件"
  65. Command2.Caption = "替換某行"
  66. Command1.Caption = "刪除某行"
  67. Command1.Caption = "插入某行"
  68. End Sub
將下面的代碼拷貝到標(biāo)準(zhǔn)模塊中:
  1. '刪除、替換文件中一行,或者插入內(nèi)容到文本中某一行
  2. Public Function ModifyInstSet(strSourceFile As String, strTargetFile As String, intRow As Long, CommandCode As String)
  3. 'strSourceFile 原始文件完整名
  4. 'strTargetFile 生成新文件的完整名
  5. 'intRow 操作的行數(shù)
  6. Dim Filenum As Integer
  7. Dim FileContents As String
  8. Dim FileInfo() As String
  9. Dim ThI As Integer
  10. Dim ReplaceContent As String '要替換的文本
  11. '取出源文件行數(shù),按照回車換行來分隔成數(shù)組
  12. Filenum = FreeFile
  13. Open strSourceFile For Binary As #Filenum
  14. FileContents = Space(LOF(Filenum))
  15. Get #Filenum, , FileContents
  16. Close Filenum
  17. FileInfo = Split(FileContents, vbCrLf)
  18. '如果文件已存在則刪除原文件
  19. Filenum = FreeFile
  20. If Dir(strTargetFile, vbNormal) <> "" Then
  21. Kill strTargetFile
  22. End If
  23. '替換指定行
  24. If CommandCode = "替換" Then
  25. ReplaceContent = Form1.Text1.Text + " " + Form1.Text2.Text + " " + Form1.Text3.Text + " " + Form1.Text4.Text + " " + Form1.Text5.Text
  26. '替換一行代碼塊
  27. Open strTargetFile For Append As #Filenum
  28. '循環(huán)每一行
  29. For ThI = 0 To UBound(FileInfo) - 1
  30. If ThI = intRow - 1 Then
  31. Print #Filenum, ReplaceContent '替換的行
  32. Else
  33. Print #Filenum, FileInfo(ThI) '保留原來的行
  34. End If
  35. Next
  36. Close #Filenum
  37. MsgBox "替換完畢"
  38. '刪除指定行
  39. ElseIf CommandCode = "刪除" Then
  40. '刪除一行代碼塊
  41. Open strTargetFile For Append As #Filenum
  42. '循環(huán)每一行
  43. For ThI = 0 To UBound(FileInfo) - 1
  44. If ThI <> intRow - 1 Then
  45. Print #Filenum, FileInfo(ThI)
  46. End If
  47. Next
  48. Close #Filenum
  49. MsgBox "刪除完畢"
  50. '插入指定行
  51. ElseIf CommandCode = "插入" Then
  52. Open strTargetFile For Append As #Filenum
  53. InsertContent = Form1.Text1.Text + " " + Form1.Text2.Text + " " + Form1.Text3.Text + " " + Form1.Text4.Text + " " + Form1.Text5.Text
  54. '循環(huán)每一行
  55. For i = 0 To UBound(FileInfo) - 1
  56. If i = intRow - 1 Then
  57. Print #Filenum, InsertContent
  58. Print #Filenum, FileInfo(i) '保留原來的行,位置后移一位
  59. End If
  60. Next
  61. Close #Filenum
  62. MsgBox "插入完畢"
  63. End If
  64. End Function



本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VB中刪除、替換或者插入內(nèi)容到文本中某一行,及文本行列的處理實例
VB.NET下載程序代碼實現(xiàn)
英漢詞典翻譯程序源代碼xZQ簡介
NET平臺下WEB應(yīng)用程序的部署(安裝數(shù)據(jù)庫和自動配置)
VBA讀取文件路徑中的文件
VB.net讀寫二進(jìn)制數(shù)據(jù)方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服