12-06-2018 01:52 PM
Hi,
Is there a function to space out strings and etc. without impeding on a set character length. i.e. I want to spread out my table columns.
I'm currently using a lot of spaces to format it. The tab escape doesn't seem to have an effect on moving it at all.
Any help will be appreciated.
Solved! Go to Solution.
12-07-2018 07:48 AM
Hi mpwbs,
Have you tried using the Table Control Attributes for the size of your table?
http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/uiref/cvitable_attributes/
If these attributes don't work for you, can you elaborate on what you mean by spreading out your table columns? Do you need the width of your columns to be a set size that is bigger than the set number of characters that can be entered?
12-07-2018 02:46 PM - edited 12-07-2018 02:48 PM
Well, I'm not creating a table. I'm creating one by hardcoding. So, there is a header and then the data follows below.
If the one section has a character of 3 or more then all my alignment is thrown out the window. Wondered if there was a command or something that can set how far I am from the previous character. Like in C++, there is setw(). I wonder if there is something other than "%5d" so it moves it 5 spaces or spots over that would work. But, then I would need to sprintf all my strings and character which can't be done because they are fixed strings/arrays. Attached is the example:
12-10-2018 02:56 AM - edited 12-10-2018 02:58 AM
I know two ways:
01-01-2019 02:25 PM
Just to emphasize what CVI-User says: find a reference on the printf family of functions (fprintf, sprintf etc) and fully understand all the options the standard c library gives you there.
01-02-2019 05:30 PM
@mpwbs wrote:
Well, I'm not creating a table. I'm creating one by hardcoding. So, there is a header and then the data follows below.
If the one section has a character of 3 or more then all my alignment is thrown out the window. Wondered if there was a command or something that can set how far I am from the previous character. Like in C++, there is setw(). I wonder if there is something other than "%5d" so it moves it 5 spaces or spots over that would work. But, then I would need to sprintf all my strings and character which can't be done because they are fixed strings/arrays. Attached is the example:
I did something like this for a logging function. This function outputs columnar formatted rows of text that are then written to file, no a MessagePopup. But outputting to a popup should work the same.
The '-' character will left-justify the substring.
#define TIME_COL 10 sprintf(string, "%-*s", TIME_COL, TimeStr());
01-03-2019 07:17 AM
I'll give that a try. I'll let you know how it goes.
Thanks!
01-03-2019 10:11 AM
@ElectroLund how do I format a character to a character variable like you did in your output below. I get a mismatch error when I try to do it. And if I try using a string as the character mapping. It won't move the output at all. Even if I put 100 spaces there.
01-03-2019 10:33 AM
I'm not totally clear what you are seeing. But I'm guessing you got a GPF for specifiers not matching? In my example above, "string" is a character buffer
char string[100] = {0};
Now make sure that the elements correspond correctly. When you use a '*' character in place of a literal width, you can then use a variable reference for width. This is not required, you could have "hard-coded" the width. But if you use a variable width, you must have the order correct in the specifier list!
This is a great reference.
01-03-2019 01:16 PM
Okay, I sorta found out why I was running into issues. It was a dumb mistake on my part. Never changed my variables after I added spaces into them. But I do understand what you were saying in the last reply.
Thanks for the help!