Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21846

create function from words and letter

$
0
0
Hey guys ...
I'm working on program that count the position of word + amount of letters
example: "Hello World"

the word hello at the first and amount of letters are five, the sum is 1+5 = 6
World at the second and amount of letters are five, the sum is 2+5 = 7

when I saw this code I thought you can help me

Code:

Option Explicit
 
Private Sub Command1_Click()
 
    Dim tempArray()    As String
    Dim lngWordCount    As Long
    Dim lngCharCount    As Long
    Dim lngCharCountS    As Long
   
    tempArray = Split(Trim$(RichTextBox1.Text), " ")
   
    lngWordCount = UBound(tempArray) + 1    '~~~ Number of words. ie, delimited by a single space
    lngCharCount = Len(RichTextBox1.Text)  '~~~ Number of characters including spaces
    lngCharCountS = Len(Replace(RichTextBox1.Text, " ", "")) '~~~ Number of characters (excludes white spaces)
   
    '~~~ Display it
    MsgBox "Word Count = " & lngWordCount & vbNewLine & _
            "Character count(includes white spaces) = " & lngCharCount & vbNewLine & _
            "Character count(without white spaces) = " & lngCharCountS
           
End Sub


Viewing all articles
Browse latest Browse all 21846

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>