Welcome to the forum.

This example might do the trick
http://www.microengineeringlabs.com/...pbc/countx.bas