first array row skipped

smtdev
smtdev used Ask the Experts™
on
Hi all,

   I'm running into a freakish thing. I using the GetRows method to pull records into an array. As I loop through this array to see if it matches a variable I pass into my function, it should assign a string to another variable. This works as expected except for one slight problem...I know that it is skipping the first row in the array. All the others display correctly. I have also isolated this code and ran it on a separate page and it shows all the rows, including the first. So, I think I'm just missing something. Here's a snippet:

**********************

msql = "select respID, modid, partID from modresp where modid LIKE 'M06%' and partID = '"&request("pid")&"'"
Set rec = DataConn.Execute(msql)
arr2 = rec.GetRows()
iRecFirst2   = LBound(arr2, 2)
iRecLast2    = UBound(arr2, 2)
iFieldFirst2 = LBound(arr2, 1)
iFieldLast2  = UBound(arr2, 1)

rec.close
set DataConn = nothing

function chkresp(nuvar)
For J = iRecFirst2 To iRecLast2
nuqual = arr2(1,J)
if trim(nuvar) = nuqual then
modres = "<a href=""javascript:subpop('modresp.asp?actid="&trim(arr2(0,J))&"');""><img src='../images/ballmag.gif' width='12' height='12' border='0'></a>"
exit for
else
modres = ""
'modres = arr2(0,J)
end if
Next
end function

************************

the function is called like so passing the value from a different array- there are 20 some odd case instances

      case "M06P016"
         call chkresp(arr(1,I))
     response.write("<tr><td"&modres&"td></tr>")

As I said, aside from skipping the first row, everything works fine. But I can't figure out why the first is the problem - well aside from something I'm doing wrong.

TIA,
Steve
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Why does this line use 1 instead of iFieldFirst2  ??

nuqual = arr2(1,J)

Using the getrows method you can be fairly confident that the lower bound of each dimension will be 0 (zero)

Hope that helps, let me know.
Dave

Commented:
How do you know it's skipping the first record?  I suggest that you post code that actually outputs at least one field for each record for testing.  Show us that code.

Best Regards,
Jim

Author

Commented:
Here's the code that I ran on a separate page and the results I get:

msql = "select respID, modid, partID from modresp where modid LIKE 'M06%' and partID = '101'"
Set rec = DataConn.Execute(msql)
arr2 = rec.GetRows()
iRecFirst2   = LBound(arr2, 2)
iRecLast2    = UBound(arr2, 2)
iFieldFirst2 = LBound(arr2, 1)
iFieldLast2  = UBound(arr2, 1)

rec.close
set DataConn = nothing

For J = iRecFirst2 To iRecLast2
response.write arr2(1,J)
Next


which produces:

M06P016
M06P032
M06P060
M06P017

That first result is the one that gets left off from my original code...I don't think it is a problem with the array per se, but in how the function is operating.

Thanks,
Steve
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Commented:
OK, I suggest that you encapuslate the VBScript variables in the function to make sure that the variable(s) are not being changed elsewhere.  I've rewritten you code as follows:

============================================
At the top of your ASP, add
<%
Option Explicit

DIM glDebug
glDebug = True

%>

function chkresp(nuvar, paData)

     'paData - 2D Array of data (Field, Record)

     DIM jRec, nuqual, modres

     For jRec = LBound(paData, 2) To UBound(paData, 2)
         
          CALL DebugOut ("Row: " & jRec & "   Field1: " & paData(1, jRec))
         
          nuqual = arr2(1,jRec)
     
          if trim(nuvar) = nuqual then
               modres = "<a href=""javascript:subpop('modresp.asp?actid=" _
                         & trim(arr2(0,jRec)) _
                         & "');""><img src='../images/ballmag.gif' width='12'" _
                         & " height='12' border='0'></a>"
               exit for
          else
               modres = ""
               'modres = arr2(0,jRec)
          end if
     
     Next
end function

'==================================================================='
SUB DebugOut (pcMsg)
'==================================================================='
     
     DIM llDebug
     
     'llDebug = Application("Debug")          'USE this if you can
     
     llDebug = glDebug
     
     IF VarType(llDebug) = vbBoolean THEN
          IF llDebug THEN
               Response.Write ("<BR>" & pcMsg)
          END IF
     END IF

END SUB    
=======================================================

Note that the function chkresp does NOT reference any global variables.  Also, I've added a parameter to pass the array being used.  You will need to adjust your calling code accordingly.

Try this.  This way, you will know for sure what rows are being processed in the function chkresp.  Please NOTE:  I have NOT tested this code.  There may be syntax/typos.  You should double check the code before running.

Best Regards,
Jim

Commented:
smtdev,

I forgot to change the arr2 to paData.  The function chkresp should be:

===============================
function chkresp(nuvar, paData)

     'paData - 2D Array of data (Field, Record)

     DIM jRec

     For jRec = LBound(paData, 2) To UBound(paData, 2)
         
          CALL DebugOut ("Row: " & jRec & "   Field1: " & paData(1, jRec))
         
          nuqual = paData(1,jRec)
     
          if trim(nuvar) = nuqual then
               modres = "<a href=""javascript:subpop('modresp.asp?actid=" _
                         & trim(paData(0,jRec)) _
                         & "');""><img src='../images/ballmag.gif' width='12'" _
                         & " height='12' border='0'></a>"
               exit for
          else
               modres = ""
               'modres = paData(0,jRec)
          end if
     
     Next
end function
==================================================
Commented:
Sorry, 3rd times a charm.  Use this:

===================================================
function chkresp(nuvar, paData)

     'paData - 2D Array of data (Field, Record)

     DIM jRec, nuqual, modres

     For jRec = LBound(paData, 2) To UBound(paData, 2)
         
          CALL DebugOut ("Row: " & jRec & "   Field1: " & paData(1, jRec))
         
          nuqual = paData(1,jRec)
     
          if trim(nuvar) = nuqual then
               modres = "<a href=""javascript:subpop('modresp.asp?actid=" _
                         & trim(paData(0,jRec)) _
                         & "');""><img src='../images/ballmag.gif' width='12'" _
                         & " height='12' border='0'></a>"
               exit for
          else
               modres = ""
               'modres = paData(0,jRec)
          end if
     
     Next
end function
===========================================

Author

Commented:
Jim,

I'll have to go back through and try your suggestion (I have 13 such pages to do similar to this...it's a convoluted mess as I have to access a remote server -the first array- and then make a pass at my own server -the second array: arr2)

Anyway, I think you're on the right track...I was finally able to get it to work by not calling the function on the first item, but inserting that code directly in my case statement. I then call the function on subsequent case statements and everything works fine. Not the most elegant solution but through some testing I found that the first function call did not pass my variable value ("M06P016"}, which was why it was missing the first record.

At least I have it narrowed down to where the error is occuring. I'll give your code a whirl and see if I can clean up this mess. Thanks for your time and the help.

Steve
Looking at your codes:

====================
1.     msql = "select respID, modid, partID from modresp where modid LIKE 'M06%' and partID = '"&request("pid")&"'"
2.     Set rec = DataConn.Execute(msql)
3.     arr2 = rec.GetRows()
4.     iRecFirst2   = LBound(arr2, 2)
5.     iRecLast2    = UBound(arr2, 2)
6.     iFieldFirst2 = LBound(arr2, 1)
7.     iFieldLast2  = UBound(arr2, 1)

8.     rec.close
9.     set DataConn = nothing

10.     function chkresp(nuvar)
11.     For J = iRecFirst2 To iRecLast2
12.     nuqual = arr2(1,J)
13.     if trim(nuvar) = nuqual then
14.     modres = "<a href=""javascript:subpop('modresp.asp?actid="&trim(arr2(0,J))&"');""><img src='../images/ballmag.gif' width='12' height='12' border='0'></a>"
15.     exit for
16.     else
17.     modres = ""
18.     'modres = arr2(0,J)
19.     end if
20.     Next
21.     end function

************************

the function is called like so passing the value from a different array- there are 20 some odd case instances

22.          case "M06P016"
23.             call chkresp(arr(1,I))
24.         response.write("<tr><td"&modres&"td></tr>")
1.     msql = "select respID, modid, partID from modresp where modid LIKE 'M06%' and partID = '"&request("pid")&"'"
2.     Set rec = DataConn.Execute(msql)
3.     arr2 = rec.GetRows()
4.     iRecFirst2   = LBound(arr2, 2)
5.     iRecLast2    = UBound(arr2, 2)
6.     iFieldFirst2 = LBound(arr2, 1)
7.     iFieldLast2  = UBound(arr2, 1)

8.     rec.close
9.     set DataConn = nothing

10.     function chkresp(nuvar)
11.     For J = iRecFirst2 To iRecLast2
12.     nuqual = arr2(1,J)
13.     if trim(nuvar) = nuqual then
14.     modres = "<a href=""javascript:subpop('modresp.asp?actid="&trim(arr2(0,J))&"');""><img src='../images/ballmag.gif' width='12' height='12' border='0'></a>"
15.     exit for
16.     else
17.     modres = ""
18.     'modres = arr2(0,J)
19.     end if
20.     Next
21.     end function

************************

the function is called like so passing the value from a different array- there are 20 some odd case instances

22.          case "M06P016"
23.             call chkresp(arr(1,I))
24.         response.write("<tr><td"&modres&"td></tr>")
=============================

Line 12.  nuqual = arr2(1,J) and
Line 13.  if trim(nuvar) = nuqual then
have eliminated the first row which is actually arr2(0,J).

Author

Commented:
Okay, if I pull from a database, three records with three fields each and create an array, I would have this:

Row 1: 1-1, 1-2, 1-3
Row 2: 2-1, 2-2, 2-3
Row 3: 3-1, 3-2, 3-3

if I declare

iRecFirst2   = LBound(arr2, 2)
iRecLast2    = UBound(arr2, 2)
iFieldFirst2 = LBound(arr2, 1)
iFieldLast2  = UBound(arr2, 1)

then
arr2(1,0) = 1-2
arr2(0,0) = 1-1
arr2(1,1) = 2-1
arr2(1,2) = 3-1 and so forth

I am using the static 1 in arr2(1,J) as I want the second field in every row; the J variable designates the number of the records I'm looping through.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial