Now I would like to incorporate Solver into a macro ... I think I have nearly succeeded but my code fails at the "solve.Objective = oCell.CellAddress" line with the error message:
Here is my code so far:BASIC runtime error.
An exception occurred
Type: com.sun.star.uno.RuntimeException
Message: [jni_uno bridge error] UNO calling Java method Objective: [map_to_uno():com.sun.star.table.CellAddress] null-ref given!
java stack trace:
.
Code: Select all
Sub StartMeasure
Dim v1 as Single
Dim v2 as Single
Dim oDocument As Object
Dim oSheet As Object
Dim oCell As Object
Dim oCellRange As Object
Dim Variables(4) As New com.sun.star.table.CellAddress
oDocument=ThisComponent
oSheet=oDocument.Sheets.getByName("Model_2")
svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
oCellRange = oSheet.getCellRangeByPosition( 2, 12, 2, 15 ) 'C13:C16
arg = array( oCellRange )
v1 = svc.callFunction( "AVERAGE", arg )
oCellRange = oSheet.getCellRangeByPosition( 2, 39, 2, 42 ) 'C40:C43
arg = array( oCellRange )
v2 = svc.callFunction( "AVERAGE", arg )
oCell=oSheet.getCellByPosition(3,3) ' D4
oCell.setValue(v1)
oCell=oSheet.getCellByPosition(3,4) ' D5
oCell.setValue(v2)
smgr = GetProcessServiceManager()
solv = smgr.createInstance("com.sun.star.sheet.Solver")
solv.Document = oDocument
Variables(0) = oSheet.getCellByPosition(3, 3).CellAddress 'D4
Variables(1) = oSheet.getCellByPosition(3, 4).CellAddress 'D5
Variables(2) = oSheet.getCellByPosition(3, 5).CellAddress 'D6
Variables(3) = oSheet.getCellByPosition(3, 6).CellAddress 'D7
solv.Variables = Variables()
oCell = oSheet.getCellByPosition(5,44) 'F45
solv.Objective = oCell.CellAddress
solv.Maximize = False
solv.Solve()
' Print solv.ResultValue
End SubBTW surely there must be more settings for Solver than are listed here: http://www.openoffice.org/api/docs/comm ... olver.html
Should I be looking somewhere else?