{"id":2066,"date":"2024-11-26T08:00:00","date_gmt":"2024-11-26T00:00:00","guid":{"rendered":"https:\/\/www.wyrcad.com\/?p=2066"},"modified":"2025-02-05T11:42:02","modified_gmt":"2025-02-05T03:42:02","slug":"notepad-%e5%87%bd%e6%95%b0%e7%b3%bb%e5%88%97%e4%b9%8b%e4%ba%8c","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=2066","title":{"rendered":"NotePad \u51fd\u6570\u7cfb\u5217\u4e4b\u4e8c"},"content":{"rendered":"\n<p>Public Sub TampNotePad(ByVal sTxtFile As String, Optional ByVal bTrimRow As Variant = True) &#8216;\u5bf9\u6587\u672c\u6587\u4ef6\u6d88\u9664\u7a7a\u884c, bTrimRow \u4e3a\u771f, \u5219\u884c &#8221; &#8221; \u89c6\u4e3a\u7a7a\u884c &#8220;&#8221;<br>On Error Resume Next<br>Dim I As Integer, J As Integer<br>Dim Lines() As String<br>Dim LineContent As String<br>Dim iLineCount As Integer<br>Dim TxtFileNumber As Integer<br>TxtFileNumber = FreeFile<br>If Not FileExist(sTxtFile) Then Exit Sub<br>Open sTxtFile For Input As TxtFileNumber<br>Do While Not EOF(TxtFileNumber) &#8216;\u628a\u6587\u672c\u8bfb\u81f3\u6570\u7ec4<br>Line Input #TxtFileNumber, LineContent<br>iLineCount = iLineCount + 1<br>ReDim Preserve Lines(1 To iLineCount)<br>Lines(iLineCount) = LineContent<br>Loop<br>Close TxtFileNumber<br>Open sTxtFile For Output As TxtFileNumber<br>For I = 1 To iLineCount &#8216;\u628a\u6570\u7ec4\u5199\u5165\u6587\u672c<br>If bTrimRow Then Lines(I) = Trim(Lines(I))<br>If Not Lines(I) = &#8220;&#8221; Then Print #TxtFileNumber, Lines(I)<br>Next I<br>Close TxtFileNumber<br>If Err.Number &lt;&gt; 0 Then Err.Clear<br>On Error GoTo 0<br>End Sub<\/p>\n\n\n\n<p><br>Public Sub TrimNotePad(ByVal sTxtFile As String, Optional ByVal bTrimRow As Variant = True) &#8216;\u5bf9\u6587\u672c\u6587\u4ef6\u6d88\u9664\u524d\u540e\u7a7a\u884c, \u4e2d\u95f4\u7a7a\u884c\u4e0d\u7ba1, bTrimRow \u4e3a\u771f, \u5219\u884c &#8221; &#8221; \u89c6\u4e3a\u7a7a\u884c &#8220;&#8221;<br>On Error Resume Next<br>Dim I As Integer, J As Integer<br>Dim Lines() As String<br>Dim LineContent As String<br>Dim iLineCount As Integer<br>Dim TxtFileNumber As Integer<br>TxtFileNumber = FreeFile<br>If Not FileExist(sTxtFile) Then Exit Sub<br>Open sTxtFile For Input As TxtFileNumber<br>Do While Not EOF(TxtFileNumber) &#8216;\u628a\u6587\u672c\u8bfb\u81f3\u6570\u7ec4<br>Line Input #TxtFileNumber, LineContent<br>iLineCount = iLineCount + 1<br>ReDim Preserve Lines(1 To iLineCount)<br>Lines(iLineCount) = LineContent<br>Loop<br>Close TxtFileNumber<br>Dim iBegin As Integer, iEnd As Integer<br>For I = 1 To iLineCount<br>If bTrimRow Then Lines(I) = Trim(Lines(I))<br>If Not Lines(I) = &#8220;&#8221; Then<br>iBegin = I<br>Exit For<br>End If<br>Next I<br>For I = iLineCount To 1 Step -1<br>If bTrimRow Then Lines(I) = Trim(Lines(I))<br>If Not Lines(I) = &#8220;&#8221; Then<br>iEnd = I<br>Exit For<br>End If<br>Next I<br>Open sTxtFile For Output As TxtFileNumber<br>For I = iBegin To iEnd &#8216;\u628a\u6570\u7ec4\u5199\u5165\u6587\u672c<br>Print #TxtFileNumber, Lines(I)<br>Next I<br>Close TxtFileNumber<br>If Err.Number &lt;&gt; 0 Then Err.Clear<br>On Error GoTo 0<br>End Sub<\/p>\n\n\n\n<p><br>Public Sub CleanNotePad(ByVal sTxtFile As String) &#8216;\u5bf9\u6587\u672c\u6587\u4ef6\u6d88\u9664\u91cd\u590d\u884c<br>On Error Resume Next<br>Dim I As Integer, J As Integer<br>Dim Lines() As String<br>Dim LineContent As String<br>Dim iLineCount As Integer<br>Dim TxtFileNumber As Integer<br>TxtFileNumber = FreeFile<br>If Not FileExist(sTxtFile) Then Exit Sub<br>Open sTxtFile For Input As TxtFileNumber<br>Do While Not EOF(TxtFileNumber) &#8216;\u628a\u6587\u672c\u8bfb\u81f3\u6570\u7ec4<br>Line Input #TxtFileNumber, LineContent<br>iLineCount = iLineCount + 1<br>ReDim Preserve Lines(1 To iLineCount)<br>Lines(iLineCount) = LineContent<br>Loop<br>Close TxtFileNumber<br>Call <a href=\"https:\/\/www.wyrcad.com\/?p=798\">CleanUpArray<\/a>(Lines) &#8216;\u53bb\u9664\u91cd\u590d\u5143\u7d20<br>iLineCount = UBound(Lines) &#8211; LBound(Lines) + 1<br>Open sTxtFile For Output As TxtFileNumber<br>For I = 1 To iLineCount<br>Print #TxtFileNumber, Lines(I)<br>Next I<br>Close TxtFileNumber<br>If Err.Number &lt;> 0 Then Err.Clear<br>On Error GoTo 0<br>End Sub<\/p>\n\n\n\n<p><br>Public Sub SortNotePad(ByVal sTxtFile As String, ByVal bAscending As Boolean) &#8216;\u5bf9\u6587\u672c\u6587\u4ef6\u6309\u884c\u6392\u5e8f<br>On Error Resume Next<br>Dim I As Integer, J As Integer<br>Dim Lines() As String<br>Dim LineContent As String<br>Dim iLineCount As Integer<br>Dim TxtFileNumber As Integer<br>TxtFileNumber = FreeFile<br>If Not FileExist(sTxtFile) Then Exit Sub<br>Open sTxtFile For Input As TxtFileNumber<br>Do While Not EOF(TxtFileNumber) &#8216;\u628a\u6587\u672c\u8bfb\u81f3\u6570\u7ec4<br>Line Input #TxtFileNumber, LineContent<br>iLineCount = iLineCount + 1<br>ReDim Preserve Lines(1 To iLineCount)<br>Lines(iLineCount) = LineContent<br>Loop<br>Close TxtFileNumber<br>If iLineCount = 0 Then Exit Sub &#8216;LBound \u4f1a\u51fa\u9519<br>Dim iBest As Integer<br>Dim sBest As String<br>For I = 1 To iLineCount &#8211; 1 &#8216;\u5bf9\u6570\u7ec4\u8fdb\u884c\u6709\u5e8f\u5904\u7406<br>iBest = I<br>sBest = Lines(I)<br>For J = I + 1 To iLineCount<br>If StrComp(Lines(J), sBest, vbTextCompare) &lt; 0 Then sBest = Lines(J) iBest = J End If Next J Lines(iBest) = Lines(I) Lines(I) = sBest Next I Open sTxtFile For Output As TxtFileNumber If bAscending = True Then &#8216;\u628a\u6570\u7ec4\u5199\u5165\u6587\u672c &#8216;Ascending order For I = 1 To iLineCount Print #TxtFileNumber, Lines(I) Next I Else &#8216;Descending order For I = iLineCount To 1 Step -1 Print #TxtFileNumber, Lines(I) Next I End If Close TxtFileNumber If Err.Number &lt;&gt; 0 Then Err.Clear<br>On Error GoTo 0<br>End Sub<\/p>\n\n\n\n<p><br>Public Sub ClearNotePad(ByVal sTxtFile As String) &#8216;\u4fdd\u7559\u6587\u672c\u6587\u4ef6\u4f46\u6e05\u7a7a\u5176\u5185\u5bb9<br>On Error Resume Next<br>Dim I As Integer, J As Integer<br>Dim Lines() As String<br>Dim TxtFileNumber As Integer<br>TxtFileNumber = FreeFile<br>Open sTxtFile For Output As TxtFileNumber<br>For I = LBound(Lines) To UBound(Lines) &#8216;\u628a\u6570\u7ec4\u5199\u5165\u6587\u672c<br>Print #TxtFileNumber, Lines(I)<br>Next I<br>Close TxtFileNumber<br>If Err.Number &lt;&gt; 0 Then Err.Clear<br>On Error GoTo 0<br>End Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Public Sub TampNotePad(ByVal sTxtFile As String, Option &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=2066\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cNotePad \u51fd\u6570\u7cfb\u5217\u4e4b\u4e8c\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-2066","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2066"}],"version-history":[{"count":4,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2066\/revisions"}],"predecessor-version":[{"id":2229,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2066\/revisions\/2229"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}