I don't think I really understand what you're trying to do. Are you trying to write a series of numbers to a file or just the single random number present when you click the save button? If you want every number saved, there's no need for a case structure. Just continuously write to the file. You'd want to put your file dialog, new file, close file outside the while loop. Another way and to keep the case structure, is to have a shift register and a build array function. The array in the shift register would keep accumulating values. then when you click save, first write the current array and then clear it.