Spread Windows Forms 12.0 Product Documentation
Adding Formulas to Calculate Balances
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Getting Started > Tutorial: Creating a Checkbook Register > Adding Formulas to Calculate Balances

Your checkbook register is now set up to look like a checkbook register; however, it does not balance the currency figures you enter in the register. This step sets up the formula for balancing the figures.

  1. Provide the following code in the Form Load event after the code you have already added:

    Example

    C#
    Copy Code
    // Set formula for calculating balance.
    fpSpread1.Sheets[0].ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
    int i;
    for (i = 0; i <= fpSpread1.ActiveSheet.RowCount - 1; i++)
    {
    if (i == 0)
    fpSpread1.Sheets[0].Cells[i, 7].Formula = "RC[-1] - RC[-2]" ;
    else
    fpSpread1.Sheets[0].Cells[i, 7].Formula = "RC[-1] - RC[-2] + R[-1]C";
    }
    
    VB
    Copy Code
    ' Set formula for calculating balance.
    fpSpread1.Sheets(0).ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
    Dim i As Integer
    For i = 0 To fpSpread1.ActiveSheet.RowCount - 1
    If i = 0 Then
    fpSpread1.Sheets(0).Cells(i, 7).Formula = "RC[-1] - RC[-2]"
    Else
    fpSpread1.Sheets(0).Cells(i, 7).Formula = "RC[-1]-RC[-2]+R[-1]C"
    End If
    Next
    

  2. Save your project, then click the Start button in the toolbar to run your project.
  3. Your form should look similar to the following picture. Type data into your checkbook register to test it and see how it operates.

    Completed register with data

  4. You have created a checkbook register using Spread. You have completed this tutorial.

Review the list of steps for Tutorial: Creating a Checkbook Register.