Dear Excel Experts,
I am using Excel (2003) Solver in my application for some minor optimization problem. The application has been used within our business without problems since several years back. The Excel file contains macros that is triggered by changing a certain cell value. The macro SolveTheProblem() that calls solver and an example of values used in the sheet is defined and showed below (I wanted to attach a screen dump showing the complete Excel sheet but don't know how-to).
Now my Windows application (c++ RAD Studio) will open the Excel template and fill some cells with values to be included in the optimization. However, the return from Solver contains an error message: "an unexpected internal error occured, or available memory was exhausted" i.e. no solution.
Now, if I instead copy the cell values into the very same Excel template and run the SAME macro manually it returns a correct solution.
Since the last time I worked with development of this particular application I've had Visual Studio 2010 installed (used VS 2005 before) BUT here I'm talking about RAD Studio and NOT VS at all. But maybe this version will affect the OLE objects used by RAD studio, or?
I'm very lost and totally confused about this, any help appreciated!
BR,
Per
Public Sub SolveTheProblem()
Dim row As Integer, rowTarget As Integer, columnTarget As Integer
Dim cellTarget As String
Dim vars As String, leftSide As String, rightSide As String
Dim targetValue As String
Dim resultInt As Integer
solutionFound = False
targetValue = CStr(Cells(1, 1).Value)
targetValue = Replace(targetValue, ",", ".")
rowTarget = Cells(2, 1).Value
columnTarget = Cells(3, 1).Value
If columnTarget = 2 Then
cellTarget = "$B$" + CStr(rowTarget)
Else
cellTarget = "$C$" + CStr(rowTarget)
End If
vars = "$B$" + CStr(rowTarget) + ","
For row = 1 To 17
If Cells(row, 4).Value > 0 Then
vars = vars + "$B$" + CStr(row) + ","
End If
Next row
vars = Left(vars, Len(vars) - 1)
'SolverReset
Application.Run "Solver.xla!SolverReset"
Application.Run "Solver.xla!SolverOptions", 100, 400, 0.00001, False, False, _
1, 2, 1, 5, False, 0.0001, False
Application.Run "Solver.xla!SolverOk", cellTarget, 3, targetValue, vars
Application.Run "Solver.xla!SolverAdd", "$b$1:$b$16", 3, "0"
Application.Run "Solver.xla!SolverAdd", "$b$22", 1, "0.999"
For row = 1 To 17
If Not row = rowTarget Then
If Cells(row, 4).Value > 0 Then
leftSide = "$C$" + CStr(row)
rightSide = "$D$" + CStr(row)
Application.Run "Solver.xla!SolverAdd", leftSide, 2, rightSide
End If
End If
Next row
resultInt = Application.Run("Solver.xla!SolverSolve", True)
Cells(31, 2) = resultInt
If resultInt < 2 Then
Application.Run "Solver.xla!SolverFinish", 1
Else
Application.Run "Solver.xla!SolverFinish", 2
End If
End Sub
<table width="288" border="0" cellpadding="0" cellspacing="0"><col style="width:54pt" span="4" width="72"> <tbody><tr style="height:14.25pt" height="19"> <td style="height:14.25pt;width:54pt" height="19" width="72" align="right">A
0.05</td> <td style="width:54pt" width="72" align="right">B
0</td> <td style="width:54pt" width="72" align="right">C
0</td> <td style="width:54pt" width="72" align="right">D
0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">12</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">2</td> <td align="right">0.007</td> <td align="right">741.7482</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.005</td> <td align="right">529.8202</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.02001</td> <td align="right">2120.34</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.05</td> <td align="right">5298.202</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.107</td> <td align="right">9095</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.03</td> <td align="right">3178.921</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">1.246636</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">105964</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">85000</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.11201</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">1</td> <td align="right">0</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> </tbody></table>
I am using Excel (2003) Solver in my application for some minor optimization problem. The application has been used within our business without problems since several years back. The Excel file contains macros that is triggered by changing a certain cell value. The macro SolveTheProblem() that calls solver and an example of values used in the sheet is defined and showed below (I wanted to attach a screen dump showing the complete Excel sheet but don't know how-to).
Now my Windows application (c++ RAD Studio) will open the Excel template and fill some cells with values to be included in the optimization. However, the return from Solver contains an error message: "an unexpected internal error occured, or available memory was exhausted" i.e. no solution.
Now, if I instead copy the cell values into the very same Excel template and run the SAME macro manually it returns a correct solution.
Since the last time I worked with development of this particular application I've had Visual Studio 2010 installed (used VS 2005 before) BUT here I'm talking about RAD Studio and NOT VS at all. But maybe this version will affect the OLE objects used by RAD studio, or?
I'm very lost and totally confused about this, any help appreciated!
BR,
Per
Public Sub SolveTheProblem()
Dim row As Integer, rowTarget As Integer, columnTarget As Integer
Dim cellTarget As String
Dim vars As String, leftSide As String, rightSide As String
Dim targetValue As String
Dim resultInt As Integer
solutionFound = False
targetValue = CStr(Cells(1, 1).Value)
targetValue = Replace(targetValue, ",", ".")
rowTarget = Cells(2, 1).Value
columnTarget = Cells(3, 1).Value
If columnTarget = 2 Then
cellTarget = "$B$" + CStr(rowTarget)
Else
cellTarget = "$C$" + CStr(rowTarget)
End If
vars = "$B$" + CStr(rowTarget) + ","
For row = 1 To 17
If Cells(row, 4).Value > 0 Then
vars = vars + "$B$" + CStr(row) + ","
End If
Next row
vars = Left(vars, Len(vars) - 1)
'SolverReset
Application.Run "Solver.xla!SolverReset"
Application.Run "Solver.xla!SolverOptions", 100, 400, 0.00001, False, False, _
1, 2, 1, 5, False, 0.0001, False
Application.Run "Solver.xla!SolverOk", cellTarget, 3, targetValue, vars
Application.Run "Solver.xla!SolverAdd", "$b$1:$b$16", 3, "0"
Application.Run "Solver.xla!SolverAdd", "$b$22", 1, "0.999"
For row = 1 To 17
If Not row = rowTarget Then
If Cells(row, 4).Value > 0 Then
leftSide = "$C$" + CStr(row)
rightSide = "$D$" + CStr(row)
Application.Run "Solver.xla!SolverAdd", leftSide, 2, rightSide
End If
End If
Next row
resultInt = Application.Run("Solver.xla!SolverSolve", True)
Cells(31, 2) = resultInt
If resultInt < 2 Then
Application.Run "Solver.xla!SolverFinish", 1
Else
Application.Run "Solver.xla!SolverFinish", 2
End If
End Sub
<table width="288" border="0" cellpadding="0" cellspacing="0"><col style="width:54pt" span="4" width="72"> <tbody><tr style="height:14.25pt" height="19"> <td style="height:14.25pt;width:54pt" height="19" width="72" align="right">A
0.05</td> <td style="width:54pt" width="72" align="right">B
0</td> <td style="width:54pt" width="72" align="right">C
0</td> <td style="width:54pt" width="72" align="right">D
0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">12</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">2</td> <td align="right">0.007</td> <td align="right">741.7482</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.005</td> <td align="right">529.8202</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.02001</td> <td align="right">2120.34</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.05</td> <td align="right">5298.202</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.107</td> <td align="right">9095</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.03</td> <td align="right">3178.921</td> <td align="right">0</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">1.246636</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">105964</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">85000</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0.11201</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td align="right">0</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19" align="right">1</td> <td align="right">0</td> <td>
</td> <td>
</td> </tr> <tr style="height:14.25pt" height="19"> <td style="height:14.25pt" height="19">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> </tbody></table>
Last edited: