LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

(HOW TO) text line counter

How can i make a line counter like the cvi has in the source editor..?

Thanks in advance..
0 Kudos
Message 1 of 6
(3,310 Views)
Where is your text located? If you are using a textbox you can use SetCtrlAttribute with ATTR_TOTAL_LINES to get the number of lines written in the control. If your text is on a file you could open it and read it line by line counting the lines read...


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,304 Views)
right now i have a textbox that im writing the text. right next to it i have another text box that i'm "indicating" the line number.. so every time i press "enter" i add one line (with the line number) to the "indicator".. but what if i delete a line..? if i understand you say after an event (probably keypress or val_changed) to get total lines count and adjust the "indicator" textbox.. this is pretty much what i'm doing.. but when i have a text with 20000 lines it take some time to update the indicator though.. (think a situation that you remove the line 10000) probably my routine is bad written.. i wondering if there was a control or something that could do this automatically or some other way..

Message Edited by karpa on 07-02-2008 10:31 AM
0 Kudos
Message 3 of 6
(3,290 Views)
Well, to have only a line counter you need a numeric indicator (better than a textbox) and in keypress event use GetCtrlVal (panelHandle, PANEL_TEXTBOX, ATTR_TOTAL_LINES, &lines); + SetCtrlVal (panelHandle, PANEL_NUMERIC, lines);  It should not cause too much overhead to the system...


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,285 Views)
On the other end, if you want to mimic the line numbers column in the editor: this is significantly different and may impact heavily on the system since it must be updated. But the behaviour of the column of numbers is different: even if you delete line 10000 over 20000, line numbers are rearranged so that now they show from 1 to 19999. This means that whichever is the line deleted you will only need to delete the last line in the number columns. And in case a new line is created inside the textbox, you will need to add a number at the end of number column.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 6
(3,283 Views)
problem solved.. 🙂
here is the code..
(just put two TEXTBOX's side by side.. one for your text and the other for line counter..)

int CVICALLBACK AddLine (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
int textLines,numLines,linesdiff,i;
char TextLineBuf[200];


switch (event)
{
case EVENT_KEYPRESS:
switch (eventData1)
{
case 1280: // < ENTER >
GetCtrlAttribute (panel_handle, SERIAL_TBOX_SEND, ATTR_TOTAL_LINES, &textLines);
GetCtrlAttribute (panel_handle, SERIAL_TBOX_NLINE, ATTR_TOTAL_LINES, &numLines);
numLines=(numLines==0 ? numLines+1 : numLines) ;
linesdiff= numLines -(textLines+1);
if (linesdiff<=0)
{ if (numLines==1)
InsertTextBoxLine (panel, SERIAL_TBOX_NLINE, 0, "N0001");

for (i=(numLines==1 ? 2 : numLines);i<=(textLines+1);i++)
{
sprintf(TextLineBuf, "N%0.4d ", i==1 ? i+1 : i);
InsertTextBoxLine (panel, SERIAL_TBOX_NLINE, i, TextLineBuf);
}


}
else
{
for (i=numLines-1;i>textLines;i--)
{
DeleteTextBoxLine (panel, SERIAL_TBOX_NLINE, i);
}

}
break;

case 512: case 256: // < DELETE >, < BACKSPACE >
GetCtrlAttribute (panel_handle, SERIAL_TBOX_SEND, ATTR_TOTAL_LINES, &textLines);
GetCtrlAttribute (panel_handle, SERIAL_TBOX_NLINE, ATTR_TOTAL_LINES, &numLines);
linesdiff= numLines+2-(textLines+1);
if (linesdiff>0)
{
for (i=numLines-1;i>textLines-1;i--)
{

DeleteTextBoxLine (panel, SERIAL_TBOX_NLINE, i);
}

}
break;
}
break;

}
return 0;
}
0 Kudos
Message 6 of 6
(3,219 Views)