<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Random Numbers Repeating</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Wed, 08 Feb 2012 23:58:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34519</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 28 Aug 2008 21:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34519</guid>
		<description>&lt;p&gt;fzz:  I don&#039;t send these temporary identifiers into Access.  I do use INSERT with every field except RoyaltyLineID which Access dutifully fills in.  Here&#039;s the scenario:&lt;/p&gt;
&lt;p&gt;Invoice has one or many InvoiceLines&lt;br&gt;
InvoiceLines as one or many RoyaltyLines&lt;/p&gt;
&lt;p&gt;When the user selects and invoice, the Invoice, InvoiceLines, RoyaltyLines and other classes are filled from Access.  Then the user can add, delete, or edit the Royaltylines.  If they add a RoyaltyLine, I don&#039;t immediately write that to the database, only when they &#039;Save&#039;.  But at this point, my RoyaltyLines collection contains both Access records and non-Access records.  That means there&#039;s the potential for a clash between Access&#039; autonumber and my temporary one.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>fzz:  I don&#8217;t send these temporary identifiers into Access.  I do use INSERT with every field except RoyaltyLineID which Access dutifully fills in.  Here&#8217;s the scenario:</p>
<p>Invoice has one or many InvoiceLines<br />
InvoiceLines as one or many RoyaltyLines</p>
<p>When the user selects and invoice, the Invoice, InvoiceLines, RoyaltyLines and other classes are filled from Access.  Then the user can add, delete, or edit the Royaltylines.  If they add a RoyaltyLine, I don&#8217;t immediately write that to the database, only when they &#8216;Save&#8217;.  But at this point, my RoyaltyLines collection contains both Access records and non-Access records.  That means there&#8217;s the potential for a clash between Access&#8217; autonumber and my temporary one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Alexander</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34517</link>
		<dc:creator>Mike Alexander</dc:creator>
		<pubDate>Thu, 28 Aug 2008 21:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34517</guid>
		<description>&lt;p&gt;Of course, my suggestion would require the field that holds your unique identifier to be text field.&lt;/p&gt;
&lt;p&gt;My granpa always told me (in a scruffy granpa voice), &quot;Good database design prescribes the use of number fields only for values that are to be used in calculations.  Stay away from numeric identifiers because you will never add them.&quot;&lt;/p&gt;
&lt;p&gt;Crazy grandpa....&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Of course, my suggestion would require the field that holds your unique identifier to be text field.</p>
<p>My granpa always told me (in a scruffy granpa voice), &#8220;Good database design prescribes the use of number fields only for values that are to be used in calculations.  Stay away from numeric identifiers because you will never add them.&#8221;</p>
<p>Crazy grandpa&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Alexander</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34516</link>
		<dc:creator>Mike Alexander</dc:creator>
		<pubDate>Thu, 28 Aug 2008 21:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34516</guid>
		<description>&lt;p&gt;DK,  &lt;/p&gt;
&lt;p&gt;(mcolRoyLines.Count + 1) * -1  would essentially give you what Dermot suggested, which is sequential negative numbers. This should be rock solid. &lt;/p&gt;
&lt;p&gt;Since I&#039;m lazy, I would simply prefixed the manually generated autonumbering with text;  As in Admin438?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>DK,  </p>
<p>(mcolRoyLines.Count + 1) * -1  would essentially give you what Dermot suggested, which is sequential negative numbers. This should be rock solid. </p>
<p>Since I&#8217;m lazy, I would simply prefixed the manually generated autonumbering with text;  As in Admin438?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34515</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Thu, 28 Aug 2008 17:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34515</guid>
		<description>&lt;p&gt;You&#039;re building records outside Access, and you need unique ID fields in your collection outside Access. The records in this collection would eventually be fed to Access. And you&#039;re feeding the temporary ID fields used in your collection in addition to the information fields to the Access table.&lt;/p&gt;
&lt;p&gt;Why?&lt;/p&gt;
&lt;p&gt;Access supports SQL INSERT statements for a subset of the fields in a table, and as long as you don&#039;t include the temporary ID field from your collection in the INSERT operation into your Access table, Access will generate new unique, NONCLASHING primary keys or autonumber fields for the new records. You may need to dump your collection into a temporary table then insert that table into your main access table, but you&#039;d never have to worry about key clashes again.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You&#8217;re building records outside Access, and you need unique ID fields in your collection outside Access. The records in this collection would eventually be fed to Access. And you&#8217;re feeding the temporary ID fields used in your collection in addition to the information fields to the Access table.</p>
<p>Why?</p>
<p>Access supports SQL INSERT statements for a subset of the fields in a table, and as long as you don&#8217;t include the temporary ID field from your collection in the INSERT operation into your Access table, Access will generate new unique, NONCLASHING primary keys or autonumber fields for the new records. You may need to dump your collection into a temporary table then insert that table into your main access table, but you&#8217;d never have to worry about key clashes again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Cone</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34514</link>
		<dc:creator>Jim Cone</dc:creator>
		<pubDate>Thu, 28 Aug 2008 16:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34514</guid>
		<description>&lt;p&gt;Ok, I&#039;ll take the bait - grin&lt;/p&gt;
&lt;p&gt;clsRoyaltyLine.RoyaltyLineID = mcolRoyLines.Count + 1 * -1&lt;br&gt;
Should be...&lt;br&gt;
clsRoyaltyLine.RoyaltyLineID = (mcolRoyLines.Count + 1) * -1&lt;/p&gt;
&lt;p&gt;-OR-&lt;/p&gt;
&lt;p&gt;This might be more efficient...&lt;/p&gt;
&lt;p&gt;Private Declare Function timeGetTime Lib &quot;winmm.dll&quot;() As Long&lt;br&gt;
&#039;(Returns the number of milliseconds that have elasped since Windows started.)&lt;br&gt;
clsRoyaltyLine.RoyaltyLineID = timeGetTime&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ok, I&#8217;ll take the bait &#8211; grin</p>
<p>clsRoyaltyLine.RoyaltyLineID = mcolRoyLines.Count + 1 * -1<br />
Should be&#8230;<br />
clsRoyaltyLine.RoyaltyLineID = (mcolRoyLines.Count + 1) * -1</p>
<p>-OR-</p>
<p>This might be more efficient&#8230;</p>
<p>Private Declare Function timeGetTime Lib &#8220;winmm.dll&#8221;() As Long<br />
&#8216;(Returns the number of milliseconds that have elasped since Windows started.)<br />
clsRoyaltyLine.RoyaltyLineID = timeGetTime</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34512</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 28 Aug 2008 15:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34512</guid>
		<description>&lt;p&gt;One problem with sequential: Some of the class members are already in the database and will have a autonumber assigned by Access.  If I use a Count to go sequential, it could clash with one of those.  So I think I&#039;ll go with&lt;/p&gt;
&lt;p&gt;clsRoyaltyLine.RoyaltyLineID = mcolRoyLines.Count + 1 * -1&lt;/p&gt;
&lt;p&gt;The Count suggestion and the Negative suggestion combined should make it rock solid.  Right?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>One problem with sequential: Some of the class members are already in the database and will have a autonumber assigned by Access.  If I use a Count to go sequential, it could clash with one of those.  So I think I&#8217;ll go with</p>
<p>clsRoyaltyLine.RoyaltyLineID = mcolRoyLines.Count + 1 * -1</p>
<p>The Count suggestion and the Negative suggestion combined should make it rock solid.  Right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34511</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 28 Aug 2008 15:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34511</guid>
		<description>&lt;p&gt;I won&#039;t be calling the database for this number because it would produce too many calls and performance would suffer.  I agree that I should be using built-in stuff whenever possible, but the cost is too high in this case.  It seems like sequential is the way to go.  Not sure why I didn&#039;t think of that.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I won&#8217;t be calling the database for this number because it would produce too many calls and performance would suffer.  I agree that I should be using built-in stuff whenever possible, but the cost is too high in this case.  It seems like sequential is the way to go.  Not sure why I didn&#8217;t think of that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nat</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34509</link>
		<dc:creator>Nat</dc:creator>
		<pubDate>Thu, 28 Aug 2008 00:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34509</guid>
		<description>&lt;p&gt;Replace Access with SQL Server Express, Int ID with GUID ID, although that is probably not want you want to hear :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Replace Access with SQL Server Express, Int ID with GUID ID, although that is probably not want you want to hear <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dermot</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34508</link>
		<dc:creator>dermot</dc:creator>
		<pubDate>Thu, 28 Aug 2008 00:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34508</guid>
		<description>&lt;p&gt;To keep it really simple, why not start at -1 and count backwards(-2, -3,...). Because this negative sequence will never clash with the(positive) autonumbers&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>To keep it really simple, why not start at -1 and count backwards(-2, -3,&#8230;). Because this negative sequence will never clash with the(positive) autonumbers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias Brandewinder</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/08/27/random-numbers-repeating/#comment-34506</link>
		<dc:creator>Mathias Brandewinder</dc:creator>
		<pubDate>Wed, 27 Aug 2008 21:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1888#comment-34506</guid>
		<description>&lt;p&gt;Here is a possible alternative: rather than unique numbers, use Guids. They are very convenient to use ( myClass.Id = Guid.NewGuid), and have pretty strong guarantees of being unique.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here is a possible alternative: rather than unique numbers, use Guids. They are very convenient to use ( myClass.Id = Guid.NewGuid), and have pretty strong guarantees of being unique.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

