Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a table in Access, and I want to figure out how I could in VBsc 2

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have a table in Access, and I want to figure out how I could in VBscript recursivly go through the table, steps are checking the HParents and LParents for 0,0 then under the first one, find all children, and for each childeren find under that as well like below should return something like:<br><br><FONT FACE=monospace><br>ID1¦HID¦ID¦Name¦Type ¦Val&nbsp;&nbsp;¦Label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦HParent¦LParent<br>------------------------------------------------------------<br>7&nbsp;&nbsp;¦1&nbsp;&nbsp;¦Labor&nbsp;&nbsp;¦Check¦Labor¦Labor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦0<br>7&nbsp;&nbsp;¦2&nbsp;&nbsp;¦LFD&nbsp;&nbsp;&nbsp;&nbsp;¦Check¦LFD&nbsp;&nbsp;¦Labor Force Data¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦1<br>7&nbsp;&nbsp;¦3&nbsp;&nbsp;¦LFDS&nbsp;&nbsp;&nbsp;¦Check¦LFDS ¦State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦2<br>7&nbsp;&nbsp;¦4&nbsp;&nbsp;¦LFDN&nbsp;&nbsp;&nbsp;¦Check¦LFDN ¦National&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦2<br>7&nbsp;&nbsp;¦5&nbsp;&nbsp;¦LCD&nbsp;&nbsp;&nbsp;&nbsp;¦Check¦LCD&nbsp;&nbsp;¦Labor Cost Data ¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦1<br>7&nbsp;&nbsp;¦6&nbsp;&nbsp;¦LCDW&nbsp;&nbsp;&nbsp;¦Check¦LCDW ¦Wages&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦5<br>7&nbsp;&nbsp;¦7&nbsp;&nbsp;¦LCDE&nbsp;&nbsp;&nbsp;¦Check¦LCDE ¦Employment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦5<br>7&nbsp;&nbsp;¦8&nbsp;&nbsp;¦LCDWR&nbsp;&nbsp;¦Check¦LCDWR¦Wage Ratios&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦5<br></font><br><br>into:<br><br><FONT FACE=monospace><br>...<br>&lt;input type=&quot;check&quot; name=&quot;Labor&quot;&gt; Labor &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LFD&quot;&gt; Labor Force Data &lt;/Input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LFDS&quot;&gt; State &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LFDS&quot;&gt; National &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LCD&quot;&gt; Labor Cost Data &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LCDW&quot;&gt; Wages &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LCDE&quot;&gt; Employment &lt;/input&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;check&quot; name=&quot;LCDWR&quot;&gt; Wage Ratios &lt;/input&gt;<br>...<br></font><br><br>of cource the actual output, may be in tables, forms, etc to make it into a treelike (or if its IE only, into like a pulldown) but I need something to rescursivly go through , and spit out from top to bottom, at the most it might use 4 recordsets on a stack at a time I would think (rescursive is calling itself right?)<br><br>any help is appreciated. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Use sql to sort the table first when you are retriving it and then use its sequence and create the checkboxes<br><br> <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
how in sql am I going to be able to sort the HParent and the LParent , so that it's exactly like a tree, and not have just one sorted, for example, all of the ones with 0,0 dont all go on top, those are the higest points in the tree, then all the other ones tell which parent it's under. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
<FONT FACE=monospace>select * from your table name <br>order by HParent, LParent; </font><br><br>the order by statement will help you get the order that you want !<br><br> <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
I knew about the order by, didnt know you could do two like that, anyway possible to make it do <br><br>0,0<br>children of this<br>0,0<br>children of this<br><br>instead of<br>0,0<br>0,0<br>0,0<br>then all the children. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Dear Karl,<br><br>Not with the schema you desribed. It can be done by using a MIB style UID in a column but you don't have one. It would need to be supplied by programming logic at the row creation time knowing the relationship to the other rows.<br><br>What you could do is create a 'Node' class in your script (yes... object oriented script code) that would be searchable by Node.id the id could be synthesized using HParent.LParent.HID, if I understand your schema correctly. Then as each Node instance is created from a row it's parent could be located in memory and the new Node added to it's children collection. <br><br>By ordering the recordset as Unicorn11 states and Adding HID as a final column, i.e., order by HParent, LParent, HID the parent nodes would be guaranteed to exist in memory prior to any of the children's rows being read from the recordset.<br><br>One time through the recordset would build the entire tree structure in memory. The in memory Nodes could then be walked to build your HTML in any fashion you like.<br><br>-pete<br>
 
I wrote a message board that used the same kind of technique your describing. in a Hierarchal structure display. basically what you can do is put your recordset into a 2 dimensional array using objRs.getrows for speed. I used two functions, both of them looped through the array. the first function deals with all the parents <br>If(data(Hparent, i) = 0 and data(Lparent, i) = 0) then<br>&nbsp;&nbsp;do stuff for parent.<br><br>basicly, you check if the parent has children, if they do you pass the parents' ID's, and any other data to the second function, which writes whatever you want and recurses based on whatever (like if it has siblings or children of its own). Note that it is substantially faster to use the array instead of recordsets when you're applying a lot of logic in your ASP pages. (like in my case, I usually had to loop the array within loops and such).<br><br>Hope this helped<br>J Lowery&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
would you perhaps know, or have an algorithm, that can stuff all the rows into an array? <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
this is what I am trying to use so far, but I keep getting this error and I cant figure it out:<br><br><FONT FACE=monospace><br>Labor,Check<br>Select * from Tree where HParent = 7 and LP = 1 <br>Microsoft OLE DB Provider for ODBC Drivers error '80040e10' <br><br>[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. <br><br>/wsDianostic/Tree.asp, line 15 <br></font><br><br>The Code:<br><br><FONT FACE=monospace><br>&lt;%@ Language=VBScript %&gt;<br>&lt;% Response.Buffer = True %&gt;<br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&lt;/HEAD&gt;<br>&lt;BODY&gt;<br><br>&lt;%<br>sub showkids(Hp, Lp)<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim RSKid<br>&nbsp;&nbsp;&nbsp;&nbsp;Set RSKid = Server.CreateObject(&quot;ADODB.Recordset&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;KidSql = &quot;Select * from Tree where HParent = &quot; & Hp & &quot; and LP = &quot; & Lp<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write KidSql & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>RSKid.Open KidSql,Conn, 3, 1</b><br><br>&nbsp;&nbsp;&nbsp;&nbsp;if RSKid.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RSKid.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while not RSKid.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&nbsp;&nbsp;&nbsp;&nbsp;&quot; & RSKid(&quot;Name&quot;) & &quot;,&quot; & RSKid(&quot;Type&quot;) & &quot;&lt;BR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RSKid.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wend<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RSKid.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;End if<br>&nbsp;&nbsp;&nbsp;&nbsp;Set RSKid = nothing<br>end sub<br><br>Dim RS<br>Dim Conn<br> <br>Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br>Set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;)<br><br>Conn.Open &quot;Tree&quot;, &quot;sa&quot;, &quot;&quot;<br>RS.Open &quot;Select * from Tree order by HParent, LParent&quot;,Conn, 3,1<br><br>If not RS.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;while not RS.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( RS(&quot;HParent&quot;) = 0 and RS(&quot;LParent&quot;) = 0) then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write RS(&quot;Name&quot;) & &quot;,&quot; & RS(&quot;Type&quot;) & &quot;&lt;BR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;!-- (&quot; & RS(&quot;HID&quot;) & &quot;,&quot; & RS(&quot;ID&quot;) & &quot;) --&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showkids RS(&quot;HID&quot;), RS(&quot;ID&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;wend<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;Set RS = nothing<br>end if<br> <br>Conn.Close<br>Set Conn = nothing<br> <br>Response.Flush<br>%&gt;<br><br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br></font><br><br>right now I'm just trying to figure out how I'm going to read and organize this, but that errors been buggin me. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Karl,<br><br>In your sub routine named 'showkids' you are using a variable named 'Conn' as a parameter to the recordset Open method. Within the scope of the subroutine there is no variable named 'Conn' that is initialized to anything therefore the equivalent of NULL is being passed as a parameter.<br><br>On the issue of design if you use the approach I delineated in my earlier post it will be much more efficient than multiply querying the table.<br><br>Also I saw your related post in the SQL forum and again, as I posted earlier you cannot order the rows in the 'tree' node relationship you desire with the given schema. As I stated if the row creation routine can be altered to provide a MIB ID style column value based on the relationships then that column alone would provide the tree node relationship sort order ability. I have done this before when I authored an ASP forum application. It is actually quite simple, however it DOES require code at row creation time to generate the MIB id's.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete<br>
 
I would if I knew how in Vbscript. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
As palbano said, your Conn variable is null unless you have a definition for it elsewhere. It's the connection string that's either a DSN, Driver UID Pwd, or Provider UID Pwd.<br>Another small problem I see comes right after the Open Method call.<br>if RSKid.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RSKid.MoveFirst<br><br>IF RSKid.EOF is true Right after opening the Recordset, then the recordset is empty. if this is true, none of your future calculations would work pretaining to the record set. something like<br>if RSKid.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;There are no Records.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>End If<br><br>Would be a better choice.<br><br>Also, there is no algorthim to put your rows in an array. you just use the GetRows Method of the recordset.<br><br>Dim aryData<br>aryDate = RSKid.GetRows <br>For the parent relationship, you could write a little algorithim to sort through the array and do what you want.<br>aryDate is now a two dimensional array storing all of the values of your recordset. This method is good if you don't need to&nbsp;&nbsp;do any changes to the recordset at the time of displaying it ( adOpenForwardOnly, adLockReadOnly).<br><br>Hope This Helps<br>J Lowery
 
I meant to say If not RSKid.Eof then<br>on that one. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
I'm trying out the getrow thing, and I have something like:<br><br><FONT FACE=monospace><font color=#10DD10><br>AryData = RS.GetRows<br>Response.Write UBound(AryData, 2)<br>for j = 0 to UBound(AryData, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write AryData(j,1) & &quot;&lt;BR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write AryData(j,2) & &quot;&lt;BR&gt;&quot; & vbcrlf<br>next<br></font></font><br><br>and in that section, I keep getting a Subscript out of range when it has reached a number, that doesnt have a field attatch(trys to goto the end of the row)<br>when I had it tell me the UBound, I get 9821.<br><br>am I going about this wrong(at the moment just trying to work with getrow, then see if i can put it to some more productive use) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
I think I figured out a way just to look at the data<br><br><FONT FACE=monospace><font color=#00CC00><br>AryData = RS.GetRows<br>Response.Write UBound(AryData,2)<br>for j = 0 to UBound(AryData, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;for i = 0 to 8 'number of fields in my table<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write AryData(i,j) & &quot; &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;next <br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;BR&gt;&quot; & vbcrlf<br>next<br>RS.Close<br>Set RS = nothing<br>end if<br></font></font><br> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
the reason you get the subscript out of range error is because you have your subscripts out of order. I personal use constants for the column names so I don't have to remember numbers and such. <br><br>const strcolumnname = 1<br><br>For rowcounter = 0 to Ubound(AryData,2)<br>Resoponse.Write AryData(strcolumnname, rowcounter)<br>Next
 
I already figured that out in the post right before yours, now trying to figure out how to pass the array data to a subroutine, for example<br><br><FONT FACE=monospace><font color=#00CC00><br>sub showkids(byref theObj, Hp, Lp)<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;Table Border=1 align=center&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to UBound(TheObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(7,j) = Hp and theObj(8,j) = Lp then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = 1 to 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & vbtab & &quot;&lt;TD&gt;&quot; & TheObj(i,j) & &quot;&lt;/TD&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;/TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br>end sub<br> <br>sub showparents(byref theObj)<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;Table Border=1 align=center&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to UBound(thObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(7,j) = 0 and theObj(8,j) = 0 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = 1 to 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & vbtab & &quot;&lt;TD&gt;&quot; & TheObj(i,j) & &quot;&lt;/TD&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;/TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br>end sub<br></font><br><font color=red><br>Microsoft VBScript runtime error '800a000d' <br>Type mismatch: 'UBound' <br><br>/wsDianostic/Tree.asp, line 27 <br></font><br><i> Rest of code being used (ie main code) </i><br><font color=#0000CC><br>Dim RS<br>Dim Conn<br>Dim AryData<br> <br>Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br>Set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;)<br><br>Conn.Open &quot;Tree&quot;, &quot;sa&quot;, &quot;&quot;<br>RS.Open &quot;Select * from Tree order by HParent, LParent&quot;,Conn, 3,1<br><br>If not RS.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;AryData = RS.GetRows<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;Set RS = nothing<br>end if<br>Conn.Close<br>Set Conn = nothing<br> <br>showparents(AryData) ' if RS was EOF, I would get an erorr I'm aware of this.<br>set AryData = nothing<br>Response.Flush<br></font><br></font><br><br><br><br> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
I got it to work for the UBound error, apparently , it will work if I put the Ubound into a variable first, then use it in the for loop.<br><br><FONT FACE=monospace><font color=#00CC00><br>sub showkids(byref theObj, HpLoc, LpLoc)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;Table Border=1 align=center&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=#0000CC>Dim KidRow<br>&nbsp;&nbsp;&nbsp;&nbsp;KidRow = UBound(theObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to KidRow</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(HP,j) = HpLoc and theObj(LP,j) = LpLoc then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = 1 to 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & vbtab & &quot;&lt;TD&gt;&quot; & TheObj(i,j) & &quot;&lt;/TD&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;/TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br><br>end sub<br> <br>sub showparents(byref theObj)<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;Table Border=1 align=center&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=#0000CC>Dim ParentRow<br>&nbsp;&nbsp;&nbsp;&nbsp;ParentRow = UBound(theObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to ParentRow</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(HP,j) = 0 and theObj(LP,j) = 0 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = 1 to 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & vbtab & &quot;&lt;TD&gt;&quot; & TheObj(i,j) & &quot;&lt;/TD&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;/TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br> <br>end sub<br></font></font> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
I think I may have managed to create a subroutine to work it, (man rescursion makes things small)<br><br><FONT FACE=monospace><font color=#00CC00><br>&lt;%@ Language=VBScript %&gt;<br>&lt;% Response.Buffer = True %&gt;<br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&lt;/HEAD&gt;<br>&lt;BODY&gt;<br><br>&lt;%<br>Const HID&nbsp;&nbsp;&nbsp;= 1<br>Const LID&nbsp;&nbsp;&nbsp;= 2<br>Const Name&nbsp;&nbsp;= 3<br>Const RType = 4<br>Const Value = 5<br>Const Label = 6<br>Const HP&nbsp;&nbsp;&nbsp;&nbsp;= 7<br>Const LP&nbsp;&nbsp;&nbsp;&nbsp;= 8<br><font color=blue><br>sub showtreeat(byref theObj, HpLoc, LpLoc)<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;Table Border=1 align=center&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim ParentRow<br>&nbsp;&nbsp;&nbsp;&nbsp;ParentRow = UBound(theObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to ParentRow<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(HP,j) = HpLoc and theObj(LP,j) = LpLoc then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = 1 to 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & vbtab & &quot;&lt;TD&gt;&quot; & TheObj(i,j) & &quot;&lt;/TD&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showtreeat theObj, theObj(HID, j), theObj(LID, j)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbtab & &quot;&lt;/TR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br>end sub<br></font><br>Dim RS<br>Dim Conn<br>Dim AryData<br><br>Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br>Set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;)<br>Conn.Open &quot;Tree&quot;, &quot;sa&quot;, &quot;&quot;<br>RS.Open &quot;Select * from Tree order by HID, ID&quot;,Conn, 3,1<br><br>If not RS.EOF then<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;AryData = RS.GetRows<br>&nbsp;&nbsp;&nbsp;&nbsp;RS.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;Set RS = nothing<br>end if<br>Conn.Close<br>Set Conn = nothing<br><br>showtreeat AryData, 0, 0<br> <br>set AryData = nothing<br>Response.Flush<br>%&gt;<br><br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br></font></font><br><br>I will modify this to suit my needs, thanks for your help people. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
just if any of you are curious, this is my new showtreeat sub<br><br><FONT FACE=monospace><br>sub showtreeat(byref theObj, HpLoc, LpLoc)<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim ParentRow<br>&nbsp;&nbsp;&nbsp;&nbsp;ParentRow = UBound(theObj, 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;for j = 0 to ParentRow<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If theObj(HP,j) = HpLoc and theObj(LP,j) = LpLoc then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for k = 0 to Spaces<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write vbcrlf & &quot;&lt;input type=&quot; & TheObj(RType, j) & &quot; name=&quot; & TheObj(Name, j) & &quot; value=&quot; & TheObj(Value,j) & &quot;&gt;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write TheObj(Label, j) & &quot;&lt;BR&gt;&quot; & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Spaces = Spaces + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showtreeat theObj, theObj(HID, j), theObj(LID, j)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Spaces = Spaces - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;next<br>end sub<br><i>Spaces is a global scope variable that is set at 0 on page load, this gives the ouput a treelike view</i><br></font> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top