Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example creates cells that perform a currency conversion from Norwegian kroner to U.S. dollars. Clicking a button cell converts the given number of kroner to dollars, based on the conversion rate the user provides, as illustrated in the following figure.

C++

void CmyWnd::MyFunc()
{
    // Set up labels for currency
    m_Spread11.SetColWidth(1,10);
    m_Spread1.SetCol(1);
    m_Spread1.SetRow(1);
    m_Spread1.SetText("US $");
    m_Spread1.SetRow(2);
    m_Spread1.SetText("Norway kroner");
    // Set up currency cells
    // Set up cell for US dollars
    m_Spread1.SetCol(2);
    m_Spread1.SetRow(1);
    m_Spread1.SetCellType(12);
    m_Spread1.SetTypeCurrencyDecimal(".");
    m_Spread1.SetTypeCurrencyDecPlaces(2);
    m_Spread1.SetTypeCurrencyNegStyle(1);
    m_Spread1.SetTypeCurrencyPosStyle(1);
    m_Spread1.SetTypeCurrencySeparator(",");
    m_Spread1.SetTypeCurrencyShowSep(TRUE);
    m_Spread1.SetTypeCurrencyShowSymbol(TRUE);
    m_Spread1.SetTypeCurrencySymbol("$");
    // Set up cell for kroner
    m_Spread1.SetRow(2);
    m_Spread1.SetCellType(12);
    m_Spread1.SetTypeCurrencyDecimal(",");
    m_Spread1.SetTypeCurrencyDecPlaces(2);
    m_Spread1.SetTypeCurrencyNegStyle(3);
    m_Spread1.SetTypeCurrencyPosStyle(3);
    m_Spread1.SetTypeCurrencySeparator(" ");
    m_Spread1.SetTypeCurrencyShowSep(TRUE);
    m_Spread1.SetTypeCurrencyShowSymbol(TRUE);
    m_Spread1.SetTypeCurrencySymbol("kr");
    // Set up cell to accept conversion rate
    m_Spread1.SetCol(1);
    m_Spread1.SetRow(3);
    m_Spread1.SetCellType(13);
    // Set up label for conversion rate cell
    m_Spread1.SetColWidth(2,15);
    m_Spread1.SetCol(2);
    m_Spread1.SetCellType(5);
    m_Spread1.SetText("kroner = $1 US");
    // Set up cell to perform conversion
    m_Spread1.SetCol(3);
    m_Spread1.SetRow(1);
    m_Spread1.SetCellType(7);
    m_Spread1.SetTypeButtonText("Convert");
}

void CTestprojDlg::OnButtonClickedFpspread1(long Col, long Row, short ButtonDown)
{
    double kroner, conversion;

    m_Spread1.GetFloat(2, 2, &kroner);
    m_Spread1.GetFloat(1, 3, &conversion);
    if ((Col == 3) && (Row == 1) && (conversion != 0))
        m_Spread1.SetFloat(2, 1, (kroner/conversion));
}

Visual Basic

Private Sub Form_Load()
    ' Set up labels for currency
    fpSpread1.ColWidth(1) = 10
    fpSpread1.Col = 1
    fpSpread1.Row = 1
    fpSpread1.Text = "US $"
    fpSpread1.Row = 2
    fpSpread1.Text = "Norway kroner"

    ' Set up currency cells
    ' Set up cell for US dollars
    fpSpread1.Col = 2
    fpSpread1.Row = 1
    fpSpread1.CellType = CellTypeCurrency
    fpSpread1.TypeCurrencyDecimal = "."
    fpSpread1.TypeCurrencyDecPlaces = 2
    fpSpread1.TypeCurrencyNegStyle = TypeCurrencyNegStyle1
    fpSpread1.TypeCurrencyPosStyle = TypeCurrencyPosStyle1
    fpSpread1.TypeCurrencySeparator = ","
    fpSpread1.TypeCurrencyShowSep = True
    fpSpread1.TypeCurrencyShowSymbol = True
    fpSpread1.TypeCurrencySymbol = "$"

    ' Set up cell for kroner
    fpSpread1.Col = 2
    fpSpread1.Row = 2
    fpSpread1.CellType = CellTypeCurrency
    fpSpread1.TypeCurrencyDecimal = ","
    fpSpread1.TypeCurrencyDecPlaces = 2
    fpSpread1.TypeCurrencyNegStyle = TypeCurrencyNegStyle13
    fpSpread1.TypeCurrencyPosStyle = TypeCurrencyPosStyle3
    fpSpread1.TypeCurrencySeparator = " "
    fpSpread1.TypeCurrencyShowSep = True
    fpSpread1.TypeCurrencyShowSymbol = True
    fpSpread1.TypeCurrencySymbol = "kr"

    ' Set up cell to accept conversion rate
    fpSpread1.Col = 1
    fpSpread1.Row = 3
    fpSpread1.CellType = CellTypeNumber
    ' Set up label for conversion rate cell
    fpSpread1.ColWidth(2) = 15
    fpSpread1.Col = 2
    fpSpread1.Row = 3
    fpSpread1.CellType = CellTypeStaticText
    fpSpread1.Text = "kroner = $1 US"

    ' Set up cell to perform conversion
    fpSpread1.Col = 3
    fpSpread1.Row = 1
    fpSpread1.CellType = CellTypeButton
    fpSpread1.TypeButtonText = "Convert"
End Sub

Private Sub fpSpread1_ButtonClicked(ByVal Col As Long, ByVal Row As Long, ByVal ButtonDown As Integer)
    Dim kroner As Double
    Dim conversion As Double

    fpSpread1.GetFloat 2, 2, kroner
    fpSpread1.GetFloat 1, 3, conversion

    If Col = 3 And Row = 1 And conversion <> 0 Then
        fpSpread1.SetFloat 2, 1, kroner / conversion
    End If
End Sub

Copyright © GrapeCity, inc. All rights reserved.