LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Limit of number to string work around

I am using a while loop that saves the data each time the loop is run into a different file name each time. I am using shift registers to create a number that starts with 0 on the first loop and adds 1 to it each time the loop is run. So 0,1,2,3........ This is pretty straight forward and works correctly. At the start I enter a string that then gets the nummber (string) appended to it and this is used to give the name of the file that is saved. I run into a problem when the number exceeds 255 as the string then returns the same value as the first one. Example shown below. original string: "test" 1st loop: "test_0" 2nd loop: "test_1" .................. 256th loop: "test_255" 257th loop: "test_0" Now I have thought about using dividing the number in the loop by 256 and rounding down. Then convert this number to string and append. This will limit me to 256 x 256 files but this is fine with me. Exampe below to make it clearer. 1st loop: "test_0_0" 2nd loop: "test_0_1" .................. 255th loop: "test_0_255" 256th loop: "test_1_0" Are there any better ways to do this?
0 Kudos
Message 1 of 5
(2,997 Views)
You must be using a U8 data type for the shift register.  Change this to U32 and your numerical range will be much greater. like 0 to 4294967296.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 5
(2,992 Views)
Thanks. I will try that tomorrow as I am not at work today. I would have looked into that except I was thinking that 255 was the highest number that can be converted to a string so didn't think the problem lies in the number data type.

Now you mention it, it's pretty obvious I should have checked to see if the number was a U32 instead of a U8.
0 Kudos
Message 3 of 5
(2,986 Views)
If you're writing data every loop iteration, why aren't you just using the loop count for your number?  It automatically increments and doesn't need a shift register.
0 Kudos
Message 4 of 5
(2,976 Views)
I'm not sure why I didn't use the while loop counter. I changed from a for loop where I was using the loop count but for some reason I decided to use shift registers in the while loop.

I'll blame these silly mistakes on it being Monday when I wrote the vi LOL.
0 Kudos
Message 5 of 5
(2,973 Views)