08-25-2015 02:23 PM
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.
Solved! Go to Solution.
08-25-2015 02:25 PM - edited 08-25-2015 02:27 PM
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> ---'
08-25-2015 02:28 PM
08-25-2015 02:36 PM
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> ---'
08-25-2015 02:41 PM
08-25-2015 02:42 PM
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.
08-25-2015 02:48 PM
08-25-2015 02:48 PM
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> ---'
08-25-2015 02:49 PM
08-25-2015 02:56 PM
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.