Print Page | Close Window

if statement problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=8646
Printed Date: 01 April 2026 at 1:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: if statement problem
Posted By: Corky
Subject: if statement problem
Date Posted: 07 January 2004 at 10:37am

Hello all,

I know I must be doing something stupid here but it's driving me crazy.  I'm trying to create a report through an asp page querying an access database which is fine until I have tried to create some grouping - listing the group name only once on the report. 

I'm trying to use the line <% if  objrs(i) <> grouping then %> to detect if the grouping name needs to be input into the report or not however this is always returning true and the next bit of code is always being executed...

 any help is much  appreciated. 

The full code is: -

<%

dim grouping

grouping = "first"

 

while not objrs.eof

%>

   <TR>

<% For i = 0 to objrs.fields.count - 1%>

 

<% Select Case i %>

                 <% Case "0" %>

                                  <% if  objrs(i) <> grouping then %>

                                                   <TD VALIGN=TOP><B><% = objrs(i) %></B></TD>

                                                    <% grouping = objrs.fields("Location").value %>

                                                    </tr>

                                                    <tr>

                                  <% End if %>

                 <% Case "1" %>

                                  <TD VALIGN=TOP ALIGN=LEFT><% = objrs(i) %></TD>

                                  <td></td>

                 <% Case "2" %>

   




Replies:
Posted By: aalavar
Date Posted: 07 January 2004 at 11:49am

I don't know if this is related or not, but shouldn't the case statement not contain quotes?  If you are trying to compare integers, then it should be: <% Case 1 %>.

As far as the other problem, what kind of record is being returned with objrs?  i.e. show me the list of what one record being returned contains (id,name,date,etc.), and in what order they are being returned from the database.



Posted By: Corky
Date Posted: 07 January 2004 at 12:07pm

Thanks for the reply

the fields and field values being returned in this order: -

fields

Location,ID,Title,InsuranceValue,PurcahsePrice

Values sample

Room 9,1,happy valley,3500,3500

Room10,2,rounding the copelands,300,200

probably should of included the SQL statement I was using: -

 

strSQL="SELECT Asset_Register_Heritage.Location,Asset_Register_Heritage.ID, Asset_Register_Heritage.Title,Asset_Register_Heritage.Insura nce,Asset_Register_Heritage.purchaseprice FROM Asset_Register_Heritage ORDER BY Asset_Register_Heritage.Location,Asset_Register_Heritage.ID"

I have put into the code  the statement <%=grouping%> --- <%objrs(i)%> just after the case 0 to see what values are being fired out each time and the variables being stored are correct as in when I want the statement to be false I'm getting

Room 9 --- Room9

which should ignore the td line but its not...

likewise when it comes accross a new value in the table and I want this to be represented this statement does all the right things i.e.

Room 9 --- Room 10

It just doesn't seem to be working in the if statement

 



Posted By: Gullanian
Date Posted: 07 January 2004 at 12:10pm

Sorry don't have time to fully help you, but some tips:

<% and %> are called ASP blocks, they slow the page loading time down.  In your code you have for example:

                                  <% End if %>

                 <% Case "1" %>

 

This can be changed to:

<%
  End if
  Case "1"
%>



Posted By: Corky
Date Posted: 07 January 2004 at 12:14pm
Thanks for the tips Gullanian but I really only typed in the extra blocks so it was easier to view on the forum


Posted By: aalavar
Date Posted: 07 January 2004 at 12:18pm

Room 9 <> Room9

They are different strings... Try changing your compare to "Room 9"



Posted By: Corky
Date Posted: 07 January 2004 at 12:21pm
Sorry Room 9 and Room9 was just a typo on my behalf.


Posted By: aalavar
Date Posted: 07 January 2004 at 12:26pm

Ok, let's try something else, do this and look at the output:

*<%=grouping%>* --- *<%objrs(i)%>*

I'm wondering if there are any extra spaces in your database object...  If not this should show up as *Room 9* --- *Room 9*.  If it shows up as *Room 9* --- *Room 9   * that is the problem.  I'll keep looking if you want to check that out.



Posted By: aalavar
Date Posted: 07 January 2004 at 12:58pm
Room 9
1 happy valley 3500 3500
Room10
2 rounding the copelands 300 200
2 wandering oaks 300 200

Is this what you want your fields to look like?  If so your code works for me ...



Posted By: Corky
Date Posted: 08 January 2004 at 4:19am

Thanks for all your help aalavar.  Afraid I tried something similar with no luck:-

still getting the output in the following format

Room 9

 

 

 

 

 

 

1

 

happy valley

 

3500

 

3500

Room 10

 

 

 

 



Posted By: aalavar
Date Posted: 08 January 2004 at 8:03am

That is very odd... I've tried it now with both SQL and Access databases, and it works correctly for me...

What is the location defined as in your table? 



Posted By: Corky
Date Posted: 08 January 2004 at 9:36am

Thanks for all your help aalavar - I've just tried out the code on a different database and it's worked so at least I know it's something to do with the recordset being brought in.  I'm going to get hold of the database and go through the data directly but I'm confident now thats where the problem lies.

Once again thanks for all your help.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net