Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: 2D Arrays w/ database interaction


Message #1 by "Jeff" <jdupont@j...> on Fri, 14 Sep 2001 22:50:09
What i'm trying to do is this:

Read table from database...

Storing into 2d array 4 separate values... (i have testArray(X,3))

Now the tricky part and where i can't seem to get it to work, is, as it 

moves through the values of the database, to loop back through the array 

to see that if 3 values match, if they do... it will add the 4th value 

then move to the next entry in the database, else, it will create another 

entry for the array. It's easier than it's described... but i can't seem 

to get it to work... or if you know of a better way to accomplish this 

please let me know.



Jeff Dupont

www.lytechnologies.com



Enclosed script:

<%

Set objHours = Server.CreateObject("ADODB.Recordset")

objHours.Open "tblPayroll", strConn, adOpenForwardOnly, adLockOptimistic, 

adCmdTable

objHours.Filter = "payroll = 18"



dim hoursArray(60,3), arrValue, x, tmp

 arrValue = 0

 x = 0

 

 hoursArray(arrValue,0) = objHours("employ_ID")

 hoursArray(arrValue,1) = objHours("shift")

 hoursArray(arrValue,2) = objHours("jobcode")

 hoursArray(arrValue,3) = objHours("time_out")

objHours.MoveNext

arrValue = arrValue + 1



Do While Not objHours.EOF

	For i = 0 to arrValue-1

		Response.Write i & "<br>"

		If hoursArray(i,0) = objHours("employ_ID") AND hoursArray

(i,1) = objHours("shift") AND hoursArray(i,2) = objHours("jobcode") Then

		x = x + 1

			hoursArray(i,3) = hoursArray(i,3) + objHours

("time_out")

			objHours.MoveNext

		Else

			If LCase(objHours.EOF) = "false" Then

				 hoursArray(arrValue,0) = objHours

("employ_ID")

				 hoursArray(arrValue,1) = objHours("shift")

				 hoursArray(arrValue,2) = objHours

("jobcode")

				 hoursArray(arrValue,3) = objHours

("time_out")

				arrValue = arrValue + 1

				objHours.MoveNext

			End If

		End If

	Next

	Response.Write x & "<hr>"

Loop

'Response.Write hoursArray(0,0) & " " & hoursArray(0,1) & " - " & 

hoursArray(0,2) & " - " & hoursArray(0,3) & "<br>"	

%>

Message #2 by "TomMallard" <mallard@s...> on Sat, 15 Sep 2001 09:01:47 -0700
Consider storing the id's and data for either case in an array until you're

done going through the table one time. Then as a separate loop, update the

database values you've got (either adding a 4th value or creating a new

entry). This idea means you can read with a forward-only cursor and process

the updates separately so performance should be better than trying to do it

all at once.



tom mallard

seattle

> ----- Original Message -----

> From: "Jeff" <jdupont@j...>

> To: "ASP Web HowTo" <asp_web_howto@p...>

> Sent: Friday, September 14, 2001 10:50 PM

> Subject: [asp_web_howto] 2D Arrays w/ database interaction

>

>

> > What i'm trying to do is this:

> > Read table from database...

> > Storing into 2d array 4 separate values... (i have testArray(X,3))

> > Now the tricky part and where i can't seem to get it to work, is, as it

> > moves through the values of the database, to loop back through the array

> > to see that if 3 values match, if they do... it will add the 4th value

> > then move to the next entry in the database, else, it will create

another

> > entry for the array. It's easier than it's described... but i can't seem

> > to get it to work... or if you know of a better way to accomplish this

> > please let me know.

> >

> > Jeff Dupont

> > www.lytechnologies.com

> >

> > Enclosed script:

> > <%

> > Set objHours = Server.CreateObject("ADODB.Recordset")

> > objHours.Open "tblPayroll", strConn, adOpenForwardOnly,

adLockOptimistic,

> > adCmdTable

> > objHours.Filter = "payroll = 18"

> >

> > dim hoursArray(60,3), arrValue, x, tmp

> >  arrValue = 0

> >  x = 0

> >

> >  hoursArray(arrValue,0) = objHours("employ_ID")

> >  hoursArray(arrValue,1) = objHours("shift")

> >  hoursArray(arrValue,2) = objHours("jobcode")

> >  hoursArray(arrValue,3) = objHours("time_out")

> > objHours.MoveNext

> > arrValue = arrValue + 1

> >

> > Do While Not objHours.EOF

> > For i = 0 to arrValue-1

> > Response.Write i & "<br>"

> > If hoursArray(i,0) = objHours("employ_ID") AND hoursArray

> > (i,1) = objHours("shift") AND hoursArray(i,2) = objHours("jobcode") Then

> > x = x + 1

> > hoursArray(i,3) = hoursArray(i,3) + objHours

> > ("time_out")

> > objHours.MoveNext

> > Else

> > If LCase(objHours.EOF) = "false" Then

> > hoursArray(arrValue,0) = objHours

> > ("employ_ID")

> > hoursArray(arrValue,1) = objHours("shift")

> > hoursArray(arrValue,2) = objHours

> > ("jobcode")

> > hoursArray(arrValue,3) = objHours

> > ("time_out")

> > arrValue = arrValue + 1

> > objHours.MoveNext

> > End If

> > End If

> > Next

> > Response.Write x & "<hr>"

> > Loop

> > 'Response.Write hoursArray(0,0) & " " & hoursArray(0,1) & " - " &

> > hoursArray(0,2) & " - " & hoursArray(0,3) & "<br>"

> > %>

  Return to Index