From 43a173387ed793aef7c84593cffae482b2028107 Mon Sep 17 00:00:00 2001 From: Fidel365 <107605960+Fidel365@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:58:39 +0300 Subject: [PATCH 1/2] rename with improvements --- instat/dlgName.vb | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 8d049242001..6a37f79f964 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -145,7 +145,7 @@ Public Class dlgName ucrPnlOptions.AddToLinkedControls({ucrPnlCase, ucrPnlSelectData}, {rdoRenameWith}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputCase, {rdoMakeCleanNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Snake") ucrPnlCase.AddToLinkedControls(ucrNudAbbreviate, {rdoAbbreviate}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="8") - ucrPnlCase.AddToLinkedControls(ucrInputReplace, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlCase.AddToLinkedControls(ucrInputReplace, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputBy, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="") ucrPnlCase.AddToLinkedControls(ucrInputEdit, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Starts With") ucrPnlSelectData.AddToLinkedControls(ucrReceiverColumns, {rdoSelectedColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) @@ -660,20 +660,26 @@ Public Class dlgName Private Sub RemovePattern() If rdoWholeDataFrame.Checked Then - If rdoReplace.Checked Then - clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - clsDefaultRFunction.RemoveParameterByName("label") - clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) - If ucrInputEdit.GetText = "Starts With" Then - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Ends With" Then - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Matches" Then - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Contains" Then - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + If rdoRenameWith.Checked Then + If rdoReplace.Checked Then + clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) + clsDefaultRFunction.RemoveParameterByName("label") + clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) + If ucrInputEdit.GetText = "Starts With" Then + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) + ElseIf ucrInputEdit.GetText = "Ends With" Then + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) + ElseIf ucrInputEdit.GetText = "Matches" Then + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + ElseIf ucrInputEdit.GetText = "Contains" Then + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + End If + Else + clsDefaultRFunction.RemoveParameterByName("pattern") + clsDefaultRFunction.RemoveParameterByName("replacement") + clsDefaultRFunction.RemoveParameterByName(".cols") End If Else clsDefaultRFunction.RemoveParameterByName("pattern") From 26eb99a376111e5c6a3f21327cbfd0fce446e26b Mon Sep 17 00:00:00 2001 From: Fidel365 <107605960+Fidel365@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:04:38 +0300 Subject: [PATCH 2/2] code improvements --- instat/dlgName.vb | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 6a37f79f964..b108de0f7ea 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -660,27 +660,23 @@ Public Class dlgName Private Sub RemovePattern() If rdoWholeDataFrame.Checked Then - If rdoRenameWith.Checked Then - If rdoReplace.Checked Then - clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - clsDefaultRFunction.RemoveParameterByName("label") - clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) - If ucrInputEdit.GetText = "Starts With" Then + If rdoRenameWith.Checked AndAlso rdoReplace.Checked Then + clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) + clsDefaultRFunction.RemoveParameterByName("label") + clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) + + Select Case ucrInputEdit.GetText + Case "Starts With" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Ends With" Then + Case "Ends With" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Matches" Then + Case "Matches" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) - ElseIf ucrInputEdit.GetText = "Contains" Then + Case "Contains" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) - End If - Else - clsDefaultRFunction.RemoveParameterByName("pattern") - clsDefaultRFunction.RemoveParameterByName("replacement") - clsDefaultRFunction.RemoveParameterByName(".cols") - End If + End Select Else clsDefaultRFunction.RemoveParameterByName("pattern") clsDefaultRFunction.RemoveParameterByName("replacement")