Loop/Logic Problems

1. Junior Member
Join Date
Dec 1969
Posts
24

## Loop/Logic Problems

2. Senior Member
Join Date
Dec 1969
Posts
113

## RE: Loop/Logic Problems

Maybe you do it elsewhere but I do not see you ever giving Y an initial value. This would make "Y &#060;&#062; arrQuestions(0,X)" resolve to true and the thing would always be written in the first round because there is no start-up val. It seems like it should also be written again latter though. Just check on initail definition of Y first.

3. Junior Member
Join Date
Dec 1969
Posts
24

## RE: Loop/Logic Problems

Right before I go into For ... Next loop I set it to 0.

4. Senior Member
Join Date
Dec 1969
Posts
113

## RE: Loop/Logic Problems

OK looked at it again and I see your problem. You are using the same conditional (Y &#060;&#062; arrQuestions(0,X)) to determine if this is a new question AND to determine if you should write out the how important stuff. Only you do it in the wrong order. First thing you do is check is this a new question (not the same question ID as the last one). If it is you write the question then go into your default answer write out that happens in every loop. THEN you check again is this a new question if it is you write out the how important stuff (this is why you are finding it secound). If you move that check to the first thing you check it should work ok.

5. Junior Member
Join Date
Dec 1969
Posts
24

## RE: Loop/Logic Problems

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## *** MAKING IT WAY TOO HARD! ***

What I want to know, though, is how you will associate the various "QuestionWeight" values you get with the RIGHT questions from the test??? <BR><BR>I&#039;m going to mod your code slightly to handle that, but you can easily change it back:<BR><BR>(1) Put all this code into a SUB (and get rid of the response.write for HTML code! It slows things WAY WAY down and makes it all unreadable anyway)<BR><BR>&#060;%<BR>Sub StockQuestion( qnum )<BR>%&#062;<BR> &#060;tr&#062;<BR> &#060;td align="left" bgcolor="#ffffff"&#062;<BR> &#060;p class="bodytext"&#062;<BR> &#060;select name="QuestionWeight_&#060;%=qnum%&#062;"&#062;<BR > &#060;option value="1"&#062;Not At All&#060;/option&#062;<BR> &#060;option value="2"&#062;Slightly&#060;/option&#062;<BR> &#060;option value="3"&#062;Somewhat&#060;/option&#062;<BR> &#060;option value="4"&#062;Very&#060;/option&#062;<BR> &#060;option value="5"&#062;Most&#060;/option&#062;<BR> &#060;/select&#062; How important is this question?&#060;/p&#062;<BR> &#060;/td&#062;<BR> &#060;/tr&#062;<BR>&#060;%<BR>End Sub<BR>%&#062;<BR><BR>*******************<BR><BR>T hen code:<BR><BR>&#060;%<BR>If isArray(arrQuestions) then<BR> priorQ = -1 &#039; or other impossible value<BR> <BR> For X = 0 to Ubound(arrQuestions,2)<BR> curQ = arrQuestion(0,X)<BR> If priorQ &#060;&#062; curQ AND priorQ &#060;&#062; -1 Then<BR> StockQuestion( curQ ) &#039; put on tail of *prior* question!<BR> End If <BR> priorQ = curQ<BR><BR> With Response<BR> ... all the messy stuff ...<BR> End With<BR> Next<BR> StockQuestion( priorQ ) &#039; put on tail of LAST question!<BR>End If<BR><BR>*************<BR><BR>And you really should learn to stop using Response.Write to output boiler plate HTML. It will make your code easier to write, easier to read, and somewhat faster to run.<BR><BR>

7. Junior Member
Join Date
Dec 1969
Posts
24

## RE: *** MAKING IT WAY TOO HARD! ***

I have thought of moving it out to a function or a sub, but I was hoping I wouldnt have to. I figured out how to get the count of each question into my recordset so I will jsut test against that to see if I am at the end of my questions.<BR><BR>Also, I have been told since I starting using ASP that context switching is a no-no and you want to avoid mixing regular HTML and ASP code so that it can stay in one processing engine and not switching back and forth. I used to context switch all the time and it took quite a few benchmarks for me to finally make the change, but I have never seen proof to the contrary so I am not going to switch now.<BR><BR>http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=ASP+context+switching&spell=1<BR><BR>Besides it easier for me to read this way than mixing all the HTML in there and going back and forth. It just looks sloppy. And since I work in VB and Access, it keeps it looking about the same in all the apps I use.<BR><BR>Also, I use Homesite for mey editor all the colors flow as well. If I context switch all those colors annoy me. I know I can change how the colors come out, but I havent bother to change them from the default.

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Well, that's pretty funny...

...because your Google search produced this as one of the top hits:<BR><BR>http://www.4guysfromrolla.com/webtech/010202-1.2.shtml<BR><BR>*** QUOTE ***<BR>As can be seen from this, the performance of context switching is greater than that of any other technique. This is the opposite of in earlier versions of ASP, where it was common knowledge that each context-switch was a very expensive operation.<BR>*** END QUOTE ***<BR><BR>I don&#039;t think I&#039;ll bother saying more.<BR><BR>You should check the *DATES* on articles that claim that "context switching" is bad. I&#039;ll bet 90% of them are from ASP version 1 or version 2 days.<BR><BR>But never mind. It&#039;s your code, your choice. I will keep out of it from now on.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## I have to gloat a little more

Of the first 20 hits on Google via that search, exactly *ONE* supports the position that "context switching" (which is a horrible misnomer, as one of the other "hits" correctly notes) is to be avoided in ASP 3 and beyond. And that one hit makes the assertion with no evidence of actual trial.<BR><BR>Granted, only two offer solid evidence the other way, but still... two to zero?<BR><BR>Thanks for showing me that Google query. I&#039;ll use it as proof of my own comments, from now on.<BR><BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•