Shares in a company represent a portion of a company. If that company takes in money and doesn't pay it out as a dividend (e.g. Apple), the company is still more valuable because it has cold hard cash as an asset. Theoretically, it's all the same whether your share of the money is inside the company or outside the company; the only immediate difference is tax treatment.
Of course, for large bank accounts that means that an investment in the company is a mix of investment in the bank account and investment in the business-value of the company, which may stymie investors who aren't particularly interested in buying larve amounts of bank accounts (known for low returns) and would prefer to receive their share of the cash to invest elsewhere (or in the business portion of the company.) Companies like Apple have in fact taken criticism for this.
Your company could also use that cash to invest in itself (growing the value of its profits) or buy other companies that are worth money, essentially doing the job for you. Of course, they can do the job well or they can do it poorly...
A company could also be acquired by a larger company, or taken private, in exchange for cash or the stock of another company. This is another way that the company's value could be returned to its shareholders.