Entry
TSE: Block: Convert: How to convert a line block to a column block?
Oct 28th, 2006 07:35
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 28 October 2020 - 04:13 pm --------------------
TSE: Block: Convert: How to convert a line block to a column block?
===
Pseudo code:
--- cut here: begin --------------------------------------------------
Mark a line block
Get the maximum linelength in that block
Mark a block between first and last row and from minimum to maximum
linelength
--- cut here: end ----------------------------------------------------
===
--- cut here: begin --------------------------------------------------
PROC Main()
INTEGER lineLengthMaxI = 0
INTEGER lineLengthI = 0
INTEGER downB = TRUE
PushPosition()
GotoBlockBegin()
WHILE ( IsCursorInBlock() ) AND ( downB )
lineLengthI = CurrLineLen()
IF ( lineLengthMaxI < lineLengthI )
lineLengthMaxI = lineLengthI
ENDIF
downB = Down()
ENDWHILE
MarkColumn( Query( BlockBegLine ), 0, Query( BlockEndLine ),
lineLengthMaxI )
PopPosition()
END
--- cut here: end ----------------------------------------------------
===
As a function
--- cut here: begin --------------------------------------------------
INTEGER PROC FNBlockGetLineLengthMaxI()
INTEGER lineLengthMaxI = 0
INTEGER lineLengthI = 0
INTEGER downB = TRUE
PushPosition()
GotoBlockBegin()
WHILE ( IsCursorInBlock() ) AND ( downB )
lineLengthI = CurrLineLen()
IF ( lineLengthMaxI < lineLengthI )
lineLengthMaxI = lineLengthI
ENDIF
downB = Down()
ENDWHILE
PopPosition()
RETURN( lineLengthMaxI )
END
INTEGER PROC FNBlockGetLineNumberFirstI()
RETURN( Query( BlockBegLine ) )
END
INTEGER PROC FNBlockGetLineNumberLastI()
RETURN( Query( BlockEndLine ) )
END
INTEGER PROC FNBlockConvertLineToColumnB( INTEGER xMinI )
IF NOT IsBlockMarked()
Warn( "Please mark a block first" )
RETURN( FALSE )
ENDIF
MarkColumn( FNBlockGetLineNumberFirstI(), xMinI,
FNBlockGetLineNumberLastI(), FNBlockGetLineLengthMaxI() )
RETURN( TRUE )
END
PROC Main()
IF NOT FNBlockConvertLineToColumnB( 0 )
Warn( "convert marked line block to column block not successful" )
ENDIF
END
<F12> Main()
--- cut here: end ----------------------------------------------------
===
Note:
If you use this code, it will convert from the current cursor (CurrCol
())
instead from the left most (0).
That can come handy if you want to select a column block from
your current cursor position to the most right.
--- cut here: begin --------------------------------------------------
PROC Main()
IF NOT FNBlockConvertLineToColumnB( CurrCol() )
Warn( "convert marked line block to column block not successful" )
ENDIF
END
--- cut here: end ----------------------------------------------------
===
Tested successfully on
Microsoft Windows XP Professional (service pack 2),
running
TSE 4.x
===
Internet: see also:
---
TSE: Block: Line: Length: Maximum: How to get the maximum line length
in a marked block? [longest]
http://www.faqts.com/knowledge_base/view.phtml/aid/42837/fid/898
---
TSE: Block: Column: Line: How to get first line number in a marked
block?
http://www.faqts.com/knowledge_base/view.phtml/aid/42849/fid/898
---
TSE: Block: Column: Line: How to get last line number in a marked
block?
http://www.faqts.com/knowledge_base/view.phtml/aid/42842/fid/898
----------------------------------------------------------------------