Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

vb6如何統計純文字檔內的文字出現次數

假設:C:\text1.txt檔

此檔內容假設如下

48949384810238412345098403929202048828272274838.....

請問如何用vb6來統計

1出現次數

2出現次數

3出現次數

.....

.....

謝謝

Update:

To: Liu-Liu

您好:

你的程式我大都看懂

有個小問題

請問一下

vbNewLine作什麼用呢?

因為有用和沒用

結果都一樣

謝謝^^

2 Answers

Rating
  • 世賢
    Lv 7
    1 decade ago
    Favorite Answer

    Option Explicit

    Private Sub Form_Activate()

    Dim myStr As String

    Dim word As String

    Dim i As Integer

    Me.AutoRedraw = True

    word = ""

    Open "C:\text1.txt" For Input As #1

    While Not EOF(1)

    Line Input #1, myStr

    word = word & myStr & vbNewLine

    Wend

    Close #1

    For i = 0 To 9

    Print i & "出現" & Len(word) - Len(Replace(word, Trim(Str(i)), "")) & "次"

    Next

    End Sub

    2009-01-24 09:28:17 補充:

    vbNewLine 在此程式的確沒什麼用,但若直接將結果列印出來(Print word),就有用囉!

    vbNewLine 代表換行的意思

  • 1 decade ago

    粉簡單捏! 上看都沒在聽喔

Still have questions? Get your answers by asking now.