Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 1st, 2007, 08:04 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Collections and Recordsets

Is it possible to compare items in a collection to fields in a recordset? I have a record set called rs and a collection called PNum, I want to compare each value of Pnum to each field in the recordset. Then I will have a simple if statement that will be true if any value of Pnum equals one of the fields in the recordset.

I appreciate any help, thanks.



  #2 (permalink)  
Old August 1st, 2007, 08:23 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. what are you looking for??? because you are explaining the way that the task must be done... or you are asking if it is really possible to do it automatic?? (with a function in the language??)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #3 (permalink)  
Old August 1st, 2007, 08:24 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm asking if it's possible, and if so, how do I do it? 8)

Thanks!

  #4 (permalink)  
Old August 1st, 2007, 08:27 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. I don't know any other way to do it that read every record in the recordset and compare it with all the data in the collection... as far as I know there is no auto way to do it...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #5 (permalink)  
Old August 1st, 2007, 08:29 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm pretty new to VB, could you possibly help me out with the code? Some place to start maybe.

  #6 (permalink)  
Old August 1st, 2007, 08:44 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. tell me what you have so far i will try to help you...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #7 (permalink)  
Old August 1st, 2007, 08:49 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

While Not rs.EOF

    For i = 0 To rs.fields.Count - 1

        For y = 1 To PNum.Count

            If PNum(y) = rs.fields(i) Then


            End If

        Next y

    Next i

Wend

I wasn't sure if something like this would work, is it too simple?

rs is my recordset, Pnum is my collection. RS has only one record in it called FOLDER. That is what I need to compare to the values in the collection Pnum. If any of the FOLDER fields are equal to a value in the collection, I then need to execute that IF statement.

I appreciate your help, thanks.

  #8 (permalink)  
Old August 1st, 2007, 08:52 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

this is good.. you are in the right direction.. if you find a true (a field value equals a collection value) then what do you want to do.. cancel all the for loops or just set a flag to true or what??? also I don't remember well but aren't collections indexes in 0 to??? (the first value isn't 0??)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #9 (permalink)  
Old August 1st, 2007, 08:58 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe collections index at 0. And if it's true I'm executing an sql command, that part I'm not having problems with. When I try to run the code the way I have it now, I get :


Run-time error '3265'

Item cannot be found in the collection corresponding to the requested name or ordinal.





  #10 (permalink)  
Old August 1st, 2007, 09:12 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

because if the collection has only one item and is index-0 based then the item Pnum(y) doesn't exist... try with
Code:
For y = 0 To PNum.Count -1
HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
collections help bennyt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 July 26th, 2008 01:30 AM
Collections in C#? shenku C# 1 August 17th, 2005 06:16 AM
Collections question GregV VB.NET 2002/2003 Basics 0 August 6th, 2003 12:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.