<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
	<channel>
		<title>Access database code to generate combos of 3 from Pick 5 table</title>
		<link>/blogentry/41310</link>
		<atom:link href="https://www.lotterypost.com/rss/blogcomments/41310" rel="self" type="application/rss+xml" />
		<description>LottoMining's Blog: Access database code to generate combos of 3 from Pick 5 table</description>
		<dc:language>en-us</dc:language>
		<generator>Lottery Post RSS Generator</generator>
		<item>
			<title>Comment #3</title>
			<link>/blogentry/41310#c49646</link>
			<guid isPermaLink="true">/blogentry/41310#c49646</guid>
			<pubDate>Sun, 30 May 2010 20:19:39 GMT</pubDate>
			<dc:creator>LottoMining</dc:creator>
			<description><![CDATA[<p>&#x3c;br /&#x3e;Docmd.SetWarnings False&#x3c;br /&#x3e;&#x3c;br /&#x3e;enables the append statement to continue after encountering duplicate records from the query that feeds it, otherwise an error message would be generated that would end  the sub routine unless some error handling (exception handling) had been written.  It is an implicit &#x22;brute force&#x22; method, if I may toss in this literal contradiction in terms.  (Recall that the combosof4 table should have a composite primary key to enforce uniqueness... &#x5b;&#xa0;<a href="/blogentry/41310#c49646">More</a>&#xa0;&#x5d;</p>]]></description>
			<category>LottoMining</category>
		</item>
		<item>
			<title>Comment #2</title>
			<link>/blogentry/41310#c49392</link>
			<guid isPermaLink="true">/blogentry/41310#c49392</guid>
			<pubDate>Tue, 25 May 2010 16:01:16 GMT</pubDate>
			<dc:creator>LottoMining</dc:creator>
			<description><![CDATA[<p>The BubbleSort sub can work as is in an Excel module since no piece of its syntax is tied to Excel&#x27;s object model.  The other subs and functions would have to be re-written if you wanted to call it from Excel and you&#x27;d have to set a VB Reference to the Access library so Excel&#x27;s VBA IDE could understand the Access syntax. The code would need to create an  object variable, which would be an instance of Access and then you could &#x22;call&#x22; (i.e. use) its properties and methods.... &#x5b;&#xa0;<a href="/blogentry/41310#c49392">More</a>&#xa0;&#x5d;</p>]]></description>
			<category>LottoMining</category>
		</item>
		<item>
			<title>Comment #1</title>
			<link>/blogentry/41310#c49352</link>
			<guid isPermaLink="true">/blogentry/41310#c49352</guid>
			<pubDate>Mon, 24 May 2010 12:41:08 GMT</pubDate>
			<dc:creator>CARBOB</dc:creator>
			<description><![CDATA[<p>I don&#x27;t have or use Access, will this work in Excel??</p>]]></description>
			<category>CARBOB</category>
		</item>
		<item>
			<title>Original Blog Entry: Access database code to generate combos of 3 from Pick 5 table</title>
			<link>/blogentry/41310</link>
			<guid isPermaLink="true">/blogentry/41310</guid>
			<pubDate>Mon, 24 May 2010 00:43:45 GMT</pubDate>
			<dc:creator>LottoMining</dc:creator>
			<description><![CDATA[<p>A while back an LP poster observed that that many computer generated pick 5 games have a tendency to repeat in pairs. I agreed with this finding and it had been on my list of things to program in a database to see if other interesting findings showed up. Or, how these pairs looked when looking for instances when 3 numbers repeat from the same prior day; or when 4 numbers repeat from the same prior day (a rare event though it has happened). So I wrote a database script that looks at combos of 3 (below) since I already had something for looking at pairs. Lady luck was good to me when I wrote this code last Sat 5/15; I used it to hit 3/5 four times on the LP prediction board and 5 times in real life for 17*5 or $85 (Yes I did play some of it back in the days that followed.)<br /><br />Here&#x27;s the basic logic (pseudo code):<br /><br />SELECT Fields()<br /><br />FROM [Combos of 2]<br /><br />WHERE Fields() IN [Combos of 3]<br /><br />AND/OR Fields() IN [Combos of 4]<br /><br />And these new tables would be the basis for ad hoc querying in the database.<br /><br />The script loops thru a pick 5 historical draws table and gets all 10 combos of 3 of each draw and adds it to a new table.<br /><br />In this case, the history table is for California&#x27;s Fantasy 5, which is known to have some anomalies, as chronicled in the LP forums.<br /><br />Here&#x27;s a list of the two tables and their data types:<br /><br />Table: Combosof3 (new table resulting from processing)<br /><br />note: idx, Num1, Num2, Num3 must all be selected as a composite primary key<br /><br />Fields:<br /><br />Date datetime<br /><br />idx number<br /><br />Num1 number<br /><br />Num2 number<br /><br />Num3 number<br /><br />NumX text<br /><br />Table: tblData (history table of draws)<br /><br />Fields:<br /><br />Date datetime<br /><br />idx number<br /><br />D1 number<br /><br />D2 number<br /><br />D3 number<br /><br />D4 number<br /><br />D5 number<br /><br />Here&#x27;s the code; add it to a new Access DB module (it is DAO; it will work in Access 2000/2003/2007)(Credit for<br /><br />the BubbleSort sub-routine goes to John Walkenback aka Mr Spreadsheet and author of many Excel books, two of which I bought):<br /><br />Option Compare Database<br /><br />Option Explicit<br /><br />Sub GenerateCombosof3()<br /><br />Dim db As Database<br /><br />Dim rs, rsCombo As Recordset<br /><br />Dim strSQL, strSQLcombo, strDate As String<br /><br />Dim Indx As Integer<br /><br />Dim ArNums(1 To 3) As Integer<br /><br />Dim a, ValX, AppendCount As Integer<br /><br />Dim Num1, Num2, Num3 As Integer<br /><br />Dim strNumX As String<br /><br />strSQL = SELECT Date, D1, D2, D3, D4, D5, Idx _<br /><br />FROM tblData _<br /><br />ORDER BY Date DESC;<br /><br />Set db = CurrentDb<br /><br />Set rs = db.OpenRecordset(strSQL)<br /><br />With rs<br /><br />rs.MoveFirst<br /><br />Do<br /><br />Call DeleteQDefIfExistsX( UD1 )<br /><br />Call CreateUnionQDefX(rs!Date, UD1 )<br /><br />strDate = # CStr(rs!Date) #<br /><br />Indx = rs!Idx<br /><br />strSQLcombo = SELECT UD1.Drw AS Num1, T2.Drw AS Num2, T3.Drw AS Num3 _<br /><br />FROM UD1, UD1 AS T2, UD1 AS T3 _<br /><br />WHERE (((UD1.Drw) [T2].[Drw] And (UD1.Drw) [T3].[Drw]) _<br /><br />AND ((T2.Drw) [UD1].[Drw] And (T2.Drw) [T3].[Drw]) _<br /><br />AND ((T3.Drw) [UD1].[Drw] And (T3.Drw) [T2].[Drw])) _<br /><br />ORDER BY UD1.Drw, T2.Drw, T3.Drw;<br /><br />Set rsCombo = db.OpenRecordset(strSQLcombo)<br /><br />With rsCombo<br /><br />rsCombo.MoveFirst<br /><br />Do<br /><br />Num1 = rsCombo!Num1<br /><br />Num2 = rsCombo!Num2<br /><br />Num3 = rsCombo!Num3<br /><br />strNumX = CStr(rsCombo!Num1) - CStr(rsCombo!Num2) - CStr(rsCombo!Num3)<br /><br />For a = 1 To 3<br /><br />ValX = Switch(a = 1, Num1, a = 2, Num2, a = 3, Num3)<br /><br />ArNums(a) = ValX<br /><br />Next<br /><br />a = a - 1<br /><br />Call BubbleSort(ArNums())<br /><br />Num1 = ArNums(a - 2)<br /><br />Num2 = ArNums(a - 1)<br /><br />Num3 = ArNums(a)<br /><br />DoCmd.SetWarnings False<br /><br />DoCmd.RunSQL INSERT INTO Combosof3 ( [Date], idx, Num1, Num2, Num3, NumX ) _<br /><br />SELECT strDate , Indx , Num1 , Num2 , Num3 , &#x27; strNumX &#x27;;<br /><br />DoCmd.SetWarnings True<br /><br />rsCombo.MoveNext<br /><br />Loop Until rsCombo.EOF<br /><br />End With<br /><br />rs.MoveNext<br /><br />Loop Until rs.EOF<br /><br />End With<br /><br />Set rs = Nothing<br /><br />MsgBox done<br /><br />End Sub<br /><br />Function CreateUnionQDefX(dteIn As Date, qdefName As String)<br /><br />Dim db As Database, rs As Recordset, qdef1 As QueryDef, qdef2 As QueryDef, sDate As String<br /><br />sDate = # CStr(dteIn) #<br /><br />Set db = CurrentDb<br /><br />Set qdef1 = db.CreateQueryDef(qdefName, SELECT tblData.Idx, tblData.Date, tblData.D1 AS Drw _<br /><br />FROM tblData _<br /><br />WHERE (((tblData.Date) = sDate )) _<br /><br />Union ALL _<br /><br />SELECT tblData.Idx, tblData.Date, tblData.D2 _<br /><br />FROM tblData _<br /><br />WHERE (((tblData.Date) = sDate )) _<br /><br />Union ALL _<br /><br />SELECT tblData.Idx, tblData.Date, tblData.D3 _<br /><br />FROM tblData _<br /><br />WHERE (((tblData.Date) = sDate )) _<br /><br />Union ALL _<br /><br />SELECT tblData.Idx, tblData.Date, tblData.D4 _<br /><br />FROM tblData _<br /><br />WHERE (((tblData.Date) = sDate )) _<br /><br />UNION ALL _<br /><br />SELECT tblData.Idx, tblData.Date, tblData.D5 _<br /><br />FROM tblData _<br /><br />WHERE (((tblData.Date)= sDate )); )<br /><br />End Function<br /><br />Function DeleteQDefIfExistsX(strIn As String)<br /><br />Dim db As Database, rs As Recordset, qdf As QueryDef, qCt As Integer, x As Integer<br /><br />Set db = CurrentDb<br /><br />For Each qdf In CurrentDb.QueryDefs<br /><br />&#x27;Debug.Print qdf.Name<br /><br />If qdf.Name = strIn Then<br /><br />CurrentDb.QueryDefs.Delete (strIn)<br /><br />Exit For<br /><br />End If<br /><br />Next<br /><br />End Function<br /><br />Sub BubbleSort(list() As Integer)<br /><br />Dim First As Integer, Last As Integer, i As Integer, j As Integer, temp<br /><br />First = LBound(list)<br /><br />Last = UBound(list)<br /><br />For i = First To Last - 1<br /><br />For j = i + 1 To Last<br /><br />If list(i) list(j) Then<br /><br />temp = list(j)<br /><br />list(j) = list(i)<br /><br />list(i) = temp<br /><br />End If<br /><br />Next j<br /><br />Next i<br /><br />End Sub<br /><br />... &#x5b;&#xa0;<a href="/blogentry/41310">More</a>&#xa0;&#x5d;</p>]]></description>
			<category>Blog Entry</category>
			<category>LottoMining</category>
			<wfw:comment>https://www.lotterypost.com/blogentry/41310</wfw:comment>
		</item>
	</channel>
</rss>

