단어 갯수 맞추는 프로그램 입니다.
*
Public Class frmWordCount


Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

txtEntry.Text = ""
lblWordCount.Text = "0"
txtEntry.Focus()

End Sub

Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnCount.Click
Dim J As Integer
Dim cLast As Integer = txtEntry.TextLength - 1
Dim ThisChar As Char
Dim WordCount As Integer = 0

For J = 0 To cLast
ThisChar = txtEntry.Text.Chars(J)
If ThisChar = " " Then
WordCount += 1
End If

Next J
lblWordCount.Text = WordCount + 1

End Sub

End Class

단어 갯수를 맞추는 프로그램 입니다.

 

코드는 올렸으나 약간의 오류가있는 코드 입니다.(정상작동은 됨)

 

단어가 붙어있을때 한 단어로 계산이 됩니다.

 

이 오류를 없에는 코드를 입력 해보세여.

 

 단어 개수 알기.png

이 게시물을

댓글'1'

 Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCount.Click

        Dim J As Integer
        Dim cLast As Integer = txtEntry.TextLength - 1
        Dim ThisChar As Char
        Dim WordCount As Integer = 0

        For J = 0 To cLast
            ThisChar = txtEntry.Text.Chars(J)
            If ThisChar = " " Then
                WordCount += 1


                If J < cLast Then
                    If txtEntry.Text.Chars(J + 1) = " " Then
                        WordCount -= 1
                    End If
                Else
                    WordCount -= 1
                End If
            End If
        Next J

        If cLast >= 0 Then
            lblWordCount.Text = WordCount + 1
        End If
    End Sub

이 댓글을

공유하기

SEARCH

MENU NAVIGATION