Bogemic Software        Bogemic Software RSS  Subscribe: RSS       Products  |  Purchase  |  Support  |  Contact      
Products
  Bogemic Apps
  Bogemic Docs
  Bogemic Studio
  Bogemic Grid
  Services
Order Now
Ordering Process
Documentation
Press Releases
Reseller
Feedback Form
Technical Support
Contact

Formulas and calculations

« Back Forward »

Methods: AvgRange, SumRange, MaxRange, MinRange, CountRange
Properties: Property(Prop_Formula),Property(Prop_Format),Range

Specifying a formula

Each formula should begin with the "=" sign. After the "=" sign should go the valid VBScript statement. For example:

' Specify the FormatPercent VBScript function in a formula
grid.Cell(0,0).Property(Prop_Formula) = "=FormatPercent(3/22)"

Using built-in aggregate functions

The Bogemic Grid control provides the following aggregate functions to work with ranges: AvgRange, SumRange, MaxRange, MinRange, CountRange.

' calculate the sum of values in the first column
Set range = grid.Range("A1:A10")
sumRange = grid.SumRange(range)

' to do the same as one function call, use the SUM function
sumRange = SUM("A1:A10")

Ranges, formulas, formatting: putting it all together

Now create a document that will do some real-world calculations, for example the order with a total sum calculation.

' the first column will contain the product names
' and the second column will contain prices
grid.Cell("A",0) = "Title"

' set format and data type for the entire column "B"
grid.Column("B").Property(Prop_Format) = "$%.ff"
grid.Column("B").Property(Prop_DataType) = DataType_R4

' .. except the first cell
grid.Cell("B",0).Property(Prop_DataType) = DataType_BStr
grid.Cell("B",0).Property(Prop_Format) = ""
grid.Cell("B",0) = "Price"

' fill the order with data
grid.Cell("A",1).Value = "Britney Spears Audio CD"
grid.Cell("B",1).Value = 12.99
grid.Cell("A",2).Value = "Celine Dion Blu-ray"
grid.Cell("B",2).Value = 15.95
grid.Cell("A",3).Value = "Alicia Keys Album"
grid.Cell("B",3).Value = 7.99

' set text align
grid.Property(Prop_VAlign) = VAlign_Center
grid.Column("A").Property(Prop_HAlign)=HAlign_Left
grid.Column("B").Property(Prop_HAlign)=HAlign_Right
grid.Row(0).Property(Prop_HAlign)=HAlign_Center

' add total sum
grid.Row(4).Property(Prop_BorderTop)=1
grid.Cell("A",4).Property(Prop_HAlign)=HAlign_Right
grid.Cell("A",4).Value = "Total:"

' and finally, insert a formula to calculate the total sum
grid.Cell("B",4).Property(Prop_Formula) = "=SUM(""B2:B4"")"

« Back Up Forward »