<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Iterate over query results</Title>
      <Author>Microsoft Corporation</Author>
      <Description>Creates a query and demonstrates consumption of that query in a subsequent For Each statement.</Description>
      <Shortcut>qIterate</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>queryResult</ID>
          <Type>item</Type>
          <ToolTip>Replace with the identifier for the query.</ToolTip>
          <Default>query</Default>
        </Literal>
        <Literal>
          <ID>item</ID>
          <Type>item</Type>
          <ToolTip>Replace with the the identifier for the range variable that represents an item from your data source.</ToolTip>
          <Default>fruit</Default>
        </Literal>
        <Literal>
          <ID>dataSource</ID>
          <Type>String</Type>
          <ToolTip>Replace with the identifier for your data source.</ToolTip>
          <Default>New String() {"apple", "orange", "pear", "banana"}</Default>
        </Literal>
        <Literal>
          <ID>field1</ID>
          <Type>String</Type>
          <ToolTip>Replace with the identifier for the first field you want to retrieve from your data source.</ToolTip>
          <Default>ToUpper()</Default>
        </Literal>
        <Literal>
          <ID>field2</ID>
          <Type>String</Type>
          <ToolTip>Replace with the identifier for the second field you want to retrieve from your data source.</ToolTip>
          <Default>Length</Default>
        </Literal>
        <Literal>
          <ID>iterationVar</ID>
          <Type>String</Type>
          <ToolTip>Replace with the identifier for the iteration variable used to iterate over the query.</ToolTip>
          <Default>item</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="method body"><![CDATA[Dim $queryResult$ = From $item$ In $dataSource$ _
                    Select $item$.$field1$, $item$.$field2$

                     For Each $iterationVar$ In $queryResult$
                         ' sum = sum + $item$.$field2$                   
                     Next]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>