LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Textbox spacing

I am trying to align text vertically and found a problem.  I am currently displaying a measurement and would like the PASS/FAIL text to line up vertically.  Since tabs do not work in CVI I determined that I would like to display the PASSED message 40 characters into the line.  I am reading the string length of the textbox line after the measurement is displayed and determining how many spaces I needed to add to the line so the PASSED would be displayed 40 characters into the line.  To my surprise the width of a character in a textbox are uneven.  A capital V takes up more space than a lower case letter or a space " ".  If I count characters from the left of the textbox to the first PASSED message and repeat the same measurement on the second message I count 40 characters but the text does not line up.  This only occurs in the textbox, not in the sample shown below.  How can I align text using a texbox?     
 
 
Test 1          power up current
 
    300.3mA                      PASSED
 
Test 2          5V Output
 
    5.01Vdc                           PASSED
0 Kudos
Message 1 of 16
(5,269 Views)

You cannot obtain exact alignment with in a textbox if you use a proportional font, since character lenght is not a fixed value but depends on the character being displayed.

If you want to continue using a textbox you must use a fixed font like for example NIEditor. One alternative can be to switch to a listbox and use escape codes ( \033pxxxc ) to align your texts; with a listbox you can additionally modify foreground and background colors so to add some relevance to pass and fail evidences. Another alternative could be to use a table instead of a listbox, with additional possiblities like using different fonts from cell to cell or bold characters and so on.



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?
Message 2 of 16
(5,267 Views)

The easiest way is just to use a fixed width font, such as Courier. If you have enough time, you might consider using a ListBox control instead, which allows you to embed formatting characters for pixel alignment, colour settings, column separators etc.

JR

EDIT: Must type quicker.. Must type quicker.. Must type quicker... Smiley Very Happy



Message Edited by jr_2005 on 05-20-2008 04:20 PM
Message 3 of 16
(5,266 Views)

Thanks for the quick response.  The font changed fixed the problem even though it is a kind of an ugly font.  I will also try the listbox option.

 

 

0 Kudos
Message 4 of 16
(5,260 Views)

I am new in CVI. I have a simpl question around textbox.

 

- any time i need to find out what is the last char in the TEXTBOX.  I know the technick copy from

textbox to the string.  But can any getctrlval gives the pointer to the text in the textbox ? any other

simpl  trick to get last char in the textbox ?

 

 

                                    regards smile
 

0 Kudos
Message 5 of 16
(4,997 Views)

I'm not aware of a way to directly getting the last character in a textbox.

 

If you want to reduce the amount of text read from the control, you can use GetNumTextBoxLines to get the number of lines in the textbox and GetTextBoxLine to retrieve the last one.

 

If you only want to append text to the control, please note that you can use SetCtrlVal to obtain it, while ResetTextBox replaces all the contents of the control with the text passed to the function.



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 6 of 16
(4,996 Views)

Hello ) new problem ,

 

nt CVICALLBACK Key (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{

    int numBytes;   
    int numLines=0;
   
    char a[1024];
    char msg[1024];
    char sg2[1024];
   
    switch (event)
        {
        case EVENT_VAL_CHANGED :
       
        GetCtrlAttribute (panel1, PANEL1_TEXTBOX, ATTR_STRING_TEXT_LENGTH, &numBytes);

        GetCtrlVal(panel1, PANEL1_TEXTBOX, &a[0]);
       
        GetNumTextBoxLines (panel1, PANEL1_TEXTBOX, &numLines);
       
        Fmt (msg, "bytes = %d, Lines = %d", numBytes, numLines);
       
        GetTextBoxLine (panel1, PANEL1_TEXTBOX, numLines, sg2);            // line 494
       
        MessagePopup ("The key entered", a);
        MessagePopup ("Bytes in the text: ", msg);
        MessagePopup ("Last line content: ", sg2);


            break;
        }
    return 0;
}

 

 

 NON-FATAL RUN-TIME ERROR:   "test.c", line 494, col 9, thread id 0x000003BC:   Library function error (return value == -55 [0xffffffc9]). The index passed is out of range.

 

Why this error ? Please tell me ...

 

 

                                                                                                  regards Smile_

0 Kudos
Message 7 of 16
(4,961 Views)

If there are 10 lines in a text box and you want the last one, you need to ask for line number 9. (The indexing is 0-based.) So just change your code to ask for numLines - 1.

 

JR

0 Kudos
Message 8 of 16
(4,957 Views)

hi, me again ).

 

tnx jr_

 

new trouble:

 

CODE: 

 

     InstallComCallback (comport_R, LWRS_RXCHAR, 0, EventChar_Right[0], Event_Char_Right_Fun, NULL);                      // line 230

 

 

 

void CVICALLBACK Event_Char_Right_Fun (int portNo,int eventMask,void *callbackData)
{
    char outMessage[256];
    char    readBuf[20] = {0};
    int     strLen;
       
    return;
}

 

 

& Errors:

   230, 81   Undeclared identifier 'Event_Char_Right_Fun'.
   230, 101   Type error in argument 5 to `InstallComCallback'; found 'int' expected 'ComCallbackPtr'.

 

QUESTION:

Why it found int, I copied from example, what is wrong ??

 

 

                                                                                                        regards Smile_
 

 

0 Kudos
Message 9 of 16
(4,934 Views)

Probably because, at the time the compiler found the first reference to Event_Char_Right_Fun it hadn't yet seen your definition of it. Simply provide the compiler with a function prototype first. Like this:

 

                 // This next line pre-warns the compiler about Event_Char_Right_Fun before you have fully defined it

void CVICALLBACK Event_Char_Right_Fun (int portNo,int eventMask,void *callbackData) ;

     InstallComCallback (comport_R, LWRS_RXCHAR, 0, EventChar_Right[0], Event_Char_Right_Fun, NULL);

 

void CVICALLBACK Event_Char_Right_Fun (int portNo,int eventMask,void *callbackData)
{
    char outMessage[256];
    char    readBuf[20] = {0};
    int     strLen;
       
    return;
}

  

JR

0 Kudos
Message 10 of 16
(4,929 Views)