Professional Documents
Culture Documents
Step 2: Type the below function in the code window under Main Sub and End Sub. Supporting window is below.
Ex 1. Division of two numbers.
Function DivTwo()
Dim b as integer, c as integer
b=10
c=2
DivTwo=b/c
End function.
Step 5 : You can see the answer as 2. Because the values of b and c are 10 and 2.
Ex 2. Multiplication of 3 numbers
Function Multi123()
a=10
b=10
c=10
Multi123=a*b*c
End Function
Children follow the above steps to execute the Multi123() function also.
Function Subtra123()
l= 100
m=50
Subtra123=l-m
End Function
Children follow the above steps and execute the Subtra123() function also.
Children in the above 3 example function the values are directly assigned to the variables like l=100, m=50, a=10,b=10 etc..
But from the below examples we are going to take the values from cells in OpenOffice.org( OOo Calc)
Dim oSheet
Dim oCell1
Dim oCell2
oSheet = ThisComponent.CurrentController.ActiveSheet
TheSum=oCell1.getValue() + oCell2.getValue()
Sum123=TheSum
End Function
1) oSheet, oCell1, oCell2 are just variables. Just like we have taken a,b,c,l,m in the above examples.
2) (0,0),(0,1) etc.. are given in the table above. (0,0) means A1 in SpreadSheet. (1,1) means B1 in
SpreadSheet. Learn all
3) Whatever the sheet (Sheet1, Sheet2 etc..) we select children, that sheet will become the active
Sheet for that we have the code as “ ThisComponent.CurrentController.ActiveSheet”
4) getCellByPosition() function is used to goto that particular cell. Children remember the first letter
of the first word is small and first letter of the remaining words will be capital. That is rule. You must
write the function getCellByPosition() as it is.
5) getValue() function is used to take the value from that particular cell after going to the cell.
Ex.5
Function Division123()
Dim oSheet
Dim oCell1
Dim b
oSheet = ThisComponent.CurrentController.ActiveSheet
oCell1 = oSheet.getCellByPosition(0,3)
b=2
Division123=oCell1.getValue()/b
End Function