I looked at your example, thanks.
The problem is not in GetNumTextBoxLines(), the problem is in InsertTextBoxLine(). A textbox accepts any text and isn't really organized into lines. All of the ???TextBoxLine functions try to interpret the text as divided into lines based on NewLines ('\n'). InsertTextBoxLine() automatically adds a NewLine character at the end of the string you're adding. You can verify this by doing an InsertTextBoxLine, then do a GetCtrlVal and look at the string. You'll see that it ends in a NewLine 0xa.
If you're inserting a line into the middle of the multi-line string in the textbox, InsertTextBoxLine is still handy. Using it in the middle of the string is not where you see the problem (because you need a NewLine there). Appending a line to the end of the string is where you get the extra blank line.
Here are a couple of suggestions for avoiding the blank line at the end of the textbox.
1. If you're just appending lines, don't use InsertTextBoxLine. Use SetCtrlVal and prefix the string with a NewLine (\n). (SetCtrlVal to a textbox appends to the existing contents).
e.g.
char myNewLine[256];
int myAge=99;
//...
sprintf(myNewLine, "\nMy age is %d", myAge);
SetCtrlVal(panel, PANEL_ACTIONBOX, myNewLine);
2. If you want to use InsertTextBoxLine, check to see if you're adding a line at the end of the textbox. If you are, trim the NewLine character.
e.g.
char textboxString[2000];
InsertTextBoxLine (panel, PANEL_ACTIONBOX, -1, str);
GetCtrlVal (panel, PANEL_ACTIONBOX, textboxString);
// strip off NewLine
if (textboxString[strlen(textboxString)-1] == '\n')
textboxString[strlen(textboxString)-1]='\0';
// rewrite the modified string without the ending newline
ResetTextBox (panel, PANEL_ACTIONBOX, textboxString);