There are a 1000 ways to skin a cat. So here is yet another way to do what you ask using a collection and its ability to use a string as a key to identify an item within the collection. Using a key assigned to an individual numeric character will let the collection go directly to a particular item rather than you having to write code to test each number to see where it should go.
Place a button on a form1 and copy the following code into the code window
Public Class Form1
Private numCollection As New Collection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CountNumbers(" this is a 333333 test of 555 counting 77 just 2222 then 000 numbers ")
DisplayNumberCount()
End Sub
Private Sub CountNumbers(ByVal str As String)
Dim idx, temp As Integer
Dim myKey As String
numCollection.Clear()
'Create 10 items in the collection that will track
'the numbers 0 to 9 and define their key values
'and initalize the stored value to 0.
'
'Keys provide an alternative to a numeric index
'Keys are strings and can be 1 of more characters
'
'A collection is like an array but adds some additional
'features (like keys). However collections are read only
'so to change a value you delete the old collection item
'and add a new item in its place.
For idx = 0 To 9
'create key'ed collection items
numCollection.Add(0, idx.ToString)
Next
'
'using the MID function get one character at a time from the
'string and use it as a key for numCollection.
'a TRY / CATCH block is used to handle errors that
'will be generated when a key value is not found in
'the collection
For idx = 1 To str.Length 'loop through the entire string
myKey = Mid(str, idx, 1) 'get a single character from the string
Try 'TRY / Catch error handler
temp = numCollection(myKey) 'read the stored count
temp = temp + 1 ' increment the count
numCollection.Remove(myKey) 'delete the old count
numCollection.Add(temp, myKey) 'replace the updated count to the key location
Catch ex As Exception
'the character used as a key was not found in the collection
' do nothing. Continue looping through rest of string
End Try
Next
End Sub
Private Sub DisplayNumberCount()
Dim str, temp As String
Dim idx As Integer
'vbcrlf is a built in constant used to make text go to the next line
str = "Counts:" & vbCrLf
For idx = 0 To 9
temp = numCollection(idx.ToString)
str = str & " The number " & idx & " has " & temp & vbCrLf
Next
MsgBox(str)
End Sub
End Class