It depends on where the onboard credit came from.
If it was granted as part of a promotion with the cruise fare it will be added during the course of your cruise and can be added for excursions and can be usually used for everything except the casino. Usually, these types of credits can't be used for services (tips) and you do not receive any leftover balance at the end of the cruise. Always check with the customer service desk to make sure.
If it was a credit that was obtained by either a bon voyage gift or one that you or someone else paid for with cash or credit card, prior to your cruise than it can be used for anything other than the casino and anything left will be refunded to you at the end of the cruise. The casino is a separate entity and even though the money goes into your account it doesn't come out. Strange but true.
Take care and have a great time.