LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from String Variable Order (%$) is not working

Solved!
Go to solution

Hello, I'm trying to use the function "Scan from String" with variable order using the syntax element %$ as shown in the example of the following document:

 

https://www.ni.com/docs/en-US/bundle/labview/page/lvconcepts/format_specifier_syntax.html#format_spe...

 

But it's not working, the function is taking the number I use to indicate order as if it was a fixed field width specifier, like if the $ symbol wasn't there.

 

Does anyone knows what am I missing here?

 

I'm using this code: 

ArturoCarranzaFMC_0-1681346074102.png

 

and getting this result

ArturoCarranzaFMC_1-1681346164293.png

 

I'd appreciate any help on this

 

Thanks

 

LabVIEW Professional Development System

Version 2022 Q3 (32-bit) 22.3.1f8

0 Kudos
Message 1 of 13
(1,516 Views)
Solution
Accepted by topic author ArturoCarranzaFMC

That example is meant to be used with Format Into String VI.

ZYOng_1-1681350719366.png

 

What are you trying to achieve with that syntax?

-------------------------------------------------------
Control Lead | Intelline Inc
Message 2 of 13
(1,491 Views)

As @ZYOng notes, you mixed up "Format into String" (which has an initial String input, and places at the bottom to wire in other values you want to add to the String, specifying the Format for these (presumably non-string, usually numeric or Time) inputs) and "Scan from String" which extracts data from a String input, with the data types specified by the lower terminals, and the Format String specifying how to interpret the contents of the input String.

 

When I was learning LabVIEW, I found parsing String with the many Number/String conversion functions, confusing and difficult, until I stumbled on Scan from String, which I use whenever I need to parse a String.  I have never used the Variable Order format specifier (%$), and I would urge you also to never use it -- it works, but it obscures what you really want to do, namely invert the order of the names.  Much better is to explicitly reorder the outputs on the "output side".  See if you don't agree that this is easier to code, and easier to understand what it does:

Scan from String.png

 

As I was creating this Snippet, I idly wondered how I would parse "Smith, John".  This led me to think how I would parse a "Comma-separated-variable" string (where commas separate fields).  Turns out (as I was saving the Snippet above) I had another Snippet "Scan String with commas" that I had forgotten about (I posted this in 2019).  Here's a hint -- Scan from String is the second function that you need before scanning "Smith, John".

 

Bob Schor

Message 3 of 13
(1,483 Views)

Thanks, I'm reading many data from XML files and building an array with all the data, I want to ensure that all data coming from XML files will always be in the same specific order so I can be sure that each data value is always in the same index position of the array even if the data is in different order across different XML files. When reading the XML file I get a string and I was hoping I could use the Scan from String function to get and order all my data prior to building an array with it.

 

Thanks, now I know Scan from String function might not be the way to achieve what I'm trying to do.

0 Kudos
Message 4 of 13
(1,438 Views)

ArturoCarranzaFMC_0-1681402143105.png

Thanks @Bob_Schor, I think you are referencing this snippet, I found it in your profile pictures from 2019. Thanks

0 Kudos
Message 5 of 13
(1,425 Views)

@ArturoCarranzaFMC wrote:

Thanks, I'm reading many data from XML files and building an array with all the data, I want to ensure that all data coming from XML files will always be in the same specific order so I can be sure that each data value is always in the same index position of the array even if the data is in different order across different XML files. When reading the XML file I get a string and I was hoping I could use the Scan from String function to get and order all my data prior to building an array with it.

 

Thanks, now I know Scan from String function might not be the way to achieve what I'm trying to do.


I'm not quite sure I understand the issue.  If you parse the XML values in the same order, don't they get put into the string in the same order?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 13
(1,416 Views)

Thanks for your interest, I'm working on a modular software which requires to accomplish an extensive process for verification and validation, it also requires frequent updates usually for configurations, each update requires to be verified and validated, which takes months. Even if the software is changed in minutes, the verification and validation process takes from weeks to months. So I'm trying to allow the software to work with current and future XML structures so most updates could be limited only to add data into XML files. I was thinking that could save some steps by scanning the result string from the XML, but I think I'll have to use the specific XML parser functions. I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.

 

Thank you all

0 Kudos
Message 7 of 13
(1,402 Views)

@ArturoCarranzaFMC wrote:

Thanks for your interest, I'm working on a modular software which requires to accomplish an extensive process for verification and validation, it also requires frequent updates usually for configurations, each update requires to be verified and validated, which takes months. Even if the software is changed in minutes, the verification and validation process takes from weeks to months. So I'm trying to allow the software to work with current and future XML structures so most updates could be limited only to add data into XML files. I was thinking that could save some steps by scanning the result string from the XML, but I think I'll have to use the specific XML parser functions. I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.

 

Thank you all


Oh, got it!  I didn't realize you were just doing a straight text read and not using an actual XML parser.  Thanks for clarifying.  V&V, needs to be done, but it sure is a pain.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 13
(1,396 Views)

@ArturoCarranzaFMC wrote:

I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.


The Variable Order syntax works just fine in Scan from String -- I just recommend not using it, and "interchanging the wires" on the output side, as it is much easier to understand (and hard to find an explanation for what $ means in a Format String specification.

 

Bob Schor

0 Kudos
Message 9 of 13
(1,393 Views)

Hi @Bob_Schor, I'm not sure I understand, so my code with Scan from String should work? If it could work it would be easier to edit the format specifier from an external source so I wouldn't need any change to my code and I could have it easy on the verification and validation. Swapping wires it's a change in the code so I would need to update requirements and test procedures, elaborate a test report, organize a design review and document it just to swap the wires, it would take from weeks to months, so it's much easier if I could swap data just by updating an external source without any code modification.

0 Kudos
Message 10 of 13
(818 Views)