Shiny Language Reference
Language Reference > User Interface > Memo Boxes
memoboxlinefrompos
int memoboxlinefrompos(int ID, int Pos);
Returns the line number the specified position is currently on
The MEMOBOXLINEFROMPOS statement returns the line number of the character at position Pos. Please read the following description carefully.
When using memoboxes on-screen they appear as multline edit controls. However the text data of a memobox control is actually stored as a single string, not as individual lines of text. This is necessary to allow dynamic formatting of the memobox. The size, shape, text bounding rect, font and other factors all affect the number of lines of text a memobox can display on screen at any one time. Each time Brass draws a memobox control it internally calculates how to chop up the text string into multiple lines so that it best fits the available display space. Because Brass allows non-fixed width fonts for the memobox control, a different number of characters may fit on each line. A row of 10 "W" characters takes up more pixel width than a row of 10 "I" characters. Therefore at any one time the contents of line N may differ from the contents of that same line at a different time, and inserting or removing characters elsewhere in the memobox contents will not necessarily alter the contents of that line.
Parameters
ID
The control ID of the control you wish to retrieve the line to character position for
Pos
The character position (byte) to retrieve the line number for. Remember that the byte position includes single bytes for line feeds (newlines, "\n"). Therefore a caption string of "Line 1\nLine 2" will only display 12 characters on screen, but consists of 13 bytes. Therefore to retrieve the first character of the start of "Line 2" the position parameter should be integer 7 to include the line feed.
Return Value
The line number containing the specified character position
Example Code
// Create the memo box X: 10, Y:10 and sized 150*70
int iMemoBoxID = creatememobox(1, 10, 10, 150, 70);
// Set the memobox text to "Hello World"
setcaption(iMemoBoxID, "Hello World");
// Get the line number for the "e" in "Hello"
int Line = memoboxlinefrompos(iMemoBoxID, 1);