2011/06/15

access2010 Webデータベース その68 Webマクロで春分の日秋分の日

** Office365beta(プランP1) 環境 **
Webマクロで春分の日/秋分の日を計算してみた。
クライアントマクロやVBAで書くのは良いのだけど、Int/Fixが使えない条件でできるのかどうか確かめた。データマクロでFixを使用して計算したものと比較して結果は一致した。
1949~2150の間のみ。

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
  <UserInterfaceMacro MinimumClientDesignVersion="14.0.0000.0000">
    <Statements>
      <Action Collapsed="true" Name="SetTempVar">
        <Argument Name="Name">tmpArg1</Argument>
        <Argument Name="Expression">[FYear]</Argument>
      </Action>
      <StatementGroup Description="春分の日">
        <Statements>
          <ConditionalBlock>
            <If>
              <Condition>[TempVars]![tmpArg1]&lt;=2150 And [TempVars]![tmpArg1]&gt;=1949</Condition>
              <Statements>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">lclYS</Argument>
                  <Argument Name="Expression">[TempVars]![tmpArg1]-1980</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">StrDiv4</Argument>
                  <Argument Name="Expression">FormatNumber([LocalVars]![lclYS]/4-IIf([LocalVars]![lclYS]&lt;0,0.75,0),2,-1,0,0)</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">IntDiv4</Argument>
                  <Argument Name="Expression">CDbl(Left([LocalVars]![StrDiv4],InStr(1,[LocalVars]![StrDiv4],".")-1))</Argument>
                </Action>
                <ConditionalBlock>
                  <If>
                    <Condition>[TempVars]![tmpArg1]&lt;=1979</Condition>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">20.8357+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </If>
                  <ElseIf>
                    <Condition>[TempVars]![tmpArg1]&lt;=2099</Condition>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">20.8431+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </ElseIf>
                  <Else>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">21.851+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </Else>
                </ConditionalBlock>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">StrVar1</Argument>
                  <Argument Name="Expression">FormatNumber([LocalVars]![Var1],8,-1,0,0)</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">lclDay</Argument>
                  <Argument Name="Expression">CDbl(Left([LocalVars]![StrVar1],InStr(1,[LocalVars]![StrVar1],".")))</Argument>
                </Action>
                <Action Name="MessageBox">
                  <Argument Name="Message">=DateSerial([TempVars]![tmpArg1],3,[LocalVars]![lclDay])</Argument>
                </Action>
              </Statements>
            </If>
          </ConditionalBlock>
        </Statements>
      </StatementGroup>
      <StatementGroup Description="秋分の日">
        <Statements>
          <ConditionalBlock>
            <If>
              <Condition>[TempVars]![tmpArg1]&lt;=2150 And [TempVars]![tmpArg1]&gt;=1949</Condition>
              <Statements>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">lclYS</Argument>
                  <Argument Name="Expression">[TempVars]![tmpArg1]-1980</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">StrDiv4</Argument>
                  <Argument Name="Expression">FormatNumber([LocalVars]![lclYS]/4-IIf([LocalVars]![lclYS]&lt;0,0.75,0),2,-1,0,0)</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">IntDiv4</Argument>
                  <Argument Name="Expression">CDbl(Left([LocalVars]![StrDiv4],InStr(1,[LocalVars]![StrDiv4],".")-1))</Argument>
                </Action>
                <ConditionalBlock>
                  <If>
                    <Condition>[TempVars]![tmpArg1]&lt;=1979</Condition>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">23.2588+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </If>
                  <ElseIf>
                    <Condition>[TempVars]![tmpArg1]&lt;=2099</Condition>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">23.2488+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </ElseIf>
                  <Else>
                    <Statements>
                      <Action Collapsed="true" Name="SetLocalVar">
                        <Argument Name="Name">Var1</Argument>
                        <Argument Name="Expression">24.2488+(0.242194*[LocalVars]![lclYS])-[LocalVars]![IntDiv4]</Argument>
                      </Action>
                    </Statements>
                  </Else>
                </ConditionalBlock>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">StrVar1</Argument>
                  <Argument Name="Expression">FormatNumber([LocalVars]![Var1],8,-1,0,0)</Argument>
                </Action>
                <Action Collapsed="true" Name="SetLocalVar">
                  <Argument Name="Name">lclDay</Argument>
                  <Argument Name="Expression">CDbl(Left([LocalVars]![StrVar1],InStr(1,[LocalVars]![StrVar1],".")))</Argument>
                </Action>
              </Statements>
            </If>
          </ConditionalBlock>
          <Action Name="MessageBox">
            <Argument Name="Message">=DateSerial([TempVars]![tmpArg1],9,[LocalVars]![lclDay])</Argument>
          </Action>
        </Statements>
      </StatementGroup>
    </Statements>
  </UserInterfaceMacro>
</UserInterfaceMacros>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
  <DataMacro Event="BeforeChange">
    <Statements>
      <ConditionalBlock>
        <If>
          <Condition>[FYear]&lt;=1979</Condition>
          <Statements>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro1</Argument>
              <Argument Name="Value">DateSerial([FYear],3,Fix(20.8357+0.242194*([FYear]-1980)-Fix(([FYear]-1983)/4)))</Argument>
            </Action>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro2</Argument>
              <Argument Name="Value">DateSerial([FYear],9,Fix(23.2588+0.242194*([FYear]-1980)-Fix(([FYear]-1983)/4)))</Argument>
            </Action>
          </Statements>
        </If>
        <ElseIf>
          <Condition>[FYear]&lt;=2099</Condition>
          <Statements>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro1</Argument>
              <Argument Name="Value">DateSerial([FYear],3,Fix(20.8431+0.242194*([FYear]-1980)-Fix(([FYear]-1980)/4)))</Argument>
            </Action>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro2</Argument>
              <Argument Name="Value">DateSerial([FYear],9,Fix(23.2488+0.242194*([FYear]-1980)-Fix(([FYear]-1980)/4)))</Argument>
            </Action>
          </Statements>
        </ElseIf>
        <ElseIf>
          <Condition>[FYear]&lt;=2150</Condition>
          <Statements>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro1</Argument>
              <Argument Name="Value">DateSerial([FYear],3,Fix(21.851+0.242194*([FYear]-1980)-Fix(([FYear]-1980)/4)))</Argument>
            </Action>
            <Action Collapsed="true" Name="SetField">
              <Argument Name="Field">DataMacro2</Argument>
              <Argument Name="Value">DateSerial([FYear],9,Fix(24.2488+0.242194*([FYear]-1980)-Fix(([FYear]-1980)/4)))</Argument>
            </Action>
          </Statements>
        </ElseIf>
      </ConditionalBlock>
    </Statements>
  </DataMacro>
</DataMacros>

0 件のコメント: