Already existing...many variants of this code in this Forum. You need to search and use it as per your needs.