LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I retain lefthand zeros as placeholders in LV?

I want to add two numbers, but need to retain zeros on the left for place holders. for example:
 
0000000123
0000060000
----------------
0000060123
 
The arithimetic 'add' function drops the lefthand zeros and I can't figure out a way to add two strings.
 
Note - I tried adding an additional lefthand '1' just as a place holder, like this:
 
10000000123
10000060000
------------------
20000060123
 
then converting the number into a string and truncating the extra '2', but for some reason I can't seem to add numbers this large. Any suggestions?
0 Kudos
Message 1 of 14
(3,682 Views)

You probably can't add the numbers because your representation is not enough (maybe an I16 or a U16). Try changing it to U32.

A better solution would be to simply change the formatting of the indicator to show the extra 0s. Right click the indicator, select Format & Precision, select Floating Point and play with the options to get what you want (especially Minimum Field Width).


___________________
Try to take over the world!
0 Kudos
Message 2 of 14
(3,665 Views)
hi
 
Pls find attached VI useful as reference.
There should be better solutions 🙂
 
Cheers!
 
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
Message 3 of 14
(3,664 Views)
Simple with the minimum field width setting.
Message 4 of 14
(3,660 Views)

Hi Dennis,

Many thanks 🙂

Time to sleep...

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 5 of 14
(3,657 Views)
Ian - I think your code will work. I never thought of using 'string length' like that. Thanks a million!
0 Kudos
Message 6 of 14
(3,654 Views)
Hi Paul,
 
You're most welcome!
 
With my VI, you may varies the number of 0s (string) to be padded programmatically.
Nevertheless, the padding code could be simpler (kind of seen something simpler somwhere ??)
 
However, for fixed 0s to be padded, Dennis's VI will be great!
 
Zzzz...
 
Regards,
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 7 of 14
(3,647 Views)

Dennis, my problem with using the 'pad with zeros' setting is that I need to use the number elsewhere in my code rather than just displaying it. I think Ian's code will work. Thanks again to you both.

 

 - Paul

0 Kudos
Message 8 of 14
(3,645 Views)
Using a number (as opposed to a string) with leading zeros later in the code doesn't make any sense EXCEPT for display purposes. Internally, the representation is the same. If, later in the code you have to convert the string with leading zeros to a number, then all that you're doing is extra processing.
0 Kudos
Message 9 of 14
(3,638 Views)

Dennis, I'm actually using the large number as a time code. I'm trying to build a generic timer where the user can enter in a length of run-time. Months, days, hours, minutes, seconds. I'm trying to use a number that the user generates by entering in the length of run time (for instance: 4 months, 7 days, 8 hours, 30 minutes looks like: 04070830) and adding that number to the system time formatted in the same way. (--- this is where I was having the problem with adding numbers with lefthand zeros)

I'm trying to use this method so that the vi will be generic and totally independant of the point in time when the vi is called. Attached is my code so far if you're at all interested (keep in mind this is a work in progress and I am a complete newby at programming).

This started as a very simple sub-vi until I decided to make it as generic as possible. The difficult thing is trying to match the system clock. What if someone sets the run-time to run 9 hours overnight? After 23:59 hours the clock resets to 0100 and the day increments by one. Same problem if the vi happens to be running on the last day of the month or the last day of the year.

Oh well - once I get it debugged it should be truly generic and I can use it in any number of different applications.

- Paul
0 Kudos
Message 10 of 14
(3,631 Views)