protectorfeelgood
Technical User
Hi all,
Hopefully someone out there could help me with this question.
I've made a sub asking users to input a three letter sentence...
The output at the end should be a list of all letters used in the sentence - sorted alphabetically and a statement telling how many times the letter were used in total.
So far I've made it check for threee words, and somehow sort the sentence...but as you can see - there's still stuff missing.
Mostly in the sorting part of the script.
Please excuse any bad English, as it is not my native tongue.
Any help would be highly appreciated.
Here's my code so far:
Hopefully someone out there could help me with this question.
I've made a sub asking users to input a three letter sentence...
The output at the end should be a list of all letters used in the sentence - sorted alphabetically and a statement telling how many times the letter were used in total.
So far I've made it check for threee words, and somehow sort the sentence...but as you can see - there's still stuff missing.
Mostly in the sorting part of the script.
Please excuse any bad English, as it is not my native tongue.
Any help would be highly appreciated.
Here's my code so far:
Code:
sub WordSplit
dim strMessage,arrWords,strSentence,startagain,arrCounter
Do
startagain ="no"
strSentence = Trim(InputBox("Write a three word sentence"))
arrWords = Split(strSentence, " ")
arrCounter = UBound(arrWords)+1
If arrCounter <> 3 then
alert "Use three words only!"
startagain = "yes"
Else
if CheckForNumbers(strSentence) then
alert "Don't use numbers!"
startagain = "yes"
else
End If
End If
Loop While startagain = "yes"
dim intCounter,i,k,arrMatrix,strSpaces
intCounter = 1
i = 1
strSpaces = Replace(strSentence," ","")
ReDim arrMatrix(len(strSpaces)-1)
for k=1 to len(strSpaces)
arrMatrix(k-1)=mid(strSpaces,k,1)
next
do while not i > Ubound(arrMatrix)
if arrMatrix(i-1) = arrMatrix(i) then
intCounter = intCounter + 1
i = i + 1
else
strMessage = strMessage & intCounter & " Instances of " & arrMatrix(i-1) & vbCrLf
i = i + 1
intCounter = 1
end if
loop
strMessage = strMessage & intCounter & " Instances of " & arrMatrix(i-1) & vbCrLf
alert (strSentence & vbCrLf & strMessage)
End Sub
function CheckForNumbers(string)
dim i
CheckForNumbers = false
for i = 1 to len(string)
if IsNumeric(mid(string,i,1)) then
CheckForNumbers = true
end if
next
end function