Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Iterating Functions

Reply
 
Old 05-27-2009   #1 (permalink)
p byers


 
 

Iterating Functions

Hi folks

I need a function that needs to iterate many (up around 20) times.

It needs to Select records from a table

BUT if I do it as a single nested ude function, the Record Set from
previous iterations will be lost.

The only way that I can see of doing it is to have twenty functions each
with a slightly different FunctionName and RecordSetName !!


Any ideas for simple was to do it with just one function and one
TableOpen ??

Thanks in anticipation
Pete (Northolt UK)


Example
=======


dataBaseRoot = "C:\inetpub\wwwroot\data\treeSite\"



DBConMT1 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
dataBaseRoot & "data\atree.mdb"
set my_connMT1 = Server.CreateObject("ADODB.Connection")
my_ConnMT1.Open DBConMT1

DBConMT2 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
dataBaseRoot & "data\atree.mdb"
set my_connMT2 = Server.CreateObject("ADODB.Connection")
my_ConnMT2.Open DBConMT2



''''''''''''''''etc



DBConMT20 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
dataBaseRoot & "data\atree.mdb"
set my_connMT20 = Server.CreateObject("ADODB.Connection")
my_ConnMT20.Open DBConMT20



cRecRef = "abc"



function lookForRefs1(cRefIn)
StrSqlMT1 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
"'"
set rsMT1 = my_connMT1.Execute (StrSqlMT1)
if NOT rsMT1.EOF AND NOT rsMT1.BOF then
do while NOT rsMT1.EOF
''process bottom-ref here
cReply = lookForRefs2(rsMT1("bottom_ref"))
rsMT1.MoveNext
loop
end if

lookForRefs = "OK"
end function

function lookForRefs2(cRefIn)
StrSqlMT2 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
"'"
set rsMT2 = my_connMT2.Execute (StrSqlMT2)
if NOT rsMT2.EOF AND NOT rsMT2.BOF then
''process bottom-ref here
do while NOT rsMT2.EOF
cReply = lookForRefs3(rsMT2("bottom_ref"))
rsMT2.MoveNext
loop
end if

lookForRefs = "OK"
end function



''''''''''''''''etc



function lookForRefs20(cRefIn)
StrSqlMT20 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
"'"
set rsMT20 = my_connMT20.Execute (StrSqlMT20)
if NOT rsMT20.EOF AND NOT rsMT20.BOF then
do while NOT rsMT20.EOF
''process bottom-ref here
rsMT20.MoveNext
loop
end if

lookForRefs = "OK"
end function


My System SpecsSystem Spec
Old 05-27-2009   #2 (permalink)
Jeff C


 
 

RE: Iterating Functions


--
Jeff C
Live Well .. Be Happy In All You Do


"p byers" wrote:
Quote:

> Hi folks
>
> I need a function that needs to iterate many (up around 20) times.
>
> It needs to Select records from a table
>
> BUT if I do it as a single nested ude function, the Record Set from
> previous iterations will be lost.
>
> The only way that I can see of doing it is to have twenty functions each
> with a slightly different FunctionName and RecordSetName !!
>
>
> Any ideas for simple was to do it with just one function and one
> TableOpen ??
Have you considered creating action queries and/or VBA code that
accomplishes your process and then placing your process into a macro (which
can repeat).

Then you can use Access command line functionality to run the macro from a
batch file which could then be scheduled?

Sample command line:

"full path to access.exe" "full path to atree.mdb" /x "name of macro"

Quote:

>
> Thanks in anticipation
> Pete (Northolt UK)
>
>
> Example
> =======
>
>
> dataBaseRoot = "C:\inetpub\wwwroot\data\treeSite\"
>
>
>
> DBConMT1 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT1 = Server.CreateObject("ADODB.Connection")
> my_ConnMT1.Open DBConMT1
>
> DBConMT2 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT2 = Server.CreateObject("ADODB.Connection")
> my_ConnMT2.Open DBConMT2
>
>
>
> ''''''''''''''''etc
>
>
>
> DBConMT20 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT20 = Server.CreateObject("ADODB.Connection")
> my_ConnMT20.Open DBConMT20
>
>
>
> cRecRef = "abc"
>
>
>
> function lookForRefs1(cRefIn)
> StrSqlMT1 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
> "'"
> set rsMT1 = my_connMT1.Execute (StrSqlMT1)
> if NOT rsMT1.EOF AND NOT rsMT1.BOF then
> do while NOT rsMT1.EOF
> ''process bottom-ref here
> cReply = lookForRefs2(rsMT1("bottom_ref"))
> rsMT1.MoveNext
> loop
> end if
>
> lookForRefs = "OK"
> end function
>
> function lookForRefs2(cRefIn)
> StrSqlMT2 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
> "'"
> set rsMT2 = my_connMT2.Execute (StrSqlMT2)
> if NOT rsMT2.EOF AND NOT rsMT2.BOF then
> ''process bottom-ref here
> do while NOT rsMT2.EOF
> cReply = lookForRefs3(rsMT2("bottom_ref"))
> rsMT2.MoveNext
> loop
> end if
>
> lookForRefs = "OK"
> end function
>
>
>
> ''''''''''''''''etc
>
>
>
> function lookForRefs20(cRefIn)
> StrSqlMT20 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
> "'"
> set rsMT20 = my_connMT20.Execute (StrSqlMT20)
> if NOT rsMT20.EOF AND NOT rsMT20.BOF then
> do while NOT rsMT20.EOF
> ''process bottom-ref here
> rsMT20.MoveNext
> loop
> end if
>
> lookForRefs = "OK"
> end function
>
>
My System SpecsSystem Spec
Old 05-27-2009   #3 (permalink)
p byers


 
 

Re: Iterating Functions



Jeff C wrote:
Quote:

> --
> Jeff C
> Live Well .. Be Happy In All You Do
>
> "p byers" wrote:
>
Quote:

> > Hi folks
> >
> > I need a function that needs to iterate many (up around 20) times.
> >
> > It needs to Select records from a table
> >
> > BUT if I do it as a single nested ude function, the Record Set from
> > previous iterations will be lost.
> >
> > The only way that I can see of doing it is to have twenty functions each
> > with a slightly different FunctionName and RecordSetName !!
> >
> >
> > Any ideas for simple was to do it with just one function and one
> > TableOpen ??
>
> Have you considered creating action queries and/or VBA code that
> accomplishes your process and then placing your process into a macro (which
> can repeat).
>
> Then you can use Access command line functionality to run the macro from a
> batch file which could then be scheduled?
>
> Sample command line:
>
> "full path to access.exe" "full path to atree.mdb" /x "name of macro"
>
Quote:

> >
> > Thanks in anticipation
> > Pete (Northolt UK)
> >
Thank you for the suggestion - I will give it a try.

Since the original post, I have been mulling it over and am wondering about
adding a "Sequence number" on the table
Then
Populating it as phase One of a process
and
Re-Read the table "ORDER BY" the sequence number


But as the purpose of the script is to examine the Table (which contains data
describing a tree) for closed loops,

The creating of such sequence numbers might get into an everlasting loop !!

Actually, that may have given me the answer
Set the sequence number to null to start with
then
If I find the Sequence number is present already before I put one in - that
indicates a loop !!

Sorry to have asked a question and then rambled on in this post - I have been
contemplating the problem for several days before the original post

Pete (Northolt UK)


My System SpecsSystem Spec
Old 05-27-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: Iterating Functions


"p byers" <pb@xxxxxx-ltd.co.uk> wrote in message
news:4A1D54E9.86FCD066@xxxxxx-ltd.co.uk...
Quote:

>
>
> Jeff C wrote:
>
Quote:

>> --
>> Jeff C
>> Live Well .. Be Happy In All You Do
>>
>> "p byers" wrote:
>>
Quote:

>> > Hi folks
>> >
>> > I need a function that needs to iterate many (up around 20) times.
>> >
>> > It needs to Select records from a table
>> >
>> > BUT if I do it as a single nested ude function, the Record Set from
>> > previous iterations will be lost.
>> >
>> > The only way that I can see of doing it is to have twenty functions
>> > each
>> > with a slightly different FunctionName and RecordSetName !!
>> >
>> >
>> > Any ideas for simple was to do it with just one function and one
>> > TableOpen ??
>>
>> Have you considered creating action queries and/or VBA code that
>> accomplishes your process and then placing your process into a macro
>> (which
>> can repeat).
>>
>> Then you can use Access command line functionality to run the macro from
>> a
>> batch file which could then be scheduled?
>>
>> Sample command line:
>>
>> "full path to access.exe" "full path to atree.mdb" /x "name of macro"
>>
Quote:

>> >
>> > Thanks in anticipation
>> > Pete (Northolt UK)
>> >
>
> Thank you for the suggestion - I will give it a try.
>
> Since the original post, I have been mulling it over and am wondering
> about
> adding a "Sequence number" on the table
> Then
> Populating it as phase One of a process
> and
> Re-Read the table "ORDER BY" the sequence number
>
>
> But as the purpose of the script is to examine the Table (which contains
> data
> describing a tree) for closed loops,
>
> The creating of such sequence numbers might get into an everlasting
> loop !!
>
> Actually, that may have given me the answer
> Set the sequence number to null to start with
> then
> If I find the Sequence number is present already before I put one in -
> that
> indicates a loop !!
>
> Sorry to have asked a question and then rambled on in this post - I have
> been
> contemplating the problem for several days before the original post
>
> Pete (Northolt UK)
>
>
I don't understand what you are trying to do, but from your last response I
wonder if a dictionary object would help. This is great for keeping track of
unique items. I use it when working with nested groups, for example, to
prevent an infinite loop, or anytime I use recursive functions. If all you
want is to count for 20 iterations (or nested loops), then a counter may be
the solution.

Also, it looks to like your 20 Connection objects are identical. If so,
there is no reason why you cannot use one. In the past I have used several
nested Recordset objects but one Connection object with success. However, I
would recommend closing each Recordset object when you are done with it, and
then closing the Connection object when you are done with that.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 05-28-2009   #5 (permalink)
p byers


 
 

Re: Iterating Functions



"Richard Mueller [MVP]" wrote:
Quote:

> "p byers" <pb@xxxxxx-ltd.co.uk> wrote in message
> news:4A1D54E9.86FCD066@xxxxxx-ltd.co.uk...
Quote:

> >
> >
> > Jeff C wrote:
> >
Quote:

> >> --
> >> Jeff C
> >> Live Well .. Be Happy In All You Do
> >>
> >> "p byers" wrote:
> >>
> >> > Hi folks
> >> >
> >> > I need a function that needs to iterate many (up around 20) times.
> >> >
> >> > It needs to Select records from a table
> >> >
> >> > BUT if I do it as a single nested ude function, the Record Set from
> >> > previous iterations will be lost.
> >> >
> >> > The only way that I can see of doing it is to have twenty functions
> >> > each
> >> > with a slightly different FunctionName and RecordSetName !!
> >> >
> >> >
> >> > Any ideas for simple was to do it with just one function and one
> >> > TableOpen ??
> >>
> >> Have you considered creating action queries and/or VBA code that
> >> accomplishes your process and then placing your process into a macro
> >> (which
> >> can repeat).
> >>
> >> Then you can use Access command line functionality to run the macro from
> >> a
> >> batch file which could then be scheduled?
> >>
> >> Sample command line:
> >>
> >> "full path to access.exe" "full path to atree.mdb" /x "name of macro"
> >>
> >> >
> >> > Thanks in anticipation
> >> > Pete (Northolt UK)
> >> >
> >
> > Thank you for the suggestion - I will give it a try.
> >
> > Since the original post, I have been mulling it over and am wondering
> > about
> > adding a "Sequence number" on the table
> > Then
> > Populating it as phase One of a process
> > and
> > Re-Read the table "ORDER BY" the sequence number
> >
> >
> > But as the purpose of the script is to examine the Table (which contains
> > data
> > describing a tree) for closed loops,
> >
> > The creating of such sequence numbers might get into an everlasting
> > loop !!
> >
> > Actually, that may have given me the answer
> > Set the sequence number to null to start with
> > then
> > If I find the Sequence number is present already before I put one in -
> > that
> > indicates a loop !!
> >
> > Sorry to have asked a question and then rambled on in this post - I have
> > been
> > contemplating the problem for several days before the original post
> >
> > Pete (Northolt UK)
> >
> >
>
> I don't understand what you are trying to do, but from your last response I
> wonder if a dictionary object would help. This is great for keeping track of
> unique items. I use it when working with nested groups, for example, to
> prevent an infinite loop, or anytime I use recursive functions. If all you
> want is to count for 20 iterations (or nested loops), then a counter may be
> the solution.
>
> Also, it looks to like your 20 Connection objects are identical. If so,
> there is no reason why you cannot use one. In the past I have used several
> nested Recordset objects but one Connection object with success. However, I
> would recommend closing each Recordset object when you are done with it, and
> then closing the Connection object when you are done with that.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
Richard, thank you - "dictionary object" is a great suggestion !!

I knew that the folks in this group would direct my thinking in lots of other
directions.

Pete (Northolt UK)

My System SpecsSystem Spec
Old 05-29-2009   #6 (permalink)
trading_jacks


 
 

Re: Iterating Functions

On May 27, 7:24*am, p byers <p...@xxxxxx-ltd.co.uk> wrote:
Quote:

> Hi folks
>
> I need a function that needs to iterate many (up around 20) times.
>
> It needs to Select records from a table
>
> BUT if I do it as a single nested ude function, the Record Set from
> previous iterations will be lost.
>
> The only way that I can see of doing it is to have twenty functions each
> with a slightly different FunctionName and RecordSetName !!
>
> Any ideas for simple was to do it with just one function and one
> TableOpen ??
>
> Thanks in anticipation
> Pete (Northolt UK)
>
> Example
> =======
>
> dataBaseRoot = "C:\inetpub\wwwroot\data\treeSite\"
>
> DBConMT1 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT1 = Server.CreateObject("ADODB.Connection")
> my_ConnMT1.Open DBConMT1
>
> DBConMT2 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT2 = Server.CreateObject("ADODB.Connection")
> my_ConnMT2.Open DBConMT2
>
> ''''''''''''''''etc
>
> DBConMT20 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
> dataBaseRoot & "data\atree.mdb"
> set my_connMT20 = Server.CreateObject("ADODB.Connection")
> my_ConnMT20.Open DBConMT20
>
> cRecRef = "abc"
>
> * * function lookForRefs1(cRefIn)
> * * * * StrSqlMT1 = "SELECT * FROM links WHERE top_ref = '" &cRefIn &
> "'"
> * * * * set rsMT1 = my_connMT1.Execute (StrSqlMT1)
> *if NOT rsMT1.EOF AND NOT rsMT1.BOF then
> * * * * * * do while NOT rsMT1.EOF
> * * * * * * * * ''process bottom-ref here
> * * * * * * * * cReply = lookForRefs2(rsMT1("bottom_ref"))
> * * * * * * * * rsMT1.MoveNext
> * * * * * * loop
> * * * * end if
>
> *lookForRefs = "OK"
> * * end function
>
> * * function lookForRefs2(cRefIn)
> * * * * StrSqlMT2 = "SELECT * FROM links WHERE top_ref = '" &cRefIn &
> "'"
> * * * * set rsMT2 = my_connMT2.Execute (StrSqlMT2)
> *if NOT rsMT2.EOF AND NOT rsMT2.BOF then
> * * * * * * * * ''process bottom-ref here
> * * * * * * do while NOT rsMT2.EOF
> * * * * * * * * cReply = lookForRefs3(rsMT2("bottom_ref"))
> * * * * * * * * rsMT2.MoveNext
> * * * * * * loop
> * * * * end if
>
> *lookForRefs = "OK"
> * * end function
>
> ''''''''''''''''etc
>
> * * function lookForRefs20(cRefIn)
> * * * * StrSqlMT20 = "SELECT * FROM links WHERE top_ref = '" & cRefIn &
> "'"
> * * * * set rsMT20 = my_connMT20.Execute (StrSqlMT20)
> *if NOT rsMT20.EOF AND NOT rsMT20.BOF then
> * * * * * * do while NOT rsMT20.EOF
> * * * * * * * * ''process bottom-ref here
> * * * * * * * * rsMT20.MoveNext
> * * * * * * loop
> * * * * end if
>
> *lookForRefs = "OK"
> * * end function
What about using loop to call the same function 20 times, then using
GetRows to set the RS as a two dem array and pass it back to the main
program? I don't know if this will work for you, but it seems
possible? Is passing a recordset completely out of the question with
VBScript? I think I have tried with no luck in the past.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Functions and how to use them PowerShell
Fun with functions PowerShell
Iterating over List of Servicese PowerShell
Where are the functions? Vista General
Functions PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46