LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to parse a string for use in a lookup table?

Solved!
Go to solution

I'm trying to create a system whereby users can create a premade simulation, and store the simulations to be able to load them easily at their convenience. The way it currently works is that when the user creates a simulation, the information about the simulation characteristics is condensed down to a 12-character string, which is written to a text file of the same name as its contents. This string is then read, and ideally I'd have some kind of lookup table to convert the characters into the information they were condensed from. For example, a variable X may have possible values {650,720,851} which gets mapped to {A,B,C} during the creation process. When loading, I'd like to be able to send C into a subVI and have it output 851, for bundling in a cluster. How can I neatly accomplish this in LV? So far, the best I've got is this messy thing:

 

Which basically scans through the string character by character, and bundles the appropriate value for the given character at the given offset.

0 Kudos
Message 1 of 14
(4,138 Views)
Solution
Accepted by topic author ijustlovemath

You want to use the configuration VI palette.

These VIs make it stupid easy to save and load values from file using Sections and Keys.

 

You could use section "X" and keys "A", "B", or "C" to fulfill your example.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 14
(4,134 Views)
So, I've already created the "new simulation" interface. Will I have to change how things are set up there to use these?
0 Kudos
Message 3 of 14
(4,130 Views)

The config VIs are a solution for the File IO part and are really the best way to do it. You can stick with your current method of parsing through 12 cahracter strips, but you're making it way harder for yourself.

 

Where are the settings coming from? Are these direct values from controls on your front panel? If so, you can use OpenG Write Panel and Read Panel VIs to load and save control and indicator values even easier.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 14
(4,110 Views)
This does look much easier, I think I'm going to use it. This will run before the simulation, so no front panel will have spawned yet. The new simulation portion is currently a series of dialogs prompting for configuration details, which are then parsed into the characters of the string. Thanks for the tip, you've probably just added years into my life!
0 Kudos
Message 5 of 14
(4,104 Views)

How do you keep the database of possible values for each string? How ofter does it change?

 

Also remember that the use of variant attributes is a very fast and efficient way to store/retrieve key/value pairs.

0 Kudos
Message 6 of 14
(4,101 Views)
My user basically gave me a spreadsheet of characteristics they'd like to be able to set, there's 35 permutations for all 12 variables. Currently the dialogues have typedef enums (drop down boxes) that the user changes. I had to do 10 dialogues to preserve the character order, but now there's probably a way to do them in parallel. What are variant attributes?
0 Kudos
Message 7 of 14
(4,095 Views)

To add on to what Altenbach said, you should get the OpenG add-on if you don't have it already. It comes with a few altered versions of the config VIs that make it easy to save and load data from file without needing to parse to/from a string (it uses variant conversions). OpenG can be found in your VI Package Manager.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 8 of 14
(4,093 Views)
They aren't likely to change, as the rest of the application is complete to the users specifications.
0 Kudos
Message 9 of 14
(4,090 Views)

I would probably use String To Byte Array.  You can then Autoindex on the array of bytes and use Index Array to get your values.  This assumes you have an array with the possible values to index in the first place.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 14
(4,074 Views)