ASP Classic Code Can someone interpret what this code does?

Am I nuts or ignorant (both very possible) or does this code do nothing?

I support a legacy site written by a third-party company, so there really is no one associated with the site that I can ask.

I understand that they iterate over the recordset and get the number of the last record. But I do not understand what the if block does. The psuedocode seems to say: "If I have a number and subtracting the same number from it, dividing it by four, and then multiplying by four, and it is not zero ... then"

When can it not be zero (except when you generate division by a zero error)? <- ignore this, I thought back, you could get 0/4, but not 4/0. The question remains.

The only thing I can think of is that the record number was negative? Is it possible that I do not pretend to be an expert in ASP Classic, but I don’t know what might happen.

Does anyone know what I don't see here?

do while not rs.EOF recordNum = recordNum + 1 rs.MoveNext loop rs.MoveFirst if recordNum-((recordNum\4)*4) > 0 then recordNumber = (recordNum\4)+1 else recordNumber = (recordNum\4) end if 
+4
source share
3 answers

First of all, as indicated in the now deleted answer, recordNum\4 returns the integer part of division, since the backslash operator in VBScript is used for Integer Division , and the collision slash (/) is used for floating point division.

Here are a few sample values:

  recordNum |  recordNumber
 ---------- | -------------
     0 |  0
     1 |  1
     2 |  1
     3 |  1
     4 |  1
     5 |  2
     6 |  2
     7 |  2
     8 |  2
     9 |  3

So, this value is not the number of records, it rather answers questions like "how many groups of four elements that I have"?

Now, based on this, whoever writes the code can then find out how many rows of the table should be displayed, for example:

 For x=1 To recordNumber Response.Write("<tr>") Response.Write("<td>...</td>") Response.Write("<td>...</td>") Response.Write("<td>...</td>") Response.Write("<td>...</td>") Response.Write("</tr>") Next 
+3
source

this is a kind of pagination algorithm that does nothing meaningful, only spends your processor cycles, which IF in 100% of cases will lead to 0

and btw: you will never achieve division by a null exception, because divide 0 by 4 = 0.

+1
source

Just to add to this conversation (although he was answered); the aforementioned “algorithm” counts the number of “pages” in the data and assumes that there can only be more than n pages, but not exactly n + 1. Another way to do this is to read the scalar value:

 sqlString = "SELECT COUNT(id_field) AS total FROM table WHERE criteria = TRUE " ... 'Read data into array and pass to variable. ... Dim maxPages maxPages = recs \ 4 + (((recs \ 4) <> (recs / 4)) And 1) 

Quoting from records, according to your post to Valis, is a huge waste of time.

0
source

Source: https://habr.com/ru/post/1479034/


All Articles