SSRS Preview and Print Layout render differently (calculated field)

I have a calculated field in a footer of the outermost group, that doesn’t render correctly in print layout (see picts below). I’m trying to sequentially number the group footer

The expression of a field above (before and outside) the outermost group is: =code.initLineNum()

the expression of the “Line” field (which is in the outermost groups footer) is =code.myLineNum()

the code for those functions is:

Public dim lineNum  as integer

Public Function initLineNum()
  lineNum = 0
End Function

Public Function myLineNum() as integer
  lineNum = lineNum + 1
  Return lineNum
End Function

Below is what I get from SSRS and from E10

Here’s what it looks like when previewing in SSRS Report Builder. This is what I expect.
image

Here’s what Print Layout looks like in SSRS Report Builder:
image

And here’s what it looks like when run from E10:
image