Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 2nd, 2015, 08:32 PM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default Complex If Statement

I have the following IF statement but my logic is all wrong. In fact, I'm not sure how to accomplish what I'm trying to do. Here's my goal:

1. I total the alerts from all cities (HQ) and if there are alerts, I check to see which city has alerts.

1. I have cities that have alerts and if a city has an alert I need to display the appropriate table.

2. If the city has NO alerts, I don't display any table.

If (rshq("hq_total")) = 0 Then
%>


<!--#include file="header.html" -->
<!--#include file="hq-table.asp" -->
</html>

<%
elseif (rslosangeles("losangeles_total")) <> 0 Then
%>
<!--#include file="losangeles-alerts.asp" -->

<%
elseif (rssandiego("sandiego_total")) <> 0 Then
response.write "alerts found"
%>
<!--#include file="sandiego-alerts.asp" -->

<%
elseif (rsdenver("denver_total")) <> 0 Then
%>
<!--#include file="denver-alerts.asp" --

However, I can see that the elseif construct is all wrong. I've tried various incantations of if/or if/and and even CASE statements.

Any ideas?

Thanks!
Reply With Quote
  #2 (permalink)  
Old March 2nd, 2015, 10:17 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

No you can not do this. The include files are processed first, so the contents of header.html and
hq-table.asp (and all of the others) will be rendered to the page. After this your ASP processed, its just not going to work

Change your approach:
1. I would place all of the code in all of your included files into a one file called functions.asp
making sure all of thier individual contents are inside subroutines as described in 2-6 below.

or you could do this

2. change header.html to header.asp and place all its contents inside a subroutine. EG myHeaderInfo()
3. place all of hq-table.asp inside a subroutime. EG myHQTableInfo()
4. place all of losangeles-alerts.asp inside a subroutime. EG myLosangelesAlerts()
5. place all of sandiego-alerts.asp inside a subroutime. EG mySandiegoAlerts()
6. place all of denver-alerts.asp inside a subroutime. EG myDenverAlerts()
7. now change your code to this:

Code:
'Note - If you use approach 1 (which is my suggestion) you would only need to include one file here of course
<!--#include file="header.asp"-->
<!--#include file="hq-table.asp"-->
<!--#include file="losangeles-alerts.asp"-->
<!--#include file="sandiego-alerts.asp"-->
<%  If trim(rshq("hq_total")) = 0 Then 
        call myHeaderInfo() 
		call myHQTableInfo()   
%>
    </html>
<%  elseif trim(rslosangeles("losangeles_total")) <> 0 Then
        call myLosangelesAlerts()
    elseif trim(rssandiego("sandiego_total")) <> 0 Then
        response.write "alerts found"
        call mySandiegoAlerts()
    elseif trim(rsdenver("denver_total")) <> 0 Then
        call myDenverAlerts()
	end if  %>
__________________
Wind is your friend
Matt

Last edited by mat41; March 2nd, 2015 at 10:26 PM..
Reply With Quote
  #3 (permalink)  
Old March 4th, 2015, 08:10 AM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Matt,

I tried your suggestion (and thanks!), but when two locations have alerts only one is displayed. I need to display all the locations if they have alerts.

Dale
Reply With Quote
  #4 (permalink)  
Old March 4th, 2015, 07:11 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Im not sure what you expect from me. Am I supposed to guess which locations/alerts are giving you issues? I am not a mind reader...

What suggestions did you take, one include or multiple. Which IF statement is not behaving? If its 'sandiego_total' what is the routine called beneath it, what include file does it link to and what is the routine called in the file? Where is the code?

Your first post was detailed therefore was easy to answer. your send is no good at all
__________________
Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old March 5th, 2015, 07:03 PM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

My apology. Didn't mean to offend you. I can only access this site from home as it's block where I work.

Here's the updated code:

<!--#include file="functions.asp"-->
<%
If trim(rshq("hq_total")) = 0 Then
call myHeaderInfo()
call hqtable()
elseif trim(rslosangeles("losangeles_total")) <> 0 Then
call myHeaderInfo()
call losangelesAlerts()
End if

If trim(rshq("hq_total")) = 0 Then
call hqtable()
elseif trim(rssandiego("sandiego_total")) <> 0 Then
call myHeaderInfo()
call sandiegoAlerts()
End if

If trim(rshq("hq_total")) = 0 Then
call hqtable()
elseif trim(rsdenver("denver_total")) <> 0 Then
call denverAlerts()
response.write "denver <> 0"
End if

If trim(rshq("hq_total")) = 0 Then
call myHeaderInfo()
call hqtable()
elseif trim(rsboston("boston_total")) <> 0 Then
call bostonAlerts()
End if
Reply With Quote
  #6 (permalink)  
Old March 5th, 2015, 08:17 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

no need to appologize you did not offend at all. I am just trying to help you help yourself. So now I can see your code I still dont know what condition is firing and what is not therefore do not know where your issue is.

What I can say is to use cint around the values if you a re comparing the to integers and not strings. This way you know you are comparing int to int EG:

Code:
response.write cint(trim(rshq("hq_total"))) & " = my hq_total value<br>"
response.write cint(trim(rshq("losangeles_total"))) & " = my losangeles_total<br>"
If cint(trim(rshq("hq_total"))) = 0 Then
    response.write "hq_total is equal to 0<bR>"
	call myHeaderInfo()
    call hqtable()
elseif trim(rslosangeles("losangeles_total")) <> 0 Then
    response.write "losangeles_total is not equal to 0<bR>"
    call myHeaderInfo()
    call losangelesAlerts()
else
    response.write "my else fired<br>"
end if
Notice I have placed some response.writes in there as debugging to see what are in the variables you are comparing, also which conditions are firing and which are not. Use this approach around the sections of your page that are problematic. it will show you whats going on
__________________
Wind is your friend
Matt
Reply With Quote
  #7 (permalink)  
Old March 5th, 2015, 09:31 PM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

So I already did you what you suggested and I'm verifying count totals using response.write(s). Here's what's happening:

1. The HQ count is <> 0 which means it falls through to the city conditions.
2.LosAngeles <> 0 and the table is displayed correctly.
3. SanDiego is also <> 0 (verified), but that table is not displayed.
4. Denver and Boston are also <> 0, but their respective tables are not being displayed either.

If I move SanDiego up in the LosAngeles position then it displays correctly.

Dale
Reply With Quote
  #8 (permalink)  
Old March 5th, 2015, 10:15 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I can not see anything wrong with your code. Of course I cant see you routines.... SO here is your first issue:

;;;SanDiego is also <> 0 (verified), but that table is not displayed.

what do you mean by verified, you have used response.writes's. Place them before and after all you calls in the else condition. Does it write all three? hopefully not. E.G. if it writes 1 and 2 but not 3 then you issue is in the sandiegoAlerts() routine.
Code:
If trim(rshq("hq_total")) = 0 Then
	call hqtable()
elseif trim(rssandiego("sandiego_total")) <> 0 Then
        response.write "before myHeaderInfo =1<bR>"
	call myHeaderInfo()
        response.write "after myHeaderInfo =2<bR>"
	call sandiegoAlerts()
        response.write "after sandiegoAlerts =3<bR>"
End if
Are you using OPTION EXPLICIT as the first line on your page so any silly errors will be more clear?

Did you wrsp the cint function around ALL of the values which should be converted to integers?
__________________
Wind is your friend
Matt
Reply With Quote
  #9 (permalink)  
Old March 7th, 2015, 11:00 PM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Here's the updated code snippet:



Code:
response.write "HQ total: "
response.write rsHQ("HQ_total")
response.write "   LosAngeles total: "
response.write rsLosAngeles("LosAngeles_total")
response.write "   SanDiego total: "
response.write rsSanDiego("SanDiego_total")
response.write "   Denver total: "
response.write rsDenver("Denver_total")
response.write "   CMAS total: "
response.write rscmas("cmas_total")

!Note the totals display correctly above.

%>

<!--#include file="functions.asp"-->

<%
If trim(rsHQ("HQ_total")) = 0 Then
        call myHeaderInfo()
        call majcomtable()

elseif trim(rsMiami("Miami_total")) <> 0 Then
        call myHeaderInfo()
        call MiamiAlerts()
        response.write "   LosAngeles total: "
        response.write rsLosAngeles("LosAngeles_total")
        response.write "....calling LosAngeles"
        !Note: The LosAngeles total is more than one here.

elseif trim(rsLosAngeles("LosAngeles_total")) <> 0 Then
        call LosAngelesAlerts()
        response.write rsLonAngeles("LosAngeles_total")
        !The LosAngeles total does NOT display here.        

elseif trim(rsSanDiego("SanDiego_total")) <> 0 Then
        call SanDiegoAlerts()
    response.write "SanDiego <> 0"

elseif trim(rsDenver("Denver_total")) <> 0 Then
        call DenverAlerts()

elseif trim(rsBoston("Boston_total")) <> 0 Then
        call BostonAlerts()

elseif trim(rscmas("cmas_total")) <> 0 Then
        call cmasAlerts()

elseif trim(rsNewYork("NewYork_total")) <> 0 Then
        call NewYorkAlerts()
End if
So, all the city alerts have a count of at least one, but the only city that displays the table is the first one (Miami).
Reply With Quote
  #10 (permalink)  
Old March 9th, 2015, 10:50 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Sure that's great you have placed all the debugging code in there but its no use to me unless I can see what is printed in the browser. It should be however obvious to you.

I wonder why you have not used the cint function like I suggested. I didn't say this for fun, it will actually help you. In fact it could be your issue. If you are comparing to an integer never do this:

If trim(rsHQ("HQ_total")) = 0 Then

always do this:

If cint(trim(rsHQ("HQ_total"))) = 0 Then

How you have done it is fine if you are comparing to a string such as this:

If trim(rsHQ("HQ_total")) = "0" Then

There is a big difference!. So try this change. You say:

;;;but the only city that displays the table is the first one (Miami)

maybe the issue is not in the code you are showing me. Maybe its in your MiamiAlerts() function. do the contents of this routine print to the browser in full? The does the next line in your code show, the next line looks like 'LosAngeles total:'

As I said there does not appear to be any issues in the code I can see. Without seeing its output its hard to help you
__________________
Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Complex SQL Select Statement GeoffreyG SQL Server 2008 1 May 3rd, 2011 11:49 AM
Complex Serialization abedijoo C# 2005 5 April 18th, 2007 10:38 AM
Complex sorting kjohnstone XSLT 1 November 26th, 2004 08:11 AM
complex insert statement? qwjunk SQL Server 2000 3 November 2nd, 2004 04:12 AM



All times are GMT -4. The time now is 05:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.