网络大杂烩首页

网络大杂烩

  • 网站首页
  • HTML/CSS
  • javascript
  • seo优化
  • PS美工
  • 系统安全
  • 漏洞预警
  • 编程学习
  • 原创专区
  • 【网络大杂烩】是一家综合技术门户,为您提供网站建设,编程开发,安全维护,漏洞预警等技术文章

    技术文章MAP

    文章

    VB将txt文本按行数平均分割成多个txt文本

    日期:2019/12/22 23:39:58来源分类:编程开发

    VB将txt文本按行数平均分割成多个txt文本

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const EM_GETLINE = &HC4
    Const EM_GETLINECOUNT = &HBA
    Const EM_SETSEL = &HB1
    Dim appdisk$, aa$, pageno%, LineCnt&, LineNum&, i&, j&

    Private Sub Form_Load()
     appdisk = Trim(App.Path)
     If Right(appdisk, 1) <> "\" Then appdisk = appdisk & "\"
     Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
     aa = "c:\test.txt"
     RichTextBox1.LoadFile aa, 1
     LineCnt = TextBoxLineCnt(RichTextBox1) '总共有几行
    End Sub

    Private Sub Command1_Click()
     pageno = 1
     fname = appdisk & "book" & Format(Str(pageno), "000") & ".txt"
     Open fname For Output As #1
     LineNum = 0
     For i = 1 To LineCnt
     aa = getlinetext(RichTextBox1, i - 1) '取得第二行的字串,以0为基底
     Print #1, aa;   '分号表示不换行
     LineNum = LineNum + 1
     If LineNum >= LineCnt \ 10 Then
     Close #1
     pageno = pageno + 1
     fname = appdisk & "book" & Format(Str(pageno), "000") & ".txt"
     Open fname For Output As #1
     LineNum = 0
     End If
     Next i
     Close #1
     MsgBox "ok"
    End Sub

    Public Function getlinetext(RichTextBox1 As RichTextBox, ByVal ntx As Long) As String
     Dim str1(255) As Byte
     Dim str2 As String
     str1(0) = 255
     j = SendMessage(RichTextBox1.hwnd, EM_GETLINE, ntx, str1(0))
     If j = 0 Then
     getlinetext = ""
     Else
     str2 = StrConv(str1, vbUnicode)
     getlinetext = Trim(Left(str2, InStr(1, str2, Chr(0)) - 1))
     End If
    End Function

    Public Function TextBoxLineCnt(ct1 As RichTextBox) As Long
     TextBoxLineCnt = SendMessage(ct1.hwnd, EM_GETLINECOUNT, 0, 0)
    End Function

    随机推荐

    • 该分类还没有添加任何内容!
    • 该分类还没有添加任何内容!

    Copyright 2005-2019 【网络大杂烩】 版权所有 黑ICP备16886888号

    声明:本站所有文章来自互联网 如有异议 请联系本站管理员