Posts: 262
Threads: 63
Joined: Nov 2005
My wife wants me to create a program that when you are done answering about a hundred questions it will either take you to a webpage or ask you some more questions and then based on the answers to the questions will give you some information. What would be the best way to make this? Cases, ifs or gotos or is there a better way to make the program?
Posts: 1,769
Threads: 410
Joined: Feb 2003
are you going to be doing the questioning by dialog boxes or one big dialog or some other way.
Posts: 262
Threads: 63
Joined: Nov 2005
I think the best way would be a list; questions 1 to 100 with answer to each question A B C or D. and then based on the answers do something. I will use an EXE dialog for all my work. It will probably look like the tests that we took in school but I do not know how to tally or sum up the answers. Example If(1=B and 2=D and 3=A and 4=D) as you can see this program would take way to much programming and err checking. Is there a better way of doing the programming?
Posts: 12,073
Threads: 140
Joined: Dec 2002
Example with web form in dialog.
Function
Dialog64
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
;out
str controls = "3"
str ax3SHD
;HTML table with questions. Will add radio buttons later.
ax3SHD=
;<style>
;table { border: 2px solid #D1D7DC; border-collapse: collapse; margin: 10px; width: 90%; }
;td,th { border: 1px solid #D1D7DC; border-collapse: collapse; padding-left: 4px; }
;</style>
;<form>
;<table>
;<thead><th>Question</th><th>A</th><th>B</th><th>C</th><th>D</th></thead>
;<!--begin-->
;<tr><td>Question 1</td></tr>
;<tr><td>Question 2</td></tr>
;<tr><td>And so on</td></tr>
;</table>
;</form>
;Add radio buttons.
int-- nrows ncols
ncols=4 ;;change if needed
int i j k=find(ax3SHD "<!--begin-->")
for i 1 1000000
,k=find(ax3SHD "</tr>" k); if(k<0) break
,str s1=""
,for(j 0 ncols) s1.formata("<td><input type=''radio'' name=''r%i''</input></td>" i)
,ax3SHD.insert(s1 k)
,k+s1.len+5
nrows=i-1
;out ax3SHD
;ret
if(!ShowDialog("Dialog64" &Dialog64 &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ActiveX 0x54030000 0x0 0 0 224 112 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,Htm el
,;for each row
,for i 0 nrows
,,;find checked column
,,for j 0 ncols
,,,el=htm("INPUT" "" "" hDlg 0 i*ncols+j)
,,,if(val(el.Attribute("CHECKED"))) break
,,if(j=ncols) j=-1
,,
,,;out checked column
,,if(j>=0) out "%i. %i (%c)" i j 'A'+j
,,else out "%i. %i (all unchecked)" i j
,
,case IDCANCEL
ret 1
Posts: 262
Threads: 63
Joined: Nov 2005
WOW; this is fantastic. It will take me a couple of days just to understand it but it works great!
Thank You
Posts: 262
Threads: 63
Joined: Nov 2005
Why can I only have eight questions? When I put more questions and run the macro it is blank.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Download QM 2.3.0 beta. Older versions did not work with big HTML.
Another way - save the HTML to a temporary file with .htm extension. Let ax3SHD be file path insteaf of HTML. For example, insert this before ShowDialog:
ax3SHD.setfile("$temp$\x1.htm")
ax3SHD="$temp$\x1.htm"
Posts: 262
Threads: 63
Joined: Nov 2005
I did both and both work great; I will have to try the new improvements you made.