Skip to content

Commit

Permalink
Merge pull request #163 from N-thony/br_two_var_anas
Browse files Browse the repository at this point in the history
getting changes
  • Loading branch information
anastasia-mbithe authored Aug 10, 2023
2 parents 6bf04c5 + ccfe12c commit 6192ee4
Show file tree
Hide file tree
Showing 32 changed files with 2,263 additions and 1,046 deletions.
6 changes: 4 additions & 2 deletions instat/Interface/IDataViewGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ Public Interface IDataViewGrid

Sub AddRowData(dataFrame As clsDataFrame)

Sub SearchInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bCellOrRow As Boolean = False)
Sub SearchRowInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bApplyToRows As Boolean = False)

Sub SelectColumnInGrid(strColumn As String)

Sub AdjustColumnWidthAfterWrapping(strColumn As String, Optional bApplyWrap As Boolean = False)

Expand Down
2 changes: 1 addition & 1 deletion instat/Model/Output/clsOutputElement.vb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Public Class clsOutputElement
Get
Dim _lstRScriptElements As New List(Of clsRScriptElement)
Try
Dim rScript As New clsRScript(_strScript)
Dim rScript As New clsRScript("")
Dim lstTokens As List(Of clsRToken) = rScript.GetLstTokens(rScript.GetLstLexemes(_strScript)) 'rScript.lstTokens
If lstTokens IsNot Nothing Then
For Each rToken In lstTokens
Expand Down
8 changes: 6 additions & 2 deletions instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ Public Class ucrDataViewLinuxGrid
dataGrid.Rows(iRow).Cells(iColumn).Value = GetCurrentDataFrameFocus.DisplayedData(iRow, iColumn)
End Sub

Public Sub SearchInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bCellOrRow As Boolean = False) Implements IDataViewGrid.SearchInGrid
Public Sub SearchRowInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bApplyToRows As Boolean = False) Implements IDataViewGrid.SearchRowInGrid
End Sub

Public Sub SelectColumnInGrid(strColumn As String) Implements IDataViewGrid.SelectColumnInGrid

End Sub
End Class
88 changes: 68 additions & 20 deletions instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ Public Class ucrDataViewReoGrid
For i = 0 To grdData.CurrentWorksheet.Rows - 1
For j = 0 To grdData.CurrentWorksheet.Columns - 1
Dim strData As String = dataFrame.DisplayedData(i, j)
If grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(LT)") Then
If grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(LT)") AndAlso
strData IsNot Nothing Then
strData = GetInnerBracketedString(strData)
strData = If(strData.Contains(":"), strData.Replace(":", ", "), strData)
End If
grdData.CurrentWorksheet(row:=i, col:=j) = strData
Next
Expand All @@ -103,7 +105,7 @@ Public Class ucrDataViewReoGrid
End Sub

Public Sub AdjustColumnWidthAfterWrapping(strColumn As String, Optional bApplyWrap As Boolean = False) Implements IDataViewGrid.AdjustColumnWidthAfterWrapping
Dim iColumnIndex As Integer = GetColumnIndex(grdData.CurrentWorksheet, strColumn)
Dim iColumnIndex As Integer = GetColumnIndex(strColName:=strColumn)
If iColumnIndex < 0 OrElse grdData.CurrentWorksheet.ColumnHeaders(iColumnIndex).Text.Contains("(G)") Then
MsgBox("Cannot wrap or unwrap this type of variable.")
Exit Sub
Expand All @@ -129,6 +131,8 @@ Public Class ucrDataViewReoGrid
Dim intLastLeftBracket As Integer = InStrRev(strData, "(")
If intFirstRightBracket = 0 Or intLastLeftBracket = 0 Then
Return strData
ElseIf strData = "numeric(0)" Then
Return String.Empty
Else
Dim strOutput As String = Mid(strData, intLastLeftBracket + 1, intFirstRightBracket - intLastLeftBracket - 1)
Return strOutput
Expand Down Expand Up @@ -243,10 +247,11 @@ Public Class ucrDataViewReoGrid
End If
End Sub

Private Function GetColumnIndex(currWorkSheet As Worksheet, strColName As String) As Integer
If currWorkSheet IsNot Nothing Then
For i As Integer = 0 To currWorkSheet.Columns - 1
Dim strCol As String = currWorkSheet.ColumnHeaders(i).Text
Private Function GetColumnIndex(strColName As String) As Integer
Dim currWorksheet = grdData.CurrentWorksheet
If currWorksheet IsNot Nothing Then
For i As Integer = 0 To currWorksheet.Columns - 1
Dim strCol As String = currWorksheet.ColumnHeaders(i).Text
If Trim(strCol.Split("(")(0)) = strColName.Replace("""", "") Then
Return i
End If
Expand Down Expand Up @@ -282,12 +287,17 @@ Public Class ucrDataViewReoGrid
Return lstRowsIndexes
End Function

Private Sub ScrollToCellPos(currWorkSheet As Worksheet, iRow As Integer, iCol As Integer)
currWorkSheet.FocusPos = currWorkSheet.Cells(row:=iRow, col:=iCol).Position
Private Sub ScrollToCellPos(currWorkSheet As Worksheet, iRow As Integer, iCol As Integer, bApplyToRows As Boolean)

If bApplyToRows Then
currWorkSheet.SelectRows(iRow, 1)
Else
currWorkSheet.FocusPos = currWorkSheet.Cells(row:=iRow, col:=iCol).Position
End If
currWorkSheet.ScrollToCell(currWorkSheet.Cells(row:=iRow, col:=iCol).Address)
End Sub

Private Sub SetRowOrCellBackgroundColor(currWorkSheet As Worksheet, rowNumbers As List(Of Integer), colIndex As Integer, bApplyToRow As Boolean, color As Color)
Private Sub SetRowOrCellBackgroundColor(currWorkSheet As Worksheet, rowNumbers As List(Of Integer), colIndex As Integer, bApplyToRows As Boolean, color As Color)
' Create a new style object for the row background color
Dim rowStyle As WorksheetRangeStyle = New WorksheetRangeStyle With {
.Flag = PlainStyleFlag.BackColor,
Expand All @@ -298,7 +308,7 @@ Public Class ucrDataViewReoGrid
For Each rowNumber As Integer In rowNumbers
' Check if the row index is within the valid range
If rowNumber >= 0 AndAlso rowNumber < currWorkSheet.RowCount Then
If bApplyToRow Then
If bApplyToRows Then
' Apply the row style to the entire row
currWorkSheet.Cells(rowNumber, colIndex).Style.BackColor = color
Else
Expand All @@ -308,27 +318,65 @@ Public Class ucrDataViewReoGrid
Next
End Sub

Public Sub SearchInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bApplyToRow As Boolean = False) Implements IDataViewGrid.SearchInGrid
Public Sub SearchRowInGrid(rowNumbers As List(Of Integer), strColumn As String, Optional iRow As Integer = 0,
Optional bApplyToRows As Boolean = False) Implements IDataViewGrid.SearchRowInGrid
Dim currSheet = grdData.CurrentWorksheet

If currSheet.RowHeaders.Any(Function(x) x.Text = iRow) Then
Dim iRowIndex As Integer = GetRowIndex(currSheet, iRow)
Dim iColIndex As Integer = 0
If strColumn <> "filter" Then
iColIndex = GetColumnIndex(currSheet, strColumn)
End If
Dim iColIndex As Integer = If(strColumn = Chr(34) & "filter" & Chr(34), 0, GetColumnIndex(strColName:=strColumn))

If iRowIndex > -1 AndAlso iColIndex > -1 Then
ScrollToCellPos(currWorkSheet:=currSheet, iRow:=iRowIndex, iCol:=iColIndex)
If bApplyToRow Then
ScrollToCellPos(currWorkSheet:=currSheet, iRow:=iRowIndex, iCol:=iColIndex, bApplyToRows:=bApplyToRows)
If bApplyToRows Then
SetRowOrCellBackgroundColor(currWorkSheet:=currSheet, rowNumbers:=GetRowsIndexes(currSheet, rowNumbers),
colIndex:=iColIndex, bApplyToRow:=bApplyToRow, color:=Color.LightGreen)
colIndex:=currSheet.ColumnCount, bApplyToRows:=bApplyToRows, color:=Color.LightGreen)
Else
SetRowOrCellBackgroundColor(currWorkSheet:=currSheet, rowNumbers:=GetRowsIndexes(currSheet, rowNumbers),
colIndex:=currSheet.ColumnCount, bApplyToRow:=bApplyToRow, color:=Color.LightGreen)
colIndex:=iColIndex, bApplyToRows:=bApplyToRows, color:=Color.LightGreen)
End If
End If
End If
End Sub

''' <summary>
''' This function takes an integer columnNumber as input and returns a string representing the corresponding Reogrid-style column letter.
''' For example, 1 will be converted to "A", 26 to "Z", 27 to "AA", 28 to "AB", and so on.
''' </summary>
''' <param name="columnNumber"></param>
''' <returns></returns>
Private Function ColumnNumberToAlpha(columnNumber As Integer) As String
Dim dividend As Integer = columnNumber
Dim columnName As String = String.Empty
Dim modulo As Integer

While dividend > 0
modulo = (dividend - 1) Mod 26
columnName = Convert.ToChar(65 + modulo) & columnName
dividend = CInt((dividend - modulo) / 26)
End While

Return columnName
End Function

Public Sub SelectColumnInGrid(strColumn As String) Implements IDataViewGrid.SelectColumnInGrid

If String.IsNullOrEmpty(strColumn) Then
Exit Sub
End If

Dim currSheet = grdData.CurrentWorksheet
Dim iColumn As Integer = grdData.CurrentWorksheet.ColumnHeaders.
Where(Function(col) col.Text.Split("(")(0).Trim = strColumn).
FirstOrDefault().Index ' Get the correspond index of a column from a column name.

Dim strOriginalColumnName As String = ColumnNumberToAlpha(iColumn + 1) & "1"
currSheet.ScrollToCell(strOriginalColumnName)
currSheet.SelectColumns(iColumn, 1)
' Set the background color for the entire column
currSheet.SetRangeStyles(0, iColumn, currSheet.RowCount, 1, New WorksheetRangeStyle With {
.Flag = PlainStyleFlag.BackColor,
.BackColor = Color.LightGreen
})
End Sub
End Class
22 changes: 14 additions & 8 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,9 @@ Public Class RLink
bAsFile = False
Evaluate(strScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
ElseIf iCallType = 1 OrElse iCallType = 4 Then
'todo. this is used by the calculator dialog
'todo. icall types 1 and 4 seem not to be used anywhere? remove this block?
'this is used by the calculator dialog
'else if script output should be stored in a temp variable
' TODO SJL In RInstat, iCallType only seems to be 0, 2 or 3. Are icall types 1 and 4 used?
' TODO SJL In RInstat, iCallType only seems to be -1, 0, 1, 2 or 3. Is icallType 4 used?
bAsFile = False
Dim strTempAssignTo As String = ".temp_val"
'TODO check this is valid syntax in all cases
Expand All @@ -823,6 +822,17 @@ Public Class RLink
If expTemp IsNot Nothing Then
strOutput = String.Join(Environment.NewLine, expTemp.AsCharacter()) & Environment.NewLine
End If
ElseIf iCallType = 5 Then
'else if script comes from script window
Dim bSuccess As Boolean = Evaluate(strScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)

'if not an assignment operation, then capture the output
If Not strScript.Contains("<-") AndAlso bSuccess Then
Dim strScriptAsSingleLine As String = strScript.Replace(vbCrLf, String.Empty)
strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbCr, String.Empty)
strScriptAsSingleLine = strScriptAsSingleLine.Replace(vbLf, String.Empty)
strOutput = GetFileOutput("view_object_data(object = " & strScriptAsSingleLine & " , object_format = 'text' )", bSilent, bSeparateThread, bShowWaitDialogOverride)
End If
Else
'else if script output should not be ignored or not stored as an object or variable

Expand Down Expand Up @@ -949,11 +959,7 @@ Public Class RLink
End If

'else execute command
Dim iCallType As Integer = 5
If strScriptCmd.Contains(strInstatDataObject & "$get_graphs") Then
iCallType = 3
End If
RunScript(strScriptCmd.Trim(vbLf), iCallType:=iCallType, strComment:=strNewComment, bSeparateThread:=False, bSilent:=False)
RunScript(strScriptCmd.Trim(vbLf), iCallType:=5, strComment:=strNewComment, bSeparateThread:=False, bSilent:=False)
strScriptCmd = ""
strNewComment = ""
Next
Expand Down
8 changes: 7 additions & 1 deletion instat/dlgCalculator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ Public Class dlgCalculator
Private Sub SaveResults()
If ucrCalc.ucrSaveResultInto.ucrChkSave.Checked AndAlso ucrCalc.ucrSaveResultInto.IsComplete Then
clsRemoveLabelsFunction.AddParameter("col_names", Chr(34) & ucrCalc.ucrSaveResultInto.GetText() & Chr(34), iPosition:=1)
ucrBase.clsRsyntax.SetAssignTo(ucrCalc.ucrSaveResultInto.GetText(), strTempColumn:=ucrCalc.ucrSaveResultInto.GetText(), strTempDataframe:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.cboAvailableDataFrames.Text, bAssignToIsPrefix:=ucrBase.clsRsyntax.clsBaseCommandString.bAssignToIsPrefix, bAssignToColumnWithoutNames:=ucrBase.clsRsyntax.clsBaseCommandString.bAssignToColumnWithoutNames, bInsertColumnBefore:=ucrBase.clsRsyntax.clsBaseCommandString.bInsertColumnBefore, bRequireCorrectLength:=ucrBase.clsRsyntax.clsBaseCommandString.bRequireCorrectLength)
ucrBase.clsRsyntax.SetAssignTo(ucrCalc.ucrSaveResultInto.GetText(), strTempColumn:=ucrCalc.ucrSaveResultInto.GetText(),
strTempDataframe:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.cboAvailableDataFrames.Text,
bAssignToIsPrefix:=ucrBase.clsRsyntax.clsBaseCommandString.bAssignToIsPrefix,
bAssignToColumnWithoutNames:=ucrBase.clsRsyntax.clsBaseCommandString.bAssignToColumnWithoutNames,
bInsertColumnBefore:=ucrBase.clsRsyntax.clsBaseCommandString.bInsertColumnBefore,
bRequireCorrectLength:=ucrBase.clsRsyntax.clsBaseCommandString.bRequireCorrectLength,
strAdjacentColumn:=ucrCalc.ucrSaveResultInto.AdjacentColumnName)
ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction, 1)
ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = True
ucrBase.clsRsyntax.iCallType = 0
Expand Down
2 changes: 1 addition & 1 deletion instat/dlgCopySheet.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6192ee4

Please sign in to comment.