Simple If - Then - Else Programming

Discussion created by carautm on Feb 16, 2014
Latest reply on Feb 16, 2014 by NeoGeo
Could someone please advise me how do use a simple "if - then - else" construct to take two columns of population data on different dates and compute a new column of the percentage change?  I also need to account for potential divide-by-zero errors.  I have tried writing straightforward
if field1 > 0 then
    (field2 - field1)/field1
end if (done both with and without the end if)
but of course this fails.  I tried using the example code from one of the knowledgebase articles:
Static lastValue as variant
Dim Output As Double

If IsEmpty(lastValue) Then
Output = 0
Output = (([Increment] - lastValue) / lastValue) * 100
End If
lastValue = [Increment]
but this, too fails.  I had even created a field containing the "increment" (but named differently), but with no success.  And of course the compiler gives absolutely no idea of what might be wrong.

This should NOT be that hard.  What am I doing wrong?