LabWindows/CVI Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
40tude_

Add PrintfTextBox function to the Text Boxes class

Status: New

This would allow user to have :

 

PrintfTextBox(ghPanel, PANEL_TEXTBOX, "%s %d", "Hello CVI ", 2018); 

  

In terms of implementation it could look like  :

 

#define DEFAULT_LEN 1024 // Quick'n dirty fix
// ---------------------------------------------------------------------------- void PrintfTextBox(int panel, int CtrlId, const char *format, ...){ char StrTmp[DEFAULT_LEN]; va_list args; int NumLines; va_start (args, format); // could be nice also to have _vscprintf function call in CVI vsnprintf (StrTmp, DEFAULT_LEN, format, args); va_end (args); InsertTextBoxLine (panel, CtrlId, -1, StrTmp); GetNumTextBoxLines (panel, CtrlId, &NumLines); SetCtrlAttribute (panel, CtrlId, ATTR_FIRST_VISIBLE_LINE, NumLines); ProcessDrawEvents(); }

 Regards, Philippe

 

Using CVI since 1.2
1 Comment
40tude2
Member

Here is a newer version of the function

 

// ----------------------------------------------------------------------------
static void InsertTextBoxPrintfLine (const int panel, const int control, const char * const FormatString, ...){
  
  va_list   args;
  va_start (args, FormatString);
  
  int NbChar = vsnprintf (NULL, 0, FormatString, args);
  char *buffer = (char*)malloc((NbChar+1)*sizeof(char));
  vsnprintf (buffer, NbChar+1, FormatString, args);    
  InsertTextBoxLine(panel, control , -1, buffer); 
  free(buffer);
  va_end(args);
}

 

Here is a way to use it

 

InsertTextBoxPrintfLine(panel, control, "Comment from %s", MyName);
InsertTextBoxPrintfLine(panel, control, "%d-%d-%d", 1, 2, Bob);