LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort 2D Array With Header?

Solved!
Go to solution

Hong.Zhang@agresearch.co. wrote:

Why error?

Thanks


Your code is fine for times in the morning (AM), but fails for times in the afternoon because the Scan from String expects to see either "am" or "pm" but you're feeding it "am" or "p.m." and the extra dots for the PM times cause the error. The code I uploaded in the previous post fixes both am and pm, by removing the dots from ".m.".

0 Kudos
Message 11 of 25
(971 Views)

There are two errors. The format specification should be "%<%d/%m/%Y %I:%M:%S %p>T" Note the change from H to I and the replacement of X with p.

 

The other is the Search and Replace String function needs to replace "a.m." with "AM" and "p.m." with "PM".  Your code only does one replacement and it uses lower case.

 

Lynn

Message 12 of 25
(970 Views)

Hi nathand

your codes is working. Date order is right but time is not right. For example, one row is  10/07/2012 3:00:00 a.m. next row is 10/07/2012 3:00:00 p.m. I want one row is  10/07/2012 3:00:00 a.m. next row is 10/07/2012 4:00:00 a.m.

 

How to is?

 

Hi Lynn

Thank you very much for help.

I could make ypur code to work. There is error. Please have a look at my vi.

 

Thanks

 

 

0 Kudos
Message 13 of 25
(961 Views)

Why do you have two different For Loops, and you aren't using one of them.

 

When I use your upper For Loop, and disable the lower one, your the code seems to work fine.

0 Kudos
Message 14 of 25
(953 Views)

Thanks RavensFan

The two For Loops are for two ideas. I only need one of them.

The lower one is working. But time order is not right.

 

The upper one report error at Scan From String function. 

 

Thanks

0 Kudos
Message 15 of 25
(948 Views)

The lower one won't work because you need to use I for the hour code rather than H (as was pointed out in earlier messages.  (Read the help for the format string codes to find out why.)  Also, it won't work because you are replacing m with M  The earlier examples showed .m. being replaced with m.  You forgot the periods.  And you are converting it to an upper case M.  So you wind up with a scan from string error because it doesn't know how to decode a.M. or p.M.

 

The upper loop works just fine.  I don't understand why you are saying the upper loop is causing you an error.  (Are you getting the words "upper" and "lower" mixed up?)

 

In short,

  • Use "I" for the hour code because it uses the 12 hour clock with AM/PM.  H uses the 24 hour clock and will ignore AM/PM thus getting the data intermixed because they both look like the same 1 o'clock hour.
  • Replace a.m. with AM and p.m. with PM.  You've got to get rid of the periods.  Where is the string data coming from?  Perhaps you should fix whatever is generating the string data so it writes AM and PM properly with the periods in it.

Attached is your VI with the loop that works.  I saved the results as the defaults in the indicator to show you the order is just fine.

 

 

0 Kudos
Message 16 of 25
(942 Views)

Thanks RavensFan

Your results looks prefect. But when I run it still got error. Please see the attached error message. What is problems?

 

The original data came from a database wrote by third part. I could not change it. I only can read the data out. 

 

Thanks again.

Hong

0 Kudos
Message 17 of 25
(939 Views)

If the "result looks perfect", how can you "still get an error"?

 

Put a probe on the string wire going into the Scan from String, or at least an indicator  That way we can see what line it is hanging up on when it stops.  Then post a screenshot of that.

 

Is it any chance that you are using an operating system where it uses a comma for a decimal point, instead of a period?  While I don't see that having an effect in the format string you have, that is a typical problem with format strings when one person has a format string that works fine, but it fails for another person.  However, your timestamp constant there appears that your OS is using a decimal point.

 

Until we see exactly what string it is hanging up on, there is no way to know what is going wrong.

0 Kudos
Message 18 of 25
(928 Views)

@johnsold wrote:

There are two errors. The format specification should be "%<%d/%m/%Y %I:%M:%S %p>T" Note the change from H to I and the replacement of X with p.

 

The other is the Search and Replace String function needs to replace "a.m." with "AM" and "p.m." with "PM".  Your code only does one replacement and it uses lower case.


Oops! Thanks, Lynn, for noting the errors in the format string. I never remember the format specifiers and apparently scanned the help too quickly when putting together this example.

 

A quick check indicates that the %p specifier is not case sensitive, so it's fine to replace ".m." with "m" as I showed without converting to uppercase.

0 Kudos
Message 19 of 25
(916 Views)

nathand,

 

I noticed that after removing the .m. it was less particular. The help file only shows upper case AM and PM.  Sounds like a situation where the documentation is less than complete or accurate. There are so many combinations in time formats that a few errors in the documentation or performance may exist.

 

Lynn

0 Kudos
Message 20 of 25
(912 Views)