LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting a Table

Solved!
Go to solution

Both methods have problems sorting numbers that have differing numbers of digits past the decimal point. For example, 10.425 becomes 10.000000425, while 10.422425 becomes 10.0000422425. That I can control easily by formatting any numbers with a fixed number of decimal places. 

But both methods also have trouble with negative numbers, and I haven't figured out how to fix that yet...

 

 

FlatCat_0-1768148994602.png

0 Kudos
Message 21 of 28
(108 Views)

@FlatCat wrote:

Both methods have problems sorting numbers that have differing numbers of digits past the decimal point. For example, 10.425 becomes 10.000000425, while 10.422425 becomes 10.0000422425. That I can control easily by formatting any numbers with a fixed number of decimal places. 

But both methods also have trouble with negative numbers, and I haven't figured out how to fix that yet...

 

 

FlatCat_0-1768148994602.png


I never considered supporting fractional numbers.  (But I might start thinking about it.)

0 Kudos
Message 22 of 28
(103 Views)

It is not expected to work with floating point numbers, but that can be solved once we know what's allowed.

 

Can we assume that your floating point fields don't have any alphabetic characters, or can they also be "mixed" (e.g. "10.456OHM" , "ABC=1.456", etc. "R.45AX:, etc.) Of course if they have an "E", they might be in exponential format.

 

Note that my sorting is most useful for filenames, mirroring the default behavior of windows explorer (e.g. file names have other periods, delimiting the file extension, so you need to be careful.)

 

0 Kudos
Message 23 of 28
(97 Views)

If we can assume that floating point numbers are cleanly formatted, here's what you could do:

 

altenbach_0-1768154509698.png

 

 

 

altenbach_0-1768153177051.png

 

 

 

Basically, we check if scanning the fields as floating point gives no error or no remaining string. Please test! No guarantees. Works fine with negative numbers, integers, and floating point in any recognized format.

 

See below for even simpler code...

0 Kudos
Message 24 of 28
(94 Views)

@altenbach wrote:

Yes, I got the gist of it from the picture

 

You are padding with spaces (i.e. a non-numeric character) while I am padding with zeroes (i.e. a numeric character)..

I am curious if there could be edge cases where it would make a difference, but haven't explored that.

 

One simplification would be to use the upper input of the format, eliminating your inner concatenation.

 

altenbach_0-1768150554547.png

 


I briefly thought about space vs zero, but quickly convinced myself that it would be OK.

0 Kudos
Message 25 of 28
(89 Views)
Solution
Accepted by FlatCat

It's probably sufficient just to check for error and switch mode when an error occurs:

 

altenbach_0-1768155843067.png

 

You might want to implement some error handling to ensure that all fields were processed with the same algorithm. (not shown).

Message 26 of 28
(71 Views)

This works. But, as I mentioned a few comments back when I described my first solution, I actually know beforehand whether the chosen column contains purely numeric or alphanumeric data. So I can chose the method on that basis. But the error check is nice if I just want to go by the contents of the table itself. 

0 Kudos
Message 27 of 28
(61 Views)

Try this.  Works with floats, scientifics, arbitrary number width.

0 Kudos
Message 28 of 28
(23 Views)