<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Philben - Ms Access</title>
	<atom:link href="https://blog.developpez.com/philben/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/philben</link>
	<description></description>
	<lastBuildDate>Thu, 26 Sep 2013 19:43:53 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>VBA : Date de fin d&#8217;une période</title>
		<link>https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode</link>
		<comments>https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode#comments</comments>
		<pubDate>Sat, 21 Sep 2013 09:24:50 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=817</guid>
		<description><![CDATA[Pour faire suite au billet précédent, cette fonction retourne la date de fin de la période choisie (mois, bimestre, trimestre, quadrimestre, semestre et année). La fonction Public Function DateFinPeriode(ByVal DateRef As Date, ByVal Periode As Integer) As Date &#160; &#160;Select &#8230; <a href="https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Pour faire suite au <a href="http://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode" title="VBA : Date de début d’une période" target="_blank">billet précédent</a>, cette fonction retourne la date de fin de la période choisie (mois, bimestre, trimestre, quadrimestre, semestre et année).<br />
<span id="more-817"></span><br />
<strong>La fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateFinPeriode(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Periode <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> Periode<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 1, 2, 3, 4, 6, 12<br />
&nbsp; &nbsp; &nbsp; DateFinPeriode = DateSerial(Year(DateRef), Int((Month(DateRef) - 1) / Periode) * Periode + Periode + 1, 0)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Exemples</strong><br />
Des exemples à exécuter dans la fenêtre ‘Exécution’ (Ctrl+G) de l’éditeur VBA (Alt+F11).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?DateFinPeriode(#2013/09/20#,1) <span style="color: #008000;">'Mois -&gt; 30/09/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,2) <span style="color: #008000;">'Bimestre -&gt; 31/10/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,3) <span style="color: #008000;">'Trimestre -&gt; 30/09/2013<br />
</span>?DateFinPeriode(#2013/09/20#,4) <span style="color: #008000;">'Quadrimestre -&gt; 31/12/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,6) <span style="color: #008000;">'Semestre -&gt; 31/12/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,12) 'Annuelle -&gt; 31/12/2013</div></div>
<p>&nbsp;<br />
<strong>Vérification</strong><br />
Résultats dans la fenêtre &lsquo;Exécution&rsquo;</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestFinPeriode()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, y <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, c <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, aDerDate(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, aCpt(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, bErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #008000;">'vba.Array retourne toujours un tableau de base zéro (indépendance vis à vis de Option Base) contrairement à Array()<br />
</span> &nbsp; <span style="color: #008000;">'Mais en règle générale, on utilise Array()<br />
</span> &nbsp; v = VBA.Array(1, 2, 3, 4, 6, 12)<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;Randomize<br />
&nbsp; &nbsp;y = Int(3000 * Rnd) + 100<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Année aléatoire : &quot;</span> &amp; y<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Mois&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Mensuel(1)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Bimestre(2)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Trimes.(3)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Quadri.(4)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Semestre(6)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Année(12)&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000;">'affecte une date initiale non interférente<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(aDerDate) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(aDerDate): aDerDate(j) = #5/15/2000#: <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 12<br />
&nbsp; &nbsp; &nbsp; r = DateSerial(y, i, Int(28 * Rnd) + 1) &nbsp; &nbsp;<span style="color: #008000;">'28 maxi pour février...<br />
</span> &nbsp; &nbsp; &nbsp;s = Format(r, <span style="color: #800000;">&quot;mm &nbsp;&quot;</span>) &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = DateFinPeriode(r, v(j))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> d &lt;&gt; aDerDate(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Month(d) &lt;&gt; Month(aDerDate(j)) <span style="color: #8D38C9; font-weight: bold;">And</span> Year(d) = y <span style="color: #8D38C9; font-weight: bold;">Then</span> aCpt(j) = aCpt(j) + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; c &amp; d &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aDerDate(j) = d<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> aCpt(i) &lt;&gt; 12 \ v(i) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Erreur détectée pour la période n°&quot;</span> &amp; (i + 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bErr = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> bErr <span style="color: #8D38C9; font-weight: bold;">Then</span> Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Aucune erreur détectée...&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Date de début d&#8217;une période</title>
		<link>https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode</link>
		<comments>https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode#comments</comments>
		<pubDate>Fri, 20 Sep 2013 19:11:39 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=807</guid>
		<description><![CDATA[Je vous présente une fonction qui retourne, en fonction de la date passée en paramètre et la période choisie (Mois, Bimestre, Trimestre, Quadrimestre, Semestre ou Année), la première date de cette période. La fonction Public Function DateDebutPeriode(ByVal DateRef As Date, &#8230; <a href="https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je vous présente une fonction qui retourne, en fonction de la date passée en paramètre et la période choisie (Mois, Bimestre, Trimestre, Quadrimestre, Semestre ou Année), la première date de cette période.<br />
<span id="more-807"></span><br />
<strong>La fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateDebutPeriode(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Periode <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
<span style="color: #008000;">'Philben - v1.0 - Free to use<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> Periode<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 1, 2, 3, 4, 6, 12<br />
&nbsp; &nbsp; &nbsp; DateDebutPeriode = DateSerial(Year(DateRef), Int((Month(DateRef) - 1) / Periode) * Periode + 1, 1)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Paramètres</strong><br />
Le premier paramètre est la date de référence de la période, le deuxième indique le type de période : 1 pour mensuelle, 2 pour bimestrielle, 3 pour trimestrielle, 4 pour quadrimestrielle, 6 pour semestrielle et 12 pour annuelle.</p>
<p>Il y a donc dans une année, 12 périodes mensuelles, 6 bimestres, 4 trimestres, 3 quadrimestres, 2 semestres.</p>
<p><strong>Exemples</strong><br />
Des exemples à exécuter dans fenêtre &lsquo;Exécution&rsquo; (Ctrl+G) de l&rsquo;éditeur VBA (Alt+F11).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?DateDebutPeriode(#2013/09/20#,1) <span style="color: #008000;">'Mois -&gt; 01/09/2013 <br />
</span><br />
?DateDebutPeriode(#2013/08/20#,2) <span style="color: #008000;">'Bimestre -&gt; 01/07/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,2) <span style="color: #008000;">'Bimestre -&gt; 01/09/2013 <br />
</span><br />
?DateDebutPeriode(#2013/09/20#,3) <span style="color: #008000;">'Trimestre -&gt; 01/07/2013<br />
</span>?DateDebutPeriode(#2013/08/20#,4) <span style="color: #008000;">'Quadrimestre -&gt; 01/05/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,6) <span style="color: #008000;">'Semestre -&gt; 01/07/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,12) 'Annuelle -&gt; 01/01/2013</div></div>
<p>&nbsp;<br />
<strong>Vérification</strong><br />
Cette fonction teste chaque période pour chaque mois d&rsquo;une année choisie aléatoirement.<br />
Un astérisque avant une date indique un changement de période.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDebutPeriode()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, y <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, c <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, aDerDate(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, aCpt(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, bErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<br />
&nbsp; &nbsp;v = VBA.Array(1, 2, 3, 4, 6, 12)<br />
&nbsp; &nbsp;Randomize<br />
&nbsp; &nbsp;y = Int(3000 * Rnd) + 100<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Année aléatoire : &quot;</span> &amp; y<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Mois&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Mensuel(1)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Bimestre(2)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Trimes.(3)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Quadri.(4)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Semestre(6)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Année(12)&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 12<br />
&nbsp; &nbsp; &nbsp; r = DateSerial(y, i, Int(28 * Rnd) + 1) &nbsp; <span style="color: #008000;">'28 maxi pour février...<br />
</span> &nbsp; &nbsp; &nbsp;s = Format(r, <span style="color: #800000;">&quot;mm &nbsp;&quot;</span>) &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = DateDebutPeriode(r, v(j))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> d &lt;&gt; aDerDate(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Day(d) = 1 <span style="color: #8D38C9; font-weight: bold;">And</span> Year(d) = y <span style="color: #8D38C9; font-weight: bold;">Then</span> aCpt(j) = aCpt(j) + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; c &amp; d &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aDerDate(j) = d<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> aCpt(i) &lt;&gt; 12 \ v(i) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Erreur détectée pour la période n°&quot;</span> &amp; (i + 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bErr = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> bErr <span style="color: #8D38C9; font-weight: bold;">Then</span> Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Aucune erreur détectée...&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Exemple comparatif des indices de similarité</title>
		<link>https://blog.developpez.com/philben/p12219/vba-access/vba-exemple-comparatif-des-indices-de-similarite</link>
		<comments>https://blog.developpez.com/philben/p12219/vba-access/vba-exemple-comparatif-des-indices-de-similarite#comments</comments>
		<pubDate>Sat, 07 Sep 2013 17:38:26 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[SQL - Ms Access]]></category>
		<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Chaîne de caractères]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Similarité]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=772</guid>
		<description><![CDATA[Après avoir vu différents algorithmes de similarité dans des billets précédents, je vous propose un petit comparatif à travers un exemple qui consiste à trouver le doublon de restaurants par leur nom, adresse, téléphone et type de cusine. Les données &#8230; <a href="https://blog.developpez.com/philben/p12219/vba-access/vba-exemple-comparatif-des-indices-de-similarite">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après avoir vu différents algorithmes de similarité dans des billets précédents, je vous propose un petit comparatif à travers un exemple qui consiste à trouver le doublon de restaurants par leur nom, adresse, téléphone et type de cusine.<br />
<span id="more-772"></span><br />
<strong>Les données</strong><br />
Les données sont issues d&rsquo;un exemple connu de recherche de doublons et sont présentées ici dans une seule colonne où nom, adresse, téléphone et type de cuisine sont fusionnés. <a href="http://philben.developpez.com/restos.txt" title="Fichier texte des restaurants" target="_blank">Le fichier de données</a> contient 224 lignes et chaque resto possède un et un seul doublon. Cet exemple reste donc plus simple qu&rsquo;un cas général de recherche de doublons&#8230;<br />
Extrait du fichier :</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Katsu 1972 Hillhurst Ave. Los Feliz 213-665-1891 Japanese<br />
Restaurant Katsu 1972 N. Hillhurst Ave. Los Angeles 213/665-1891 Asian<br />
Les Celebrites 155 W. 58th St. New York City 212-484-5113 French (Classic)<br />
Les C&amp;eacute;l&amp;eacute;brit&amp;eacute;s 160 Central Park S New York 212/484-5113 French</div></div>
<p>Une difficulté s&rsquo;ajoute pour le dernier restaurant car les &lsquo;é&rsquo; de Célébrités sont convertis en HTML (&amp; eacute;)&#8230;</p>
<p>Le fichier source original est <a href="http://www.cs.utexas.edu/users/ml/riddle/data/restaurant.tar.gz" title="Fichier source des restaurants" target="_blank">ici</a>.</p>
<p><strong>Principe</strong><br />
Le principe est donc de rechercher pour chaque ligne, le restaurant qui a la similarité la plus forte soit 49 952 mesures (224 x 223) après conversion des chaînes en majuscule.<br />
Pour chaque restaurant, je considère que le bon doublon a été correctement trouvé s&rsquo;il arrive avec le plus fort indice par rapport aux 222 autres restaurants.<br />
J&rsquo;ai comparé les 3 algorithmes <a href="http://blog.developpez.com/philben/p12207/vba-access/vba-distance-de-jaro-winkler" title="VBA : Distance de Jaro-Winkler" target="_blank">Jaro-Winkler (JW)</a>, <a href="http://blog.developpez.com/philben/p11268/vba-access/similarite_entre_deux_chaines_de_caracte" title="Similarité entre deux chaînes de caractères" target="_blank">Damerau-Levenshtein (DL)</a> et les <a href="http://blog.developpez.com/philben/p11340/vba-access/indices-de-similarite-entre-deux-chaines-de-caracteres" title="Indices de similarité entre deux chaînes de caractères" target="_blank">6 indices Cosinus/Dice/Jaccard/&#8230; (IS)</a>, en recherchant pour chacun la meilleure configuration.</p>
<p><strong>Résultats</strong><br />
Concernant DL, pas de problème pour trouver la meilleure configuration car il suffit de passer les 2 chaînes en argument de la fonction.<br />
<strong>Damerau-Levenshtein a permis de détecter <strong>185 doublons sur 224 soit 82,6%</strong> de réussite.</strong></p>
<p>Concernant Jaro-Winkler, on peut jouer sur la longueur du préfixe entre 0 et 4. Les résultats obtenus sont :</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Longueur préfixe &nbsp; &nbsp; &nbsp; &nbsp;Doublons détectés<br />
&nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 206<br />
&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 209<br />
&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 214<br />
&nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 213<br />
&nbsp; &nbsp; &nbsp; &nbsp; 4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 212</div></div>
<p>Dans cet exemple, la <strong>meilleure longueur de préfixe est 2 avec 214 doublons détectés soit un taux de réussite de 95,5%</strong>, la distance de Jaro seule (0) donne le moins bon résultat.</p>
<p>Enfin pour l&rsquo;algorithme IS, le choix du paramétrage est plus complexe car on peut choisir entre 6 indices de similarités, la longueur des Grammes (0 = mot à 5), l&rsquo;inversion ou non des grammes et une distance maximum de recherche des grammes communs.<br />
Pour la distance maxi, j&rsquo;ai laissé à -1 (pas de limite de distance) car elle fournit les meilleurs résultats dans cet exemple et la recherche de grammes inversés donne ici de moins bons résultats.</p>
<p>J&rsquo;ai donc joué sur le reste des paramètres (type d&rsquo;indice et longueur des grammes) et les résultats sont synthétisés ici :<br />
<img src="http://philben.developpez.com/restos.png" alt="Paramétrage des indices de similarité et résultats" /><br />
Les unigrammes (1) ont les moins bon résultats, la variabilité des résultats entre les indices diminue avec la longueur des grammes, les trigrammes et Simpson ont en moyenne les meilleurs résultats.</p>
<p>Pourcentage de réussite des indices en fonction de la longueur des grammes :<br />
<img src="http://philben.developpez.com/restosGraphe.png" alt="Pourcentage de réussites des indices en fonction de la longueur des grammes" /><br />
<strong>Finalement, l&rsquo;indice de Simpson avec des bigrammes donne ici le meilleur résultat : 219 doublons détectés soit 97,8% de réussite !</strong></p>
<p>Le tableau suivant indique le nombre de doublons détectés par position des résultats hormis le Top 1. Par exemple, 18 nouvelles bonnes détections faites par DL dans les Top 2 des résultats et <strong>Simpson en détecte 4 soit 223 détections cumulées (Top 1 et Top 2) sur 224 !</strong>.<br />
<img src="http://philben.developpez.com/restosPositions.png" alt="Nombre de détections en fonction de la position des résultats" /></p>
<p>Après avoir vu rapidement la capacité des indices à détecter les vrais doublons, il faut vérifier leur capacité à être discriminant entre les restaurants et compter les éventuels ex aequo.<br />
Imaginez un algo qui retourne un indice identique pour tous les restos : Ses résultats seraient parfaits mais pour chaque restaurant on aurait 223 restaurants détectés dans le Top 1 !</p>
<p>Via une requête, j&rsquo;ai donc calculé la position absolue du vrai doublon pour chaque algorithme et chaque ligne. Des ex aequo sont présents si la position absolue est supérieure au classement.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Indice&nbsp; Classement &nbsp; Position absolue<br />
---------------------------------------<br />
JW&nbsp; &nbsp; &nbsp; 28 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;29<br />
---------------------------------------<br />
IS&nbsp; &nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2<br />
---------------------------------------<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;12<br />
DL&nbsp; &nbsp; &nbsp; &nbsp;9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;11<br />
DL&nbsp; &nbsp; &nbsp; 12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;20<br />
DL&nbsp; &nbsp; &nbsp; 17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;21<br />
DL&nbsp; &nbsp; &nbsp; 24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;66</div></div>
<p>JW n&rsquo;est affecté qu&rsquo;une fois par un ex aequo et ceci pour un classement du vrai doublon en 28ème position.<br />
IS en a obtenu un seul sur un Top 1 et DL a eu 13 fois un ou plusieurs ex aequo.</p>
<p><strong>Conclusion</strong><br />
Dans cet exemple, l&rsquo;indice de Simpson a détecté le plus de doublons dans le Top 1 (219 sur 224) et 223 dans le Top 2 des résultats.<br />
Si vous le souhaitez, vous pouvez ajouter <strong>vos propres résultats</strong> de vos algorithmes en commentaire du billet.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Recherche d&#8217;une sous-chaîne particulière par la fin</title>
		<link>https://blog.developpez.com/philben/p12218/vba-access/vba-recherche-dune-sous-chaine-particuliere-par-la-fin</link>
		<comments>https://blog.developpez.com/philben/p12218/vba-access/vba-recherche-dune-sous-chaine-particuliere-par-la-fin#comments</comments>
		<pubDate>Sat, 07 Sep 2013 11:13:09 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Chaîne de caractères]]></category>
		<category><![CDATA[Code VBA]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=763</guid>
		<description><![CDATA[Après avoir vu l&#8217;extraction d&#8217;un token particulier depuis le début de la chaîne de caractère, je vous présente sa version depuis la fin de la chaîne. Objectif Extraire un token par son numéro d&#8217;apparition dans une chaîne de caractère mais &#8230; <a href="https://blog.developpez.com/philben/p12218/vba-access/vba-recherche-dune-sous-chaine-particuliere-par-la-fin">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après avoir vu <a href="http://blog.developpez.com/philben/p11126/vba-access/extraire_un_token_d_une_chaine" title="Extraire un token d’une chaîne de caractères" target="_blank">l&rsquo;extraction d&rsquo;un token particulier </a>depuis le début de la chaîne de caractère, je vous présente sa version depuis la fin de la chaîne.<br />
<span id="more-763"></span><br />
<strong>Objectif</strong><br />
Extraire un token par son numéro d&rsquo;apparition dans une chaîne de caractère mais en partant de la fin de la chaîne.<br />
Par exemple, de la chaîne &lsquo;ab-cd-ef-gh&rsquo; je souhaite extraire &lsquo;ef&rsquo; qui est l&rsquo;avant-dernier token (ou sous-chaîne délimitée) depuis le dernier caractère séparateur &lsquo;-&lsquo;, ou bien le dernier token (&lsquo;gh&rsquo;), le 3ème (&lsquo;cd&rsquo;),&#8230;</p>
<p><strong>Comment faire simple ?</strong><br />
Pour ne pas réinventer la roue , je me suis appuyé sur notre fonction <a href="http://blog.developpez.com/philben/p11126/vba-access/extraire_un_token_d_une_chaine" title="Extraire un token d’une chaîne de caractères" target="_blank">TokenBySplit()</a> et la fonction standard VBA StrReverse() qui inverse la chaîne de caractère passée en argument (&lsquo;ab&rsquo; deviendra &lsquo;ba&rsquo;).</p>
<p><strong>La fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TokenReverse(<span style="color: #151B8D; font-weight: bold;">ByVal</span> Texte <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Separateur <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Numero <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> TypeComparaison <span style="color: #151B8D; font-weight: bold;">As</span> VbCompareMethod = vbBinaryCompare) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span><br />
<span style="color: #008000;">'Retourne le token spécifié par son numéro à partir de la fin de la chaîne de caractère<br />
</span><span style="color: #008000;">'Auteur : Philben - v1.0<br />
</span><span style="color: #008000;">'Exemple : TokenReverse(&quot;ab-cd-ef-gh&quot;,&quot;-&quot;,2) -&gt; ef (2ème token en partant de la fin)<br />
</span> &nbsp; &nbsp;TokenReverse = StrReverse(TokenBySplit(StrReverse(Texte), Separateur, Numero, TypeComparaison))<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Exemples</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?TokenReverse(<span style="color: #800000;">&quot;ab-cd-ef-gh&quot;</span>,<span style="color: #800000;">&quot;-&quot;</span>,1) <span style="color: #008000;">'gh<br />
</span>?TokenReverse(<span style="color: #800000;">&quot;ab-cd-ef-gh&quot;</span>,<span style="color: #800000;">&quot;-&quot;</span>,2) <span style="color: #008000;">'ef<br />
</span>?TokenReverse(<span style="color: #800000;">&quot;ab-cd-ef-gh&quot;</span>,<span style="color: #800000;">&quot;-&quot;</span>,3) <span style="color: #008000;">'cd<br />
</span>?TokenReverse(<span style="color: #800000;">&quot;ab-cd-ef-gh&quot;</span>,<span style="color: #800000;">&quot;-&quot;</span>,4) <span style="color: #008000;">'ab<br />
</span>?TokenReverse(<span style="color: #800000;">&quot;ab-cd-ef-gh&quot;</span>,<span style="color: #800000;">&quot;-&quot;</span>,5) 'Nada !</div></div>
<p>&nbsp;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Distance de Jaro-Winkler</title>
		<link>https://blog.developpez.com/philben/p12207/vba-access/vba-distance-de-jaro-winkler</link>
		<comments>https://blog.developpez.com/philben/p12207/vba-access/vba-distance-de-jaro-winkler#comments</comments>
		<pubDate>Sat, 31 Aug 2013 03:01:16 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[SQL - Ms Access]]></category>
		<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Chaîne de caractères]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Similarité]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=703</guid>
		<description><![CDATA[Cet algorithme mesure la similarité entre deux chaînes de caractères pour la recherche de doublons par exemple. Tout comme les algorithmes de Damerau-Levenshtein et les indices de similarité Cosinus, Dice, Jaccard&#8230;, la distance est normalisée entre 0 et 1. Plus &#8230; <a href="https://blog.developpez.com/philben/p12207/vba-access/vba-distance-de-jaro-winkler">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Cet algorithme mesure la similarité entre deux chaînes de caractères pour la recherche de doublons par exemple. Tout comme les algorithmes de <a href="http://blog.developpez.com/philben/p11268/vba-access/similarite_entre_deux_chaines_de_caracte" title="Similarité entre deux chaînes de caractères" target="_blank">Damerau-Levenshtein</a> et les <a href="http://blog.developpez.com/philben/p11340/vba-access/indices-de-similarite-entre-deux-chaines-de-caracteres" title="Indices de similarité entre deux chaînes de caractères" target="_blank">indices de similarité Cosinus, Dice, Jaccard&#8230;</a>, la distance est normalisée entre 0 et 1. Plus la similarité est forte plus la distance tend vers 1.<br />
<span id="more-703"></span><br />
<strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> JaroWinkler(<span style="color: #151B8D; font-weight: bold;">ByVal</span> s1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> s2 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> LongueurPrefixe <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Byte</span> = 3, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> TypeComparaison <span style="color: #151B8D; font-weight: bold;">As</span> VbCompareMethod = vbBinaryCompare) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Single</span><br />
<span style="color: #008000;">'La distance de jaro_Winkler mesure la similarité entre deux chaines de caractères (s1 et s2)<br />
</span><span style="color: #008000;">'La distance est normalisée entre 0 et 1 (1 = similarité maximale)<br />
</span><span style="color: #008000;">'si LongueurPrefixe [0,4] = 0 =&gt; Distance de Jaro<br />
</span><span style="color: #008000;">'Référence : http://fr.wikipedia.org/wiki/Distance_de_Jaro-Winkler et références<br />
</span><span style="color: #008000;">'Remarques : Préparation parfois nécessaire des chaînes : ucase(),trim(),diacritiques<br />
</span><span style="color: #008000;">' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Quelques libertés prises pour le calcul de la fenêtre (dMax) / Wikipédia<br />
</span><span style="color: #008000;">'Auteur : Philben v1.0 - Free to use<br />
</span> &nbsp; Const cMaxLongueurPrefixe <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Byte</span> = 4, cCoeffPrefixe <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Single</span> = 0.1<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> l1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, l2 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, dMax <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> jMin <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, jMax <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, m <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, t <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, p <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, lam1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> c1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Single</span>, aUsed() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span>, ac2() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, am1() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span><br />
<br />
&nbsp; &nbsp;l1 = Len(s1): l2 = Len(s2)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> l1 &gt; 0 <span style="color: #8D38C9; font-weight: bold;">And</span> l2 &gt; 0 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #151B8D; font-weight: bold;">ReDim</span> aUsed(1 <span style="color: #8D38C9; font-weight: bold;">To</span> l2): <span style="color: #151B8D; font-weight: bold;">ReDim</span> ac2(1 <span style="color: #8D38C9; font-weight: bold;">To</span> l2)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> l2: ac2(i) = Mid$(s2, i, 1): <span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> l1 &gt;= l2 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">'dMax (1/2 fenêtre) calculée avec la + courte chaîne et non la + longue ! (voir blog)<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; dMax = (l2 + 1) \ 2 - 1 &nbsp; <span style="color: #008000;">'arrondi sup. de dMax (l=1 =&gt; 0, l=2 =&gt; 0, l=3 =&gt; 1)<br />
</span> &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dMax = (l1 + 1) \ 2 - 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> LongueurPrefixe &gt; cMaxLongueurPrefixe <span style="color: #8D38C9; font-weight: bold;">Then</span> LongueurPrefixe = cMaxLongueurPrefixe<br />
<br />
&nbsp; &nbsp; &nbsp; jMin = 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> dMax &lt; l2 <span style="color: #8D38C9; font-weight: bold;">Then</span> jMax = dMax <span style="color: #8D38C9; font-weight: bold;">Else</span>: jMax = l2<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> l1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c1 = Mid$(s1, i, 1)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> i &gt; dMax + 1 <span style="color: #8D38C9; font-weight: bold;">Then</span> jMin = jMin + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> jMax &lt; l2 <span style="color: #8D38C9; font-weight: bold;">Then</span> jMax = jMax + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> jMin &gt; jMax <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #8D38C9; font-weight: bold;">For</span> &nbsp; <span style="color: #008000;">'définitivement hors fenêtre =&gt; Fin<br />
</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> j = jMin <span style="color: #8D38C9; font-weight: bold;">To</span> jMax<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> aUsed(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> StrComp(c1, ac2(j), TypeComparaison) = 0 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m = m + 1 &nbsp; <span style="color: #008000;">'Match<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> i = j <span style="color: #8D38C9; font-weight: bold;">And</span> i &lt;= LongueurPrefixe <span style="color: #8D38C9; font-weight: bold;">And</span> p = i - 1 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p = p + 1 &nbsp;<span style="color: #008000;">'Préfixe commun<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lam1 = lam1 + 1: <span style="color: #151B8D; font-weight: bold;">ReDim</span> <span style="color: #151B8D; font-weight: bold;">Preserve</span> am1(1 <span style="color: #8D38C9; font-weight: bold;">To</span> lam1): am1(lam1) = i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aUsed(j) = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #8D38C9; font-weight: bold;">For</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">'Compte les tranpositions<br />
</span> &nbsp; &nbsp; &nbsp;k = p + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> lam1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> j = k <span style="color: #8D38C9; font-weight: bold;">To</span> l2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> aUsed(j) <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #8D38C9; font-weight: bold;">For</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> StrComp(Mid$(s1, am1(i), 1), ac2(j), TypeComparaison) &lt;&gt; 0 <span style="color: #8D38C9; font-weight: bold;">Then</span> t = t + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k = j + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp; &nbsp; t = t \ 2<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> m &gt; 0 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r = (m / l1 + m / l2 + (m - t) / m) / 3 &nbsp; <span style="color: #008000;">'Distance de Jaro<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; r = r + (p * cCoeffPrefixe * (1 - r)) &nbsp; <span style="color: #008000;">'Extension de Winkler<br />
</span> &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
<br />
&nbsp; &nbsp;JaroWinkler = r<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Paramètres de la fonction</strong><br />
<strong>&lsquo;S1&prime; et &lsquo;S2&prime;</strong> correspondent aux deux chaînes de caractères à étudier.<br />
<strong>&lsquo;LongueurPrefixe&rsquo;</strong> permet de choisir la longueur du préfixe commun entre les deux chaînes. Cette longueur permet de calculer l&rsquo;apport de Winkler à l&rsquo;algorithme de Jaro. Cette longueur est comprise entre 0 et 4 (3 par défaut). La distance de Jaro est retournée lorsque ce paramètre est égal à 0.<br />
<strong>&lsquo;TypeComparaison&rsquo;</strong> permet de choisir le type de comparaison entre les deux chaînes : Soit une comparaison binaire (par défaut) soit une comparaison textuelle (moins restrictive car ne tient pas compte de la casse des caractères mais généralement moins performante).<br />
Il sera souvent nécessaire de prétraiter les chaînes par UCase()/LCase() (casse uniforme des caractères), Trim() (suppression des espaces en début et fin de chaîne) et remplacer les caractères diacritiques pour ne pas &lsquo;parasiter&rsquo; l&rsquo;algorithme (voir <a href="http://blog.developpez.com/philben/p11217/vba-access/remplacer_les_caracteres_accentues_d_une" title="Remplacer les caractères accentués d’une chaîne" target="_blank">ici</a>).</p>
<p><strong>Tests</strong><br />
J&rsquo;ai récolté dans une publication de W. E. Winkler (voir référence plus bas) et sur le Web des exemples pour tester les résultats de mon code. La longueur du préfixe est fixée à 4.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> testJW()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Single</span>, v() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span><br />
<br />
&nbsp; &nbsp;v = Array(<span style="color: #800000;">&quot;SHACKLEFORD&quot;</span>, <span style="color: #800000;">&quot;SHACKELFORD&quot;</span>, 0.982, <span style="color: #800000;">&quot;DUNNINGHAM&quot;</span>, <span style="color: #800000;">&quot;CUNNIGHAM&quot;</span>, 0.896, <span style="color: #800000;">&quot;NICHLESON&quot;</span>, <span style="color: #800000;">&quot;NICHULSON&quot;</span>, 0.956, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800000;">&quot;JONES&quot;</span>, <span style="color: #800000;">&quot;JOHNSON&quot;</span>, 0.832, <span style="color: #800000;">&quot;MASSEY&quot;</span>, <span style="color: #800000;">&quot;MASSIE&quot;</span>, 0.933, <span style="color: #800000;">&quot;ABROMS&quot;</span>, <span style="color: #800000;">&quot;ABRAMS&quot;</span>, 0.922, <span style="color: #800000;">&quot;HARDIN&quot;</span>, <span style="color: #800000;">&quot;MARTINEZ&quot;</span>, 0#, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800000;">&quot;ITMAN&quot;</span>, <span style="color: #800000;">&quot;SMITH&quot;</span>, 0#, <span style="color: #800000;">&quot;JERALDINE&quot;</span>, <span style="color: #800000;">&quot;GERALDINE&quot;</span>, 0.926, <span style="color: #800000;">&quot;MARHTA&quot;</span>, <span style="color: #800000;">&quot;MARTHA&quot;</span>, 0.961, <span style="color: #800000;">&quot;MICHELLE&quot;</span>, <span style="color: #800000;">&quot;MICHAEL&quot;</span>, 0.921, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800000;">&quot;JULIES&quot;</span>, <span style="color: #800000;">&quot;JULIUS&quot;</span>, 0.933, <span style="color: #800000;">&quot;TANYA&quot;</span>, <span style="color: #800000;">&quot;TONYA&quot;</span>, 0.88, <span style="color: #800000;">&quot;DWAYNE&quot;</span>, <span style="color: #800000;">&quot;DUANE&quot;</span>, 0.84, <span style="color: #800000;">&quot;SEAN&quot;</span>, <span style="color: #800000;">&quot;SUSAN&quot;</span>, 0.805, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800000;">&quot;JON&quot;</span>, <span style="color: #800000;">&quot;JOHN&quot;</span>, 0.933, <span style="color: #800000;">&quot;JON&quot;</span>, <span style="color: #800000;">&quot;JAN&quot;</span>, 0#, <span style="color: #800000;">&quot;DIXON&quot;</span>, <span style="color: #800000;">&quot;DICKSONX&quot;</span>, 0.813, <span style="color: #800000;">&quot;VOYAGE&quot;</span>, <span style="color: #800000;">&quot;AGENDA&quot;</span>, 0.444, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800000;">&quot;TRAVEL&quot;</span>, <span style="color: #800000;">&quot;TRAIN&quot;</span>, 0.9, <span style="color: #800000;">&quot;ABCVWXYZ&quot;</span>, <span style="color: #800000;">&quot;CABVWXYZ&quot;</span>, 0.958)<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Chaîne 1&quot;</span>, <span style="color: #800000;">&quot;Chaîne 2&quot;</span>, <span style="color: #800000;">&quot;Attendue&quot;</span>, <span style="color: #800000;">&quot;Obtenue&quot;</span><br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;--------&quot;</span>, <span style="color: #800000;">&quot;--------&quot;</span>, <span style="color: #800000;">&quot;---------&quot;</span>, <span style="color: #800000;">&quot;-------&quot;</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">Step</span> 3<br />
&nbsp; &nbsp; &nbsp; r = JaroWinkler(v(i), v(i + 1), 4) &nbsp; <span style="color: #008000;">'Longueur Prefixe = 4<br />
</span> &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> v(i), v(i + 1), v(i + 2), Round(r, 3), IIf(Abs(r - v(i + 2)) &gt; 0.001, <span style="color: #800000;">&quot;*** Ecart ***&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Résultats et commentaires</strong></p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Chaîne 1 &nbsp; &nbsp; &nbsp;Chaîne 2 &nbsp; &nbsp; &nbsp;Attendue &nbsp; &nbsp; &nbsp;Obtenue<br />
-------- &nbsp; &nbsp; &nbsp;-------- &nbsp; &nbsp; &nbsp;--------- &nbsp; &nbsp; -------<br />
SHACKLEFORD &nbsp; SHACKELFORD &nbsp; &nbsp;0,982 &nbsp; &nbsp; &nbsp; &nbsp; 0,982 &nbsp; &nbsp; &nbsp; &nbsp;<br />
DUNNINGHAM &nbsp; &nbsp;CUNNIGHAM &nbsp; &nbsp; &nbsp;0,896 &nbsp; &nbsp; &nbsp; &nbsp; 0,896 &nbsp; &nbsp; &nbsp; &nbsp;<br />
NICHLESON &nbsp; &nbsp; NICHULSON &nbsp; &nbsp; &nbsp;0,956 &nbsp; &nbsp; &nbsp; &nbsp; 0,956 &nbsp; &nbsp; &nbsp; &nbsp;<br />
JONES &nbsp; &nbsp; &nbsp; &nbsp; JOHNSON &nbsp; &nbsp; &nbsp; &nbsp;0,832 &nbsp; &nbsp; &nbsp; &nbsp; 0,832 &nbsp; &nbsp; &nbsp; &nbsp;<br />
MASSEY &nbsp; &nbsp; &nbsp; &nbsp;MASSIE &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp;<br />
ABROMS &nbsp; &nbsp; &nbsp; &nbsp;ABRAMS &nbsp; &nbsp; &nbsp; &nbsp; 0,922 &nbsp; &nbsp; &nbsp; &nbsp; 0,922 &nbsp; &nbsp; &nbsp; &nbsp;<br />
HARDIN &nbsp; &nbsp; &nbsp; &nbsp;MARTINEZ &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,722 &nbsp; &nbsp; &nbsp; &nbsp;*** Ecart ***<br />
ITMAN &nbsp; &nbsp; &nbsp; &nbsp; SMITH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,622 &nbsp; &nbsp; &nbsp; &nbsp;*** Ecart ***<br />
JERALDINE &nbsp; &nbsp; GERALDINE &nbsp; &nbsp; &nbsp;0,926 &nbsp; &nbsp; &nbsp; &nbsp; 0,926 &nbsp; &nbsp; &nbsp; &nbsp;<br />
MARHTA &nbsp; &nbsp; &nbsp; &nbsp;MARTHA &nbsp; &nbsp; &nbsp; &nbsp; 0,961 &nbsp; &nbsp; &nbsp; &nbsp; 0,961 &nbsp; &nbsp; &nbsp; &nbsp;<br />
MICHELLE &nbsp; &nbsp; &nbsp;MICHAEL &nbsp; &nbsp; &nbsp; &nbsp;0,921 &nbsp; &nbsp; &nbsp; &nbsp; 0,921 &nbsp; &nbsp; &nbsp; &nbsp;<br />
JULIES &nbsp; &nbsp; &nbsp; &nbsp;JULIUS &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp;<br />
TANYA &nbsp; &nbsp; &nbsp; &nbsp; TONYA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,88 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,88 &nbsp; &nbsp; &nbsp; &nbsp; <br />
DWAYNE &nbsp; &nbsp; &nbsp; &nbsp;DUANE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,84 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,84 &nbsp; &nbsp; &nbsp; &nbsp; <br />
SEAN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUSAN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,805 &nbsp; &nbsp; &nbsp; &nbsp; 0,805 &nbsp; &nbsp; &nbsp; &nbsp;<br />
JON &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOHN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp; 0,933 &nbsp; &nbsp; &nbsp; &nbsp;<br />
JON &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JAN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*** Ecart ***<br />
DIXON &nbsp; &nbsp; &nbsp; &nbsp; DICKSONX &nbsp; &nbsp; &nbsp; 0,813 &nbsp; &nbsp; &nbsp; &nbsp; 0,813 &nbsp; &nbsp; &nbsp; &nbsp;<br />
VOYAGE &nbsp; &nbsp; &nbsp; &nbsp;AGENDA &nbsp; &nbsp; &nbsp; &nbsp; 0,444 &nbsp; &nbsp; &nbsp; &nbsp; 0,444 &nbsp; &nbsp; &nbsp; &nbsp;<br />
TRAVEL &nbsp; &nbsp; &nbsp; &nbsp;TRAIN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,79 &nbsp; &nbsp; &nbsp; &nbsp; *** Ecart ***<br />
ABCVWXYZ &nbsp; &nbsp; &nbsp;CABVWXYZ &nbsp; &nbsp; &nbsp; 0,958 &nbsp; &nbsp; &nbsp; &nbsp; 0,958</div></div>
<p>&nbsp;<br />
Les distances obtenues sont parfois différentes des distances attendues (4 écarts constatés).<br />
Concernant les couples <strong>HARDIN/MARTINEZ, ITMAN/SMITH, JON/JAN</strong>, ils sont fournis par W. E. Winkler qui devait utiliser un algo un peu différent de celui décrit dans Wikipédia (en effet, sa fonction strcomp.c est plus complexe&#8230;)</p>
<p>Concernant le couple <strong>TRAVEL/TRAIN</strong> et la distance attendue de 0,9, je pense qu&rsquo;il s&rsquo;agit d&rsquo;une coquille de l&rsquo;auteur car la distance de Jaro dans la même publication était seulement de 0,7.</p>
<p>De plus, l&rsquo;applet java de <a href="http://arantxa.ii.uam.es/~dcamacho/StringDistance/StringDistance.htm" title="String Distance" target="_blank">ce site</a> donne des résultats proches ou identiques aux miens.</p>
<p><strong>Remarque</strong><br />
L&rsquo;éloignement maximal (variable dMax dans mon code) devrait être calculé à l&rsquo;aide de la plus grande longueur de chaîne. J&rsquo;ai préféré utiliser la plus courte pour éviter des résultats &lsquo;étonnants&rsquo; avec certaines chaînes de caractères.<br />
Par exemple, en allongeant la seconde chaîne &lsquo;cba&rsquo; et en utilisant la plus grande longueur des deux chaînes de caractères, on obtient :</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cba&quot;</span>) <span style="color: #008000;">'0,556<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbau&quot;</span>) <span style="color: #008000;">'0,528<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbauu&quot;</span>) <span style="color: #008000;">'0,756<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbauuu&quot;</span>) '0,722</div></div>
<p>La similarité diminue avec 4 caractères (0,528) puis augmente paradoxalement avec 5 caractères (&lsquo;cbauu&rsquo; donne 0,756)!<br />
<strong>Pourquoi ?</strong><br />
<strong>Dans le 1er exemple</strong>, l&rsquo;éloignement maximal (variable dMax dans le code) est égal à 1 et on obtient une seule concordance (lettre &lsquo;b&rsquo;) entre les 2 chaînes.<br />
<strong>Dans le 2ème exemple</strong>, la similarité chute légèrement car la longueur de la chaîne n°2 est de 4 au lieu de 3 et celle-ci intervient en tant que dénominateur dans le calcul de la distance de Jaro. L&rsquo;éloignement maximal reste égal à 1.<br />
<strong>Dans le 3ème exemple</strong>, l&rsquo;éloignement maximal est égal à <strong>2</strong> car la longueur de la chaîne n°2 est de 5 caractères (arrondi supérieur de 5/2 &#8211; 1 = 2). Cet éloignement permet d&rsquo;obtenir 3 correspondances (&lsquo;a&rsquo;, &lsquo;b&rsquo;, &lsquo;c&rsquo;) et une transposition (&lsquo;a&rsquo; et &lsquo;c&rsquo;). Ces 3 correspondances au lieu d&rsquo;une seule augmentent la similarité malgré la transposition et la longueur de la chaîne n°2.</p>
<p><strong>Pour éviter ce problème</strong>, une solution consiste donc à utiliser la plus petite longueur des deux chaînes :</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cba&quot;</span>) <span style="color: #008000;">'0,556<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbau&quot;</span>) <span style="color: #008000;">'0,528<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbauu&quot;</span>) <span style="color: #008000;">'0,511<br />
</span>?JaroWinkler(<span style="color: #800000;">&quot;abc&quot;</span>,<span style="color: #800000;">&quot;cbauuu&quot;</span>) '0,5</div></div>
<p>&nbsp;<br />
<strong>Conclusion</strong><br />
Algorithme rapide et efficace sur des chaînes relativement courtes.</p>
<p><strong>Références</strong><br />
Wikipédia: <a href="http://fr.wikipedia.org/wiki/Distance_de_Jaro-Winkler" title="Jaro_Winkler sur Wikipédia" target="_blank">Distance de Jaro-Winkler</a><br />
Publication de <a href="http://www.census.gov/srd/papers/pdf/rrs2006-02.pdf" title="Overview of Record Linkage and Current Research Directions" target="_blank">W. E. Winkler</a>.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : S&#8217;agit-il d&#8217;un jour ouvré non chômé ?</title>
		<link>https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome</link>
		<comments>https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome#comments</comments>
		<pubDate>Tue, 27 Aug 2013 21:12:21 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>
		<category><![CDATA[Jour férié]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=683</guid>
		<description><![CDATA[La fonction VBA présentée dans ce billet permet de savoir si la date passée en argument correspond à un jour ouvré (du lundi au vendredi) non chômé (non férié) en France. Dépendances de la fonction Nécessite la fonction EstJourFerie() et &#8230; <a href="https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La fonction VBA présentée dans ce billet permet de savoir si la date passée en argument correspond à un jour ouvré (du lundi au vendredi) non chômé (non férié) en France.<br />
<span id="more-683"></span><br />
<strong>Dépendances de la fonction</strong><br />
Nécessite la fonction <a href="http://blog.developpez.com/philben/p11458/vba-access/sagit-il-dun-jour-ferie" title="S’agit-il d’un jour férié ?" target="_blank">EstJourFerie()</a> et la fonction <a href="http://blog.developpez.com/philben/p11431/vba-access/calculer-la-date-de-paques" title="Calculer la date de Pâques" target="_blank">Paques()</a>.</p>
<p><strong>Le code de la fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> EstJourOuvreNonChome(<span style="color: #151B8D; font-weight: bold;">ByVal</span> laDate <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> EstPentecoteChome <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span> = <span style="color: #00C2FF; font-weight: bold;">True</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<span style="color: #008000;">'Retourne Vrai si la date est un jour ouvré (du lundi au vendredi) NON férié (non chômé)<br />
</span><span style="color: #008000;">'philben - free to use<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Weekday(laDate, vbMonday) &lt; 6 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> EstJourFerie(laDate, EstPentecoteChome) <span style="color: #8D38C9; font-weight: bold;">Then</span> EstJourOuvreNonChome = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Explications</strong><br />
La fonction retourne <strong>Vrai</strong> si la date passée en argument correspond à un jour ouvré non chômé.<br />
Cette fonction admet un deuxième paramètre qui permet de définir si le jour de la Pentecôte est chômé (Vrai par défaut) ou non.</p>
<p>La ligne de code <strong>&lsquo;If Weekday(&#8230;)&rsquo;</strong> filtre les jours de semaine pour ne conserver que les jours ouvrés (du lundi au vendredi). On utilise ensuite la fonction EstJourFerie(&#8230;) qui retourne Vrai s&rsquo;il s&rsquo;agit d&rsquo;un jour férié.</p>
<p><strong>Vérification des résultats</strong><br />
La fonction suivante compte les jours ouvrés non chômés pour différentes années puis compare le résultat avec la valeur attendue (données issues de <a href="http://www.joursouvres.fr/" target="_blank">ce site</a>).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestEstJourOuvreNonChome()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;v = Array(2010, 254, 2011, 253, 2012, 253, 2013, 251, 2014, 251, 2015, 252, 2016, 253, 2021, 254)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">Step</span> 2<br />
&nbsp; &nbsp; &nbsp; d = DateSerial(v(i), 1, 1)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Year(d) = v(i)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> EstJourOuvreNonChome(d) <span style="color: #8D38C9; font-weight: bold;">Then</span> l = l + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = d + 1<br />
&nbsp; &nbsp; &nbsp; Wend<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> l &lt;&gt; v(i + 1) <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Nb jours ouvrés non chômés en &quot;</span> &amp; v(i), <span style="color: #800000;">&quot; -&gt; Attendu : &quot;</span> &amp; v(i + 1), <span style="color: #800000;">&quot; -&gt; Obtenu : &quot;</span> &amp; l, IIf(l &lt;&gt; v(i + 1), <span style="color: #800000;">&quot;*** ERREUR ***&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; l = 0<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Nombre d'erreur(s) : &quot;</span> &amp; NbErr<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>Remarque : Le lundi de Pentecôte est considéré comme chômé ici.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>VBA : Date d&#8217;un premier jour de semaine du mois</title>
		<link>https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois</link>
		<comments>https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois#comments</comments>
		<pubDate>Thu, 15 Aug 2013 13:56:40 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=654</guid>
		<description><![CDATA[Episode VI de la saga &#8216;Weekday&#8217;. Cette fois-ci, on introduit la notion de mois puisque l&#8217;on souhaite obtenir la date d&#8217;un premier jour de semaine du mois de la date de référence. Quelle est la date du premier dimanche du &#8230; <a href="https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>VI</strong> de la saga &lsquo;Weekday&rsquo;. Cette fois-ci, on introduit la notion de <strong>mois</strong> puisque l&rsquo;on souhaite obtenir la date d&rsquo;un premier jour de semaine du mois de la date de référence. Quelle est la date du premier dimanche du mois ? La date du premier lundi du mois ?<br />
<span id="more-654"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>La fonction VBA</strong><br />
Nécessite la fonction <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant">DateJourSuivant()</a></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourDebutMois(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourDebutMois = DateJourSuivant(DateRef - Day(DateRef), Jour)<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>Pour atteindre rapidement le dernier jour du mois précédent, on soustrait à la date de référence son jour du mois. Par exemple le 15 août &#8211; 15 donnera le 31 juillet.<br />
On recherche ensuite le jour de semaine souhaité qui suit le dernier jour du mois précédent grâce à notre fonction DateJourSuivant().</p>
<p><strong>Tester la fonction</strong><br />
Affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourDebutMois()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dm <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, djdm <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourDebutMois()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; vbMonday: d = d + 1: Wend<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Semaine de référence du &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; au &quot;</span> &amp; Format(d + 6, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; dm = DateSerial(Year(d), Month(d), 1)<br />
&nbsp; &nbsp; &nbsp; j = i <span style="color: #151B8D; font-weight: bold;">Mod</span> 7 + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(dm) &lt;&gt; j: dm = dm + 1: Wend<br />
<br />
&nbsp; &nbsp; &nbsp; djdm = DateJourDebutMois(d, Weekday(d))<br />
&nbsp; &nbsp; &nbsp; s = s &amp; vbTab &amp; <span style="color: #800000;">&quot;-&gt; Jour recherché : &quot;</span> &amp; Format(dm, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; - Jour trouvé : &quot;</span> &amp; Format(djdm, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> djdm &lt;&gt; dm <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; d = d + 1<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s &amp; <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : S&#8217;agit-il d&#8217;un jour de week-end ?</title>
		<link>https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end</link>
		<comments>https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end#comments</comments>
		<pubDate>Thu, 15 Aug 2013 11:55:58 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=637</guid>
		<description><![CDATA[Une petite fonction qui permet de savoir si la date passée en argument correspond à une jour de week-end ou non. La fonction VBA Public Function EstWeekEnd(ByVal dDate As Date) As Boolean &#160; &#160;If Weekday(dDate, vbMonday) &#62; 5 Then EstWeekEnd &#8230; <a href="https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Une petite fonction qui permet de savoir si la date passée en argument correspond à une jour de week-end ou non.<br />
<span id="more-637"></span><br />
<strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> EstWeekEnd(<span style="color: #151B8D; font-weight: bold;">ByVal</span> dDate <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> Weekday(dDate, vbMonday) &gt; 5 <span style="color: #8D38C9; font-weight: bold;">Then</span> EstWeekEnd = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
Elle retourne <strong>Vrai</strong> si la date est un samedi ou un dimanche sinon elle renvoie <strong>Faux</strong> par défaut.</p>
<p><strong>Principe</strong><br />
On impose à &lsquo;Weekday()&rsquo; que le 1er jour de semaine est le lundi (constante &lsquo;vbMonday&rsquo;) et non le dimanche par défaut. Ainsi, le 6ème et le 7ème jour sont le samedi et le dimanche.</p>
<p><strong>Exemples</strong><br />
Dans la fenêtre Exécution du VBE.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?EstWeekEnd(#2013/8/16#) <span style="color: #008000;">'Vendredi 16 août 2013 : Faux<br />
</span>?EstWeekEnd(#2013/8/17#) <span style="color: #008000;">'Samedi 17 août 2013 : Vrai<br />
</span>?EstWeekEnd(#2013/8/18#) <span style="color: #008000;">'Dimanche 18 août 2013 : Vrai<br />
</span>?EstWeekEnd(#2013/8/19#) 'Lundi 19 août 2013 : Faux</div></div>
<p>&nbsp;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Récapitulatif des fonctions &#8216;jour de semaine&#8217;</title>
		<link>https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine</link>
		<comments>https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine#comments</comments>
		<pubDate>Thu, 15 Aug 2013 11:15:36 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=623</guid>
		<description><![CDATA[Dans ces exemples, on recherche la date d&#8217;un mercredi. Le mercredi avec une croix rouge indique le mercredi retourné selon la fonction utilisée et le jour de la date de référence. DateJourSemaineEnCours() renvoie toujours la date du mercredi de la &#8230; <a href="https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img src="http://philben.developpez.com/Weekday.png" alt="Recapitulatif weekday" /><br />
<span id="more-623"></span><br />
Dans ces exemples, on recherche la date d&rsquo;un mercredi. Le mercredi avec une croix rouge indique le mercredi retourné selon la fonction utilisée et le jour de la date de référence.</p>
<ul>
<li><a href="http://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante" title="Date d’un jour de la semaine courante" target="_blank">DateJourSemaineEnCours()</a> renvoie toujours la date du mercredi de la semaine quelque soit le jour de la date de référence</li>
<li><a href="http://blog.developpez.com/philben/p11470/vba-access/date-du-jour-meme-ou-precedent" title="Date du jour-même ou précédent" target="_blank">DateJourMemeOuPrecedent()</a> renvoie la date du mercredi qui précède la date de référence ou la date de référence elle-même s&rsquo;il s&rsquo;agit d&rsquo;un mercredi</li>
<li><a href="http://blog.developpez.com/philben/p11454/vba-access/date-du-jour-de-semaine-precedent" title="Date du jour de semaine précédent" target="_blank">DateJourPrecedent()</a> renvoie la date du mercredi qui précède la date de référence</li>
<li><a href="http://blog.developpez.com/philben/p11438/vba-access/date-du-jour-meme-ou-suivant" title="Date du jour-même ou suivant" target="_blank">DateJourMemeOuSuivant()</a> renvoie la date du mercredi qui suit la date de référence ou la date de référence elle-même s&rsquo;il s&rsquo;agit d&rsquo;un mercredi</li>
<li><a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">DateJourSuivant()</a> renvoie la date du mercredi qui suit la date de référence</li>
</ul>
<p><strong>Remarque</strong><br />
Les fonctions décrites peuvent provoquer une erreur (dépassement de capacité &#8211; Erreur n°6) :</p>
<ul>
<li>si on passe une date proche du 1er janvier de l&rsquo;an 100 aux fonctions ayant un balayage arrière</li>
<li>si on passe une date proche du 31 décembre 9999 aux fonctions ayant un balayage avant</li>
</ul>
<p>En effet, on peut dépasser dans ces cas, la plage des dates autorisées par Access. Pour ne pas lever cette erreur, vous pouvez introduire un gestionnaire d&rsquo;erreur dans les fonctions.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date d&#8217;un jour de la semaine courante</title>
		<link>https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante</link>
		<comments>https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante#comments</comments>
		<pubDate>Thu, 08 Nov 2012 18:17:01 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=590</guid>
		<description><![CDATA[Episode V de la saga &#8216;Weekday&#8217;. Cette fois-ci, on introduit la notion de semaine puisque l&#8217;on souhaite obtenir la date d&#8217;un jour quelconque de la semaine de la date de référence. Quelle est la date du dimanche de cette semaine &#8230; <a href="https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>V</strong> de la saga &lsquo;Weekday&rsquo;. Cette fois-ci, on introduit la notion de <strong>semaine</strong> puisque l&rsquo;on souhaite obtenir la date d&rsquo;un jour quelconque de la semaine de la date de référence. Quelle est la date du dimanche de cette semaine ? La date du mardi ?<br />
<span id="more-590"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>Les matrices</strong><br />
On souhaite donc passer de la matrice &lsquo;Weekday&rsquo; à la matrice &lsquo;Jour de la semaine courante&rsquo;. Si le premier jour de semaine est un lundi (qui peut être le dimanche comme aux U.S.A.), la matrice finale est :</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Weekday(Date,VbDayOfWeek) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Jour de la semaine (1er jour : lundi)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp;<br />
Jour Date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D &nbsp; &nbsp; &nbsp;Jour date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D <br />
Lundi &nbsp; &nbsp; &nbsp;1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; &nbsp; &nbsp;Lundi &nbsp; &nbsp; &nbsp;0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 &nbsp; 5 &nbsp; 6 <br />
Mardi &nbsp; &nbsp; &nbsp;2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; &nbsp; &nbsp;Mardi &nbsp; &nbsp; -1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 &nbsp; 5 <br />
Mercredi &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 vers Mercredi &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 <br />
Jeudi &nbsp; &nbsp; &nbsp;4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; &nbsp; &nbsp;Jeudi &nbsp; &nbsp; -3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 <br />
Vendredi &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; &nbsp; &nbsp;Vendredi &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 <br />
Samedi &nbsp; &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; &nbsp; &nbsp;Samedi &nbsp; &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 <br />
Dimanche &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; &nbsp; &nbsp;Dimanche &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0</div></div>
<p>&nbsp;<br />
On remarque que les valeurs sont symétriquement opposées par rapport à la diagonale. Pour pouvoir gérer tous les cas quelque soit le premier jour de semaine, le plus simple est de se servir de ce premier jour de semaine comme pivot.</p>
<p><strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourSemaineEnCours(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> PremierJourDeSemaine <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek = vbMonday) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourSemaineEnCours = DateRef + (Jour - CInt(Weekday(DateRef, PremierJourDeSemaine)) - PremierJourDeSemaine + 1)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> Jour &lt; PremierJourDeSemaine <span style="color: #8D38C9; font-weight: bold;">Then</span> DateJourSemaineEnCours = DateJourSemaineEnCours + 7<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
La fonction admet trois paramètres : La date de référence et le jour de semaine recherché. Le troisième paramètre est optionnel (PremierJourDeSemaine) et contient sous forme de constante le nom du 1er jour de semaine. La valeur par défaut de ce paramètre est <strong>lundi</strong>.</p>
<p><strong>Tester la fonction</strong><br />
La fonction suivante teste les 49 x 7 possibilités des matrices et affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourSemaineEnCours()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dates(1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, SumErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourSemaineEnCours()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> l = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; d = Int(Now())<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; l: d = d + 1: Wend<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> k = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> 6: dates(Weekday(d + k)) = d + k: <span style="color: #8D38C9; font-weight: bold;">Next</span> k<br />
<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Semaine du &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; au &quot;</span> &amp; Format(d + 6, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NbErr = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = vbTab &amp; <span style="color: #800000;">&quot;-&gt; Jour recherché : &quot;</span> &amp; Format(d + i - 1, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; : &quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> j = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> 6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> DateJourSemaineEnCours(d + j, i, l) &lt;&gt; dates(i) <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SumErr = SumErr + NbErr<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> l<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(SumErr &gt; 0, SumErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Exemples</strong><br />
A coller dans la fenêtre &lsquo;Exécution&rsquo; du VBE.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">'Date du dimanche pour la date donnée et pour une semaine commençant le lundi<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbSunday) <span style="color: #008000;">'11/11/2012<br />
</span><span style="color: #008000;">'Date du lundi pour la date donnée et pour une semaine commençant le lundi<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbMonday) <span style="color: #008000;">'05/11/2012<br />
</span><span style="color: #008000;">'Date du dimanche pour la date donnée et pour une semaine commençant le dimanche<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbSunday,vbSunday) '04/11/2012</div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
