Algorithm for finding end of a list (SAP GUI)
<p>I'm writing a script that adds elements to a list in a SAP GUI screen.  Now, it seems that when using SAP GUI, nothing "exists" unless it is actually on screen, so the first step involves finding the end of the list.</p>

<p>I accomplished this by scrolling though each element, and checking if it was blank.  </p>

<pre><code>Do While Not blank
If session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" Then blank = True
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = i
i = i + 1
Loop
</code></pre>

<p>However, for very large existing lists, this takes a long time.  I'm trying to figure out a way to find the end more quickly. Some truths/limitations I know:</p>

<ol>
<li>I'm assuming I have no knowledge of the list length. </li>
<li>I cannot command the <code>verticalScrollbar.position</code> too far beyond the end of<br>
the list. For ex. if the list contains 62 elements, <code>.verticalScrollbar.Position = 100</code> will not work.</li>
<li>In the case of  the above example, SAP does NOT throw an error. Nothing happens at  all, and then next line of code executes.</li>
<li>All references to elements are with respect to their position on the screen. Ex, if I scroll down 5 positions, the 6th element of the overall list would actually indexed as 1.</li>
<li>On the other hand, <code>verticalScrollbar.Position</code> is absolute</li>
</ol>

<p>I'm thinking of doing the following (in very psuedocode):</p>

<pre><code>i = 0
do while scrolled = true
    scrolled = false
    a = GUIlist[0]
    verticalScrollbar.Position = i + 1000
    b = GUIlist[0]
    'check to see the first element shown has changed
    if a &lt;&gt; b then 
        scrolled = true
        i = i + 1000
    end if
loop

do while scrolled = true
    scrolled = false
    a = GUIlist[0]
    verticalScrollbar.Position = i + 500
    b = GUIlist[0]
    if a &lt;&gt; b then 
        scrolled = true
        i = i + 500
    end if
loop
</code></pre>

<p>...and so on until I'm iterating <code>i</code> by one.</p>

<p>Is there a generally accepted better way of doing this kind of 'search'?
Any input is appreciated.
Thanks</p>