dbTalk Databases Forums  

Need Advice - RecordSet or Array or Neither? Best Approach

comp.databases.ms-access comp.databases.ms-access


Discuss Need Advice - RecordSet or Array or Neither? Best Approach in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mjbaz
 
Posts: n/a

Default Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 08:34 AM






Hello Everyone:

I am trying to create a lottery checking program in Access 2007 (just
so I can practice my rusty skills). What would be the best approach
to comparing two sets of numbers? The user will enter their ticket
numbers (6 per record) in one table and then enter the Winning
numbers (7 per record) in another table. There is a relationship
between the the two tables based on the date of the draw.

What would be the best approach to loop through the ticket numbers and
flag those numbers that match the winning numbers?

Appreciate any ideas. Thanks in advance

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 09:18 AM






mjbaz wrote:

Quote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007 (just
so I can practice my rusty skills). What would be the best approach
to comparing two sets of numbers? The user will enter their ticket
numbers (6 per record) in one table and then enter the Winning
numbers (7 per record) in another table. There is a relationship
between the the two tables based on the date of the draw.

What would be the best approach to loop through the ticket numbers and
flag those numbers that match the winning numbers?

Appreciate any ideas. Thanks in advance

If you go to http://www.mnlottery.com/ and punch in some numbers, those
numbers that hit will be red foreground, the others black.

I would think you'd need to make each number a separate column.

Most likely with conditional formatting you could highlight the numbers
that hit setting up multiple criteria.

Reply With Quote
  #3  
Old   
mjbaz
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 09:28 AM



On Mar 31, 10:18*am, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
mjbaz wrote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007 (just
so I can practice my rusty skills). *What would be the best approach
to comparing two sets of numbers? *The user will enter their ticket
numbers (6 per record) in one table *and then enter the Winning
numbers (7 per record) in another table. There is a relationship
between the the two tables based on the date of the draw.

What would be the best approach to loop through the ticket numbers and
flag those numbers that match the winning numbers?

Appreciate any ideas. *Thanks in advance

If you go tohttp://www.mnlottery.com/and punch in some numbers, those
numbers that hit will be red foreground, the others black.

I would think you'd need to make each number a separate column.

Most likely with conditional formatting you could highlight the numbers
that hit setting up multiple criteria.
Ah, thanks. But not really answering my question. Anyone else?

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 09:41 AM



mjbaz wrote:
Quote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007 (just
so I can practice my rusty skills). What would be the best approach
to comparing two sets of numbers? The user will enter their ticket
numbers (6 per record) in one table and then enter the Winning
numbers (7 per record) in another table. There is a relationship
between the the two tables based on the date of the draw.

What would be the best approach to loop through the ticket numbers and
flag those numbers that match the winning numbers?

Appreciate any ideas. Thanks in advance
Depends on how the numbers are entered. It would probably be easiest if the
table NumbersPlayed had columns for the date, user (assuming multiple users
are involved) and single digit of the number played, so that for each date,
there would be 6 rows for each ticket played. Similarly, the WinningNumbers
table would contain columns for date and single digit resulting in 7 rows
for each date. then join the tables on date and digit, group by user and
date, and use HAVING to select the users where count(*) = 6 (This assumes
that exact matches are required)... easy-peasy.

SELECT user,p.lotterydate FROM
WinningNumbers as w join NumbersPlayed as p on p.lotterydate= w.lotterydate
and w.ticketdigit = p.ticketdigit
GROUP BY user,p.lotterydate
HAVING count(*) = 6


Of course, if you insist on storing the entire numbers as text in single
fields, then I would be inclined to forse the structure into the above
structure using some saved union queries:
qryWinningNumbers:
SELECT lotterydate,mid(TicketNumber,1,1) as ticketdigit FROM WinningTickets
UNION ALL
SELECT lotterydate,mid(TicketNumber,2,1) as ticketdigit FROM WinningTickets
etc.

qryNumbersPlayed:
Same idea

Then, join the saved queries as above.

That is the "database" approach. If you are determined to practice your
looping skills, then I would imagine that a recordset to retrieve the
winning and played numbers for each date would suffice, and two loops (no
arrays involved) one nested in the other to do the comparisons. Something
like:

dem rs as recordset
dim numplayed as string
dim numwinning as string,wdigit as string
dim i as integer, j as integer
dim matchesfound as integer
'open the recordset and start looping through it:
do until rs.eof
numplayed=rs("NumberPlayed")
numwinning =rs("WinningNumber")
matchesfound=0
for i = 1 to 7
wdigit=mid(numwinning,i,1)
for j = 1 to 6
if wdigit = mid(numplayed,j,1) then
matchesfound=matchesfound + 1
exit for
end if
next
if matchesfound = 6 then exit for
next
if matchesfound=6 then 'flag the winning ticket/user
rs.movenext
loop

Frankly, I prefer the "database" approach ... :-)

Reply With Quote
  #5  
Old   
mjbaz
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 10:57 AM



On Mar 31, 10:41*am, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
Quote:
mjbaz wrote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007 (just
so I can practice my rusty skills). *What would be the best approach
to comparing two sets of numbers? *The user will enter their ticket
numbers (6 per record) in one table *and then enter the Winning
numbers (7 per record) in another table. There is a relationship
between the the two tables based on the date of the draw.

What would be the best approach to loop through the ticket numbers and
flag those numbers that match the winning numbers?

Appreciate any ideas. *Thanks in advance

Depends on how the numbers are entered. It would probably be easiest if the
table NumbersPlayed had *columns for the date, user (assuming multiple users
are involved) and single digit of the number played, so that for each date,
there would be 6 rows for each ticket played. Similarly, the WinningNumbers
table would contain columns for date and single digit resulting in 7 rows
for each date. then join the tables on date and digit, group by user and
date, and use HAVING to select the users where count(*) = 6 (This assumes
that exact matches are required)... easy-peasy.

SELECT user,p.lotterydate FROM
WinningNumbers as w join NumbersPlayed as p on p.lotterydate= w.lotterydate
and w.ticketdigit = p.ticketdigit
GROUP BY user,p.lotterydate
HAVING count(*) = 6

Of course, if you insist on storing the entire numbers as text in single
fields, then I would be inclined to forse the structure into the above
structure using some saved union queries:
qryWinningNumbers:
SELECT lotterydate,mid(TicketNumber,1,1) as ticketdigit FROM WinningTickets
UNION ALL
SELECT lotterydate,mid(TicketNumber,2,1) as ticketdigit FROM WinningTickets
etc.

qryNumbersPlayed:
Same idea

Then, join the saved queries as above.

That is the "database" approach. If you are determined to practice your
looping skills, then I would imagine that a recordset to retrieve the
winning and played numbers for each date would suffice, and two loops (no
arrays involved) one nested in the other to do the comparisons. Something
like:

dem rs as recordset
dim numplayed as string
dim numwinning as string,wdigit as string
dim i as integer, j as integer
dim matchesfound as integer
'open the recordset and start looping through it:
do until rs.eof
* * numplayed=rs("NumberPlayed")
* * numwinning =rs("WinningNumber")
* * matchesfound=0
* * for i = 1 to 7
* * * * wdigit=mid(numwinning,i,1)
* * * * for j = 1 to 6
* * * * * * if wdigit = mid(numplayed,j,1) then
* * * * * * * * matchesfound=matchesfound + 1
* * * * * * * * exit for
* * * * * * end if
* * * * next
* * * * if matchesfound = 6 then exit for
* * next
* * if matchesfound=6 then 'flag the winning ticket/user
* * rs.movenext
loop

Frankly, I prefer the "database" approach ... :-)
Thanks much. Now I know that my table structure is lacking. I have
two tables but I've set them up so that the numbers entered are
allocated to one of eight fields (Date, Num1, Num2, Num3, etc). So
there is only ONE record (parent) for the winning numbers and several
(children) records (each with 8 fields) - depending on number of
tickets purchased. My problem lied in trying to move horizontally
through the records (field by field) to make the comparison between
the winning numbers and the ticket numbers.

I guess I concentrated on the "prettiness" of the form and ignored the
practicality. I can make the form real pretty if use a one to many
relationship and a parent form and subform. But then it falls apart.

Thanks greatly for your input. Appreciate it.

Reply With Quote
  #6  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 11:16 AM



mjbaz wrote:
Quote:
On Mar 31, 10:41 am, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
mjbaz wrote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007
(just so I can practice my rusty skills). What would be the best
approach to comparing two sets of numbers? The user will enter
their ticket numbers (6 per record) in one table and then enter the
Winning numbers (7 per record) in another table. There is a
relationship between the the two tables based on the date of the
draw.

What would be the best approach to loop through the ticket numbers
and flag those numbers that match the winning numbers?

Appreciate any ideas. Thanks in advance

Depends on how the numbers are entered. It would probably be easiest
if the table NumbersPlayed had columns for the date, user (assuming
multiple users are involved) and single digit of the number played,
so that for each date, there would be 6 rows for each ticket played.
Similarly, the WinningNumbers table would contain columns for date
and single digit resulting in 7 rows for each date. then join the
tables on date and digit, group by user and date, and use HAVING to
select the users where count(*) = 6 (This assumes that exact matches
are required)... easy-peasy.

SELECT user,p.lotterydate FROM
WinningNumbers as w join NumbersPlayed as p on p.lotterydate=
w.lotterydate and w.ticketdigit = p.ticketdigit
GROUP BY user,p.lotterydate
HAVING count(*) = 6

Of course, if you insist on storing the entire numbers as text in
single fields, then I would be inclined to forse the structure into
the above structure using some saved union queries:
qryWinningNumbers:
SELECT lotterydate,mid(TicketNumber,1,1) as ticketdigit FROM
WinningTickets UNION ALL
SELECT lotterydate,mid(TicketNumber,2,1) as ticketdigit FROM
WinningTickets etc.

qryNumbersPlayed:
Same idea

Then, join the saved queries as above.



Frankly, I prefer the "database" approach ... :-)

Thanks much. Now I know that my table structure is lacking. I have
two tables but I've set them up so that the numbers entered are
allocated to one of eight fields (Date, Num1, Num2, Num3, etc). So
there is only ONE record (parent) for the winning numbers and several
(children) records (each with 8 fields) - depending on number of
tickets purchased. My problem lied in trying to move horizontally
through the records (field by field) to make the comparison between
the winning numbers and the ticket numbers.
Well, you can keep your current "pretty" design and use the union query
approach described above to "fold" your tables so the grouping query
approach can work. Instead of Mid( ... ) just use the appropriate field to
create each row.

Reply With Quote
  #7  
Old   
mjbaz
 
Posts: n/a

Default Re: Need Advice - RecordSet or Array or Neither? Best Approach - 03-31-2011 , 11:49 AM



On Mar 31, 12:16*pm, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
Quote:
mjbaz wrote:
On Mar 31, 10:41 am, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
mjbaz wrote:
Hello Everyone:

I am trying to create a lottery checking program in Access 2007
(just so I can practice my rusty skills). What would be the best
approach to comparing two sets of numbers? The user will enter
their ticket numbers (6 per record) in one table and then enter the
Winning numbers (7 per record) in another table. There is a
relationship between the the two tables based on the date of the
draw.

What would be the best approach to loop through the ticket numbers
and flag those numbers that match the winning numbers?

Appreciate any ideas. Thanks in advance

Depends on how the numbers are entered. It would probably be easiest
if the table NumbersPlayed had columns for the date, user (assuming
multiple users are involved) and single digit of the number played,
so that for each date, there would be 6 rows for each ticket played.
Similarly, the WinningNumbers table would contain columns for date
and single digit resulting in 7 rows for each date. then join the
tables on date and digit, group by user and date, and use HAVING to
select the users where count(*) = 6 (This assumes that exact matches
are required)... easy-peasy.

SELECT user,p.lotterydate FROM
WinningNumbers as w join NumbersPlayed as p on p.lotterydate=
w.lotterydate and w.ticketdigit = p.ticketdigit
GROUP BY user,p.lotterydate
HAVING count(*) = 6

Of course, if you insist on storing the entire numbers as text in
single fields, then I would be inclined to forse the structure into
the above structure using some saved union queries:
qryWinningNumbers:
SELECT lotterydate,mid(TicketNumber,1,1) as ticketdigit FROM
WinningTickets UNION ALL
SELECT lotterydate,mid(TicketNumber,2,1) as ticketdigit FROM
WinningTickets etc.

qryNumbersPlayed:
Same idea

Then, join the saved queries as above.

Frankly, I prefer the "database" approach ... :-)

Thanks much. *Now I know that my table structure is lacking. *I have
two tables but I've set them up so that the numbers entered are
allocated to one of eight fields (Date, Num1, Num2, Num3, etc). So
there is only ONE record (parent) for the winning numbers and several
(children) records (each with 8 fields) - depending on number of
tickets purchased. *My problem lied in trying to move horizontally
through the records (field by field) to make the comparison between
the winning numbers and the ticket numbers.

Well, you can keep your current "pretty" design and use the union query
approach described above to "fold" your tables so the grouping query
approach can work. Instead of Mid( ... ) just use the appropriate field to
create each row.
Thanks everyone. Just needed to be pointed in the right direction.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.