Skip to content

Commit 66a0c15

Browse files
committed
version update
added error handling for case when objective is defined with more than one cell minor improvements to test modules
1 parent ce83663 commit 66a0c15

33 files changed

+292
-259
lines changed
512 Bytes
Binary file not shown.
512 Bytes
Binary file not shown.

dev/ActiveX_DLL/no_registration/test_Portfolio_of_Securities.bas

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,43 @@ Option Explicit
1717

1818
'This is a non-linear problem - use slvGRG_Nonlinear
1919
Sub Solve_Portfolio_of_Securities()
20-
Dim Problem As Object
20+
Dim oProblem As Object
2121
Dim ws As Worksheet
2222

23-
Set Problem = New_SolvProblem
23+
Set oProblem = New_SolvProblem
2424

2525
Set ws = ThisWorkbook.Worksheets("Portfolio of Securities")
2626

2727
'initialize the problem by passing a reference to the worksheet of interest
28-
Problem.Initialize ws
28+
oProblem.Initialize ws
2929

3030
'define the objective cell to be optimized
31-
Problem.Objective.Define "E18", slvMaximize
31+
oProblem.Objective.Define "E18", slvMaximize
3232

3333
'define and initialize the decision cell(s)
34-
Problem.DecisionVars.Add "E10:E14"
35-
Problem.DecisionVars.Initialize 0.2, 0.2, 0.2, 0.2, 0.2
34+
oProblem.DecisionVars.Add "E10:E14"
35+
oProblem.DecisionVars.Initialize 0.2, 0.2, 0.2, 0.2, 0.2
3636

3737
'add some constraints
38-
Problem.Constraints.AddBounded "E10:E14", 0#, 1#
39-
Problem.Constraints.Add "E16", slvEqual, 1#
40-
Problem.Constraints.Add "G18", slvLessThanEqual, 0.071
38+
oProblem.Constraints.AddBounded "E10:E14", 0#, 1#
39+
oProblem.Constraints.Add "E16", slvEqual, 1#
40+
oProblem.Constraints.Add "G18", slvLessThanEqual, 0.071
4141

4242
'set the solver engine to use
43-
Problem.Solver.Method = slvGRG_Nonlinear
43+
oProblem.Solver.Method = slvGRG_Nonlinear
4444

4545
'set some solver options
46-
Problem.Solver.Options.AssumeNonNeg = True
47-
Problem.Solver.Options.RandomSeed = 7
46+
oProblem.Solver.Options.AssumeNonNeg = True
47+
oProblem.Solver.Options.RandomSeed = 7
4848

49-
Problem.Solver.SaveAllTrialSolutions = True
49+
oProblem.Solver.SaveAllTrialSolutions = True
5050

5151
'solve the optimization problem
52-
Problem.SolveIt
52+
oProblem.SolveIt
5353

5454
'save all trial solutions that passed the constraints to the worksheet
55-
If Problem.Solver.SaveAllTrialSolutions Then
55+
If oProblem.Solver.SaveAllTrialSolutions Then
5656
ws.Range("o2:az10000").ClearContents
57-
Problem.SaveSolutionsToRange ws.Range("o2"), keepOnlyValid:=True
57+
oProblem.SaveSolutionsToRange ws.Range("o2"), keepOnlyValid:=True
5858
End If
5959
End Sub

dist/SolverWrapperDLLSetup.exe

369 Bytes
Binary file not shown.
779 Bytes
Binary file not shown.

src/twinBASIC/source/ClassFactory.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Attribute VB_Description = "This class is used for object instantiation when ref
33
'%ModuleDescription "This class is used for object instantiation when referencing SolverWrapper externally from another VBA project"
44
'@folder("SolverWrapper.Source")
55
' ==========================================================================
6-
' SolverWrapper v0.7
6+
' SolverWrapper v0.8
77
'
88
' A wrapper for automating MS Excel's Solver Add-in
99
'

src/twinBASIC/source/SolvConstraints.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to set/manage Solver constraints."
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.7
15+
' SolverWrapper v0.8
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'
@@ -279,7 +279,7 @@ Private Sub ProcessConstraintParams(ByRef cellRef As Variant, ByVal relation As
279279

280280
Set ws = oSolverSheet
281281

282-
'check that Relation is in valid range
282+
'check that relation is in valid range
283283
If relation < SlvRelation.[_First] Or relation > SlvRelation.[_Last] Then
284284
Err.Raise vbObjectError + 4001, , "Please specify a valid Relation between 1 and 6."
285285
End If

src/twinBASIC/source/SolvDLL.cls

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Attribute VB_Description = "This private class is used to communicate directly w
1111
'%ModuleDescription "This private class is used to communicate directly with DLL and is not exposed to User."
1212
'@folder("SolverWrapper.Source")
1313
' ==========================================================================
14-
' SolverWrapper v0.7
14+
' SolverWrapper v0.8
1515
'
1616
' A wrapper for automating MS Excel's Solver Add-in
1717
'
@@ -65,11 +65,9 @@ Public stopRestorePrevious As Boolean
6565
Public enableInternalEvents As Boolean
6666
Public enableUserDefinedCallback As Boolean
6767

68-
'internal event that triggers chained public event in SolvProblem
68+
'internal events that triggers chained public event in SolvProblem
6969
Public Event ShowTrialInternal(ByVal reason As Long, ByVal trialNum As Long, cancel As Boolean)
70-
'internal event that triggers chained public event in SolvProblem
7170
Public Event BeforeSolveInternal(cancel As Boolean)
72-
'internal event that triggers chained public event in SolvProblem
7371
Public Event AfterSolveInternal(ByVal returnMsgCode As Long, ByVal trialNum As Long)
7472
'internal event that triggers chained public callback function in SolvProblem
7573
Public Event ShowTrialCallbackInternal(ByVal reason As Long, ByVal trialNum As Long, cancel As Boolean)

src/twinBASIC/source/SolvDecisionVars.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to define the Decision variable, i.e. the ce
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.7
15+
' SolverWrapper v0.8
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'

src/twinBASIC/source/SolvObjective.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to define the Solver Objective function."
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.7
15+
' SolverWrapper v0.8
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'
@@ -67,6 +67,10 @@ Attribute Define.VB_UserMemId = 0
6767
Else
6868
Err.Raise vbObjectError + 4001, , "Please specify a valid cell reference"
6969
End If
70+
71+
If ws.Range(setCell).Count > 1 Then
72+
Err.Raise vbObjectError + 4001, , "Objective Cell must be a single cell on the active sheet"
73+
End If
7074

7175
If goal < SlvGoalType.[_First] Or goal > SlvGoalType.[_Last] Then
7276
Err.Raise vbObjectError + 4001, , "Please specify an objective Goal value between 1 and 3."

0 commit comments

Comments
 (0)