Problem analysis

In one of my current projects I am faced with the following problem:

A user keys in name and address details and then selects a Type and Subtype (both string values). Depending on the combination of these two, several screens with questions are to be presented to the user. I have 8 questions, also 8 screens. I.e.
User selects Type = 1 and Subtype = 3 then questions 1,2,4,7,8 apply.
User selects Type = 3 and Subtype = 2 then questions 3,4,5,7 apply etc.

My question: what is the best construction to save this information/matrix (in a fixed way) in and let the program decide what questions are to be shown and keep the recorded info (all questions are booleans (yes/no) and a simple text field for explanation) prior to save all info in several tables?

For example:
Dim chosed as String = type + subtype
Dim questionsIndexArr() as integer

Select Case chosed
Case “13”
questionsIndexArr = array(1,2,4,7,8)
Case “14”

The way I might approach this is to store the full list of questions in a dictionary object. Each question would have a unique id number that’s their key in the dictionary.

Then I would create arrays of id numbers for the order that the questions are to be answered. (You’d create the arrays based on the user selections.) Then you just feed the appropriate array to a routine that pulls those questions out of the dictionary and displays them.

This way all your questions are in a fixed data structure (the dictionary), but their display is variable, based on the the id list in the passed array.

This would seem very flexible to me, as you could always edit/adjust the program flow by editing the array-creation routine.

If I’m not clear, let me know and I can try and explain it in a better way! :slight_smile:

[quote=20217:@me self]For example:
Dim chosed as String = type + subtype
Dim questionsIndexArr() as integer

Select Case chosed
Case “13”
questionsIndexArr = array(1,2,4,7,8)
Case “14”
…[/quote]

The approach I usually follow is indeed to fill an array but maybe there are more Xojo-like solutions. Thnks.

[quote=20219:@Marc Zeedar]The way I might approach this is to store the full list of questions in a dictionary object. Each question would have a unique id number that’s their key in the dictionary.

Then I would create arrays of id numbers for the order that the questions are to be answered. (You’d create the arrays based on the user selections.) Then you just feed the appropriate array to a routine that pulls those questions out of the dictionary and displays them.

This way all your questions are in a fixed data structure (the dictionary), but their display is variable, based on the the id list in the passed array.

This would seem very flexible to me, as you could always edit/adjust the program flow by editing the array-creation routine.

If I’m not clear, let me know and I can try and explain it in a better way! :-)[/quote]
Never tried the Dictionary; I will look into that.

Dictionaries are great. When I first learned about them quite a while back, I found out how many places in my code they were more applicable and flexible than an array. It is not always best to subsititute an array for a dictionary, but they sure work well in a lot of circumstances.