title: need help calling a variable outside of event handler parenthesis
body: <p>i have this code</p>
  
  <pre><code>Private Sub moAccounts_PositionUpdate(ByVal poPositions As A4.API.AccountList.PositionUpdateList) Handles moAccounts.PositionUpdate
  
      ' Display the position details.
      For Each oUpdate As AccountList.PositionUpdateList.PositionUpdate In poPositions
  
         'code here
  
      Next
  
      End sub
  </code></pre>
  
  <p>What I want to do is call the sub above from within another sub.  The problem is the variable poPositions appears nowhere else in the code. I think it is an array of data fed by the API. I need to find out how to get the data from the server API in the event handler parenthesis so I can then call the sub above and update the data</p>
  
  <p>i have tried this:</p>
  
  <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      udate()
  
  End Sub
  
  Private Sub udate()
  
      Dim poPositions As A4.API.AccountList.PositionUpdateList
  
      For Each oUpdate As AccountList.PositionUpdateList.PositionUpdate In poPositions
  
         'code here
      Next
  
  End Sub
  </code></pre>
  
  <p>the code compiles, but when i run the code the code stops executing and shows an error underlining poPositions</p>
  
  <pre><code>    For Each oUpdate As AccountList.PositionUpdateList.PositionUpdate In **poPositions**
  
  *Object reference not set to an instance of an object.*
  </code></pre>
  
  <p>if ByVal poPositions As A4.API.AccountList.PositionUpdateList works inside the event handler parenthesis, it has to work outside. the issue is (i guess) in the syntax</p>
  
  <p>this obviously doesnt work</p>
  
  <pre><code>Dim poPositions As A4.API.AccountList.PositionUpdateList
  </code></pre>
  
  <p>i tried this <em>outside</em> the parenthesis:</p>
  
  <pre><code>ByVal poPositions As A4.API.AccountList.PositionUpdateList
  </code></pre>
  
  <p>but that generates an error at ByVal</p>
  
  <p>so i am stuck as to how to ... define (?) ... poPositions. what is the term to put in front of poPositons to get it to grab the data when the statement is placed <strong>outside</strong> the event handler parenthesis?</p>