<?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>detourist &#187; end-use</title>
	<atom:link href="http://detourist.net/category/end-use/feed" rel="self" type="application/rss+xml" />
	<link>http://detourist.net</link>
	<description>あちこち調整中。不具合はご容赦下さい。</description>
	<lastBuildDate>Tue, 04 May 2010 18:14:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>VBA: 円状にランダムに点を打つマクロ</title>
		<link>http://detourist.net/post/random-points</link>
		<comments>http://detourist.net/post/random-points#comments</comments>
		<pubDate>Wed, 14 Jan 2009 05:56:29 +0000</pubDate>
		<dc:creator>detourist</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Visio]]></category>

		<guid isPermaLink="false">http://detourist.net/end-use/visio/vba-%e5%86%86%e4%b8%8a%e3%81%ab%e3%83%a9%e3%83%b3%e3%83%80%e3%83%a0%e3%81%ab%e7%82%b9%e3%82%92%e6%89%93%e3%81%a4%e3%83%9e%e3%82%af%e3%83%ad</guid>
		<description><![CDATA[Visio 上で，指定した座標を中心にランダムに点を打つマクロ．ここでは，使用イメージのように点の密度が中央に偏るようにしている．

なお，Excel 関数の標準正規分布関数 NormSInv を使用するため，VBA か [...]]]></description>
			<content:encoded><![CDATA[<p>Visio 上で，指定した座標を中心にランダムに点を打つマクロ．ここでは，使用イメージのように点の密度が中央に偏るようにしている．</p>
<p><a href="http://detourist.net/uploads/2009/01/randompoints.png" title="randompoints.png"><img src="http://detourist.net/uploads/2009/01/randompoints.thumbnail.png" width="300" height="279" alt="randompoints.png" class="imageframe imgalignleft" /></a></p>
<p>なお，Excel 関数の標準正規分布関数 NormSInv を使用するため，VBA から Excel オブジェクトライブラリを参照するために，あらかじめ以下の操作が必要．<br />
(1) Visio にて，[ツール] → [マクロ] → 「Visial Basic Editor」を開く．<br />
(2) Visual Basic Editor にて，[ツール] → [参照設定] → 「Microsoft Excel 9.0 Object Library」を選択 → [OK]<br />
(*) その後，コードを編集し，保存．</p>
<p>使い方は，「実行するマクロ」内の値を適当に修正し，[ツール] → [マクロ] から「実行するマクロ」を実行．<br />
※なぜ「drawPoints」を別のプロージャ（「実行するマクロ」）から呼び出しているかというと，引数を変えた複数の drawPoints を同時に実行できるようにするため．</p>
<div style="position:relative;top:18px;margin-top:-18px;"><small><strong>VB</strong></small>
</div>
<pre name="code" class="vb" style="margin:18px 0;">
Sub 実行するマクロ()
    drawPoints 100, 100, 1000, 50
End Sub

Sub drawPoints(x, y, n, r)
    &#039;x = 中心のX座標
    &#039;y = 中心のY座標
    &#039;n = 描画する点の個数
    &#039;r = 点の散らばる範囲を調整する値

    &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;
    &#039;Microsoft Excel 9.0 Object Library を参照
    Dim objExcel As Excel.Application
    Set objExcel = CreateObject(&quot;Excel.Application&quot;)

    &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;
    Dim myCircle() As Visio.Shape
    &#039;配列生成時に変数(ここでの n )を利用できないため ReDim を使用
    ReDim myCircle(n)

    i = 0
    Do While i &lt; n
        drawX = x + objExcel.Application.NormSInv(Rnd) * r
        drawY = y + objExcel.Application.NormSInv(Rnd) * r

        &#039;※描画する点の大きさは 2 に固定．手抜き．．．
        drawX1 = drawX - 1
        drawX2 = drawX + 1
        drawY1 = drawY + 1
        drawY2 = drawY - 1

        &#039;点を描画
        Set myCircle(i) = ThisDocument.Application.ActiveWindow.Page.DrawOval(drawX1, drawY1, drawX2, drawY2)
        &#039;塗りつぶし色を変更
        myCircle(i).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = &quot;THEMEGUARD(RGB(0,32,96))&quot;
        &#039;透過度を変更
        &#039;myCircle(i).CellsSRC(visSectionObject, visRowFill, visFillForegndTrans).FormulaU = &quot;50%&quot;
        &#039;線をなしにする
        myCircle(i).CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = &quot;0&quot;
        &#039;レイヤを変更する
        &#039;myCircle(i).CellsSRC(visSectionObject, visRowLayerMem, visLayerMember).FormulaForceU = &quot;&quot;&quot;5&quot;&quot;&quot;

        &#039;カウンタを進める
        i = i + 1
    Loop

    &#039;ReDim したオブジェクトは Erase するお約束(？)
    Erase myCircle()
    &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;
End Sub
</pre>
]]></content:encoded>
			<wfw:commentRss>http://detourist.net/post/random-points/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

