The 4 advanced character generation applications I've coded so far are all variations on a theme and use the same general structure and share a lot of code. So, how did I organize the code to make an application?
Each application has a single main window that contains most of the code. The "Roll" button executes the code in it's "Action" event when the button is pressed. This resets all the global variables and initializes everything back to square one (since this button can be pressed at any time to start over). It then rolls up the basic characteristics of a new character, saves these to a table in a sqLite database file in the resource folder of the app bundle, and displays them on the screen. It also determines whether there is a noble title and displays that as well. It then enables the visibility of a placard embedded in a PagePanel at the bottom of the window which makes the next step visible to the user.
A PagePanel has multiple pages which can be displayed one at a time just by using a line of code like "PagePanel1.Value=2". Each page contains a number of display elements like Labels and TextAreas and controls like RadioButtons and a PushButton. Every time the Value of a PagePanel is changed, the code attached to the PagePanel "Change" event is executed, which is how I control program flow. I use a "Select Case PagePanel1.Value" construct with a "Case 2" (for example) for the code to execute when I switch to page 2. This code does setup for the page controls and visible elements like "graying out" controls which are not applicable to the current character being generated.
Each page in the PagePanel has a "Continue" button which executes the code in its "Action" event when the button is pressed. Sometimes the result of the calculations just gray out something on the page (like a failed enlistment option) and nothing else. This allows a different RadioButton option to be selected and the "Continue" button to be pressed again. When the calculations give a result which allows the program to continue, the code just switches to a new page in the PagePanel which makes visible a whole different set of display elements and controls and a new "Continue" button with code for that page attached to its "Action" event.
I occasionally use a totally blank page (usually for resolving an annual assignment) that just executes the code in the PagePanel "Change" event without user input and automatically determines which page to display next. This happens so quickly that the switching of pages is not visible. This code determines one of several possible pages to go to next. For example, a character with a high value of Education or Social Standing may be given a choice of assignment which would otherwise be determined by a random die roll. If so, the page is changed to one where the user can make a selection, otherwise the page is changed to go to a different step in the character generation process.
And so it goes until the character fails a survival roll or finishes mustering out. The final page just displays the fact that the process has completed and does not contain a "Continue" button.
The sqLite character database tables store integers like the 6 basic characteristics, rank number, and the current term and assignment year. Booleans are used to indicate college and academy success, officer status, and graduation with honors. Separate tables keep track of skills and skill levels earned, mustering out benefits, decorations, and special assignments. When printing out the TAS Form 2 character form, these values are read out of the database and placed in the appropriate field of the form.
A separate read-only database contains all the static data used by the code. Tables for survival, promotion, decoration, and skill rolls, categorized by department and assignment. Tables of rank titles, skills with skill descriptions, and department skill tables.
I hope this overview of how I did things will be helpful to anyone interested in picking up Real Studio and having a go at their own programming projects.