diff --git a/instat/sdgCalculationsSummmary.vb b/instat/sdgCalculationsSummmary.vb index 499067c9172..5e0aea31c49 100644 --- a/instat/sdgCalculationsSummmary.vb +++ b/instat/sdgCalculationsSummmary.vb @@ -61,8 +61,6 @@ Public Class sdgCalculationsSummmary ucrManipulations.lstAvailableData.View = View.List - ucrCalcSummary.ucrReceiverForCalculation.bAttachedToPrimaryDataFrame = False - 'temp until working ucrCalcSummary.ucrSaveResultInto.Visible = False 'ucrCalcSummary.ucrTryModelling.Visible = False @@ -345,16 +343,18 @@ Public Class sdgCalculationsSummmary Private Sub ucrCalcSummary_SelectionChanged() Handles ucrCalcSummary.SelectionChanged If {"Calculation", "Summary"}.Contains(ucrInputType.GetText()) Then + Dim strExpression As String = ucrCalcSummary.ucrReceiverForCalculation.GetText() If Not ucrCalcSummary.ucrReceiverForCalculation.IsEmpty Then - clsCalculationFunction.AddParameter("function_exp", Chr(34) & ucrCalcSummary.ucrReceiverForCalculation.GetText() & Chr(34)) + clsCalculationFunction.AddParameter("function_exp", Chr(34) & strExpression & Chr(34)) Else clsCalculationFunction.RemoveParameterByName("function_exp") End If - If Not ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.IsEmpty Then - clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList( - ucrCalcSummary.ucrSelectorForCalculations.CurrentReceiver.GetVariableNamesList(bWithQuotes:=False), - ucrCalcSummary.ucrSelectorForCalculations)) + If ucrCalcSummary.ucrSelectorForCalculations.lstAvailableVariable.Items.Count > 0 AndAlso + Not ucrCalcSummary.ucrReceiverForCalculation.IsEmpty Then + Dim lstItems As String() = ucrCalcSummary.ucrSelectorForCalculations.lstAvailableVariable.Items.Cast(Of ListViewItem)().Select(Function(item) item.Text).ToArray() + Dim strSelectedVariables As String() = lstItems.Where(Function(variable) strExpression.Contains(variable)).ToArray() + clsCalculationFunction.AddParameter("calculated_from", CreateCalcFromList(strSelectedVariables, ucrCalcSummary.ucrSelectorForCalculations)) Else clsCalculationFunction.RemoveParameterByName("calculated_from") End If @@ -374,14 +374,23 @@ Public Class sdgCalculationsSummmary 'Need to do this instead of with RFunctions because the calculated_from list can have multiple items with the same label Private Function CreateCalcFromList(lstVariables As String(), ucrCurrentSelector As ucrSelectorByDataFrame) As String + + If lstVariables Is Nothing Then + Return "" + End If + Dim strCalcFromList As String strCalcFromList = "list(" For i = 0 To lstVariables.Count - 1 - If i > 0 Then - strCalcFromList = strCalcFromList & "," + Dim strDataName As String = lstVariables(i) + If Not String.IsNullOrEmpty(strDataName) Then + If i > 0 Then + strCalcFromList = strCalcFromList & "," + End If + + strCalcFromList = strCalcFromList & ucrCurrentSelector.strCurrentDataFrame & " = " & Chr(34) & strDataName & Chr(34) End If - strCalcFromList = strCalcFromList & ucrCurrentSelector.strCurrentDataFrame & " = " & Chr(34) & lstVariables(i) & Chr(34) Next strCalcFromList = strCalcFromList & ")" Return strCalcFromList