Jump to content

Indexing combo Box for both value and String

Recommended Posts

Hi All,
I'm new to LabVIEW and overall programming. I wanted to use a combo box to extract the string and associated value to use later for calculation and presentation.
I have come up with this one below, which works fine and is very modular (I can just add the solvent info, and it is good to go with no other change, unlike implementation as case structure). However, I wanted to know if this is good or is there a better (more straightforward) way to achieve the same thing?




Link to comment

There are many ways to "skin that cat", but these are the routes I would probably use myself:

Using a Text Ring instead of a Combo Box (The RingText.Text property outputs the string of the selected item):



If you're set on using a combo box method, here would be my approach (the Text.Text property outputs the string value of the selected item):


Edited by Bryan
Link to comment

I'm not sure if I'm missing something, but I don't believe that the code is going to work reliably or as intended, unless I'm not understanding how this SubVI is to be used.

Updating combo box items/values in a subVI doesn't really make sense (unless you're passing a reference to a front panel control into it).  Even then, you'd have to update the combo box items/values before the they're selected by the  user - then use the user's selection to search for and return the Density/Refractive index values.  

I have a lot going on right now, so I'm unable to provide an example at the moment.


Link to comment

Hi Bryan, 

You are absolutely correct the file processing and updating the combo box will happen out side, and the info is will be send to the vi (but since the rest of the app is not developed I left it here to test if it works fine). 

I am also going to use the same setup to get several other constants and initialisation conditions as another combo box. 

This was done so I can just save new conditions as new procedures later and reload when needed. 

I am just not sure if I should open, update the combo only, close the file and then release the reference to save memory. Then when the user selects from the combo box reopen the file and generate the required data for initialisation and only keep that info and close the file again and empty the array, again to save resources. 

The program have a long way to go and I'm too slow in learning (not a programmer as you can tell) 



Link to comment

Okay, I understand now.  

Once you've opened a file reference, you can keep it open for the duration of the program's use without much in the way of a resource concern.  Unless you're creating a MONSTER of a program (I've seen some, they exist) or have memory leaks somewhere, modern computers should have plenty of resources. 

That being said, Opening/reading/closing a file repeatedly is harder on resources than simply keeping a reference open, but depending on the scale, it may be a non-issue.  Using the function in your example to read the file does this, but for your purposes (as I understand them), this should be fine.  If you were constantly reading/writing/streaming to a file several times a second, then using that VI wouldn't be recommended.

So, yes - I would say that you could open/read the file to populate the combo box, then later open/read the file again to search for the desired values.  My guess is that these two actions aren't going to be occurring at a fast/high enough rate to be of any concern with regard to resource usage. 

Link to comment

I think an important point has been missed in this discussion. The fact that the solvent name and density make up a "collection" of information (i.e. a data type).

@Mahbod Morshedi if you don't already know about them go an read up about Clusters in LabVIEW. They allow you to make custom data types where you can group together related elements. Maybe even a Set would be an interesting implementation here where you can look up the density by using the name of the product.

Don't be tempted to grab into your GUI to get at your data (i.e. reading from a combo box to get the density). Rather store the data somewhere else (on a wire) and just access it as you need to.

Link to comment

Thank you, Bryan; I will keep that In mind.

Thank you, Neil, as well;  Indeed I know about clusters and TypeDefs and Do use them, and I think overall, I will be leaning towards making Classes and storing all the native app data in the class, so they remain private. 

At this time, I am implementing top-down, bottom-up piece by piece since this is my first real-world programming experience.

I appreciate all your comments and help and am very grateful.


Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By nagesh
      I need to use 5 Bytes Hex string as a key, Hex string as a Value. Normally data stored in INI as ASCII.
      What can be the possibilities to store HEX String?
    • By Randy_S
      Good morning,
      I have a DLL I created (in Labview)  that takes in string information, does some magic crunching on it to create a password that is passed out as a string.  This DLL will be called from CVI and probably from a C# application.
      This should be so simple, however I cannot figure out how to pass the string in and get the modified string out of my DLL.
      I've had no luck at all getting this DLL to work by trying many different things.  It crashes LV, returns and error, or simply passes nothing out during my trials.
      I've included the project (its small) in zipped format.  Can one of you kind souls take a look at my code and tell me what I'm doing wrong, or what I need to do correctly to both, configure the DLL and then call it from LabVIEW?
      Thank you!
      Password Generator.7z
    • By bingbot
      1: How to get last index, not last element, but last index number of an 2d array?
      2: say 2d array has contents
      elephant  crow    dog      goat
      giraffe      eagle   cat       fly
      ant          pig        horse   bee
      How to get that the bee is the 12th or 11th index in the array? (11 if you count elephant as zero index, 12 if you count elephant as first index), meaning I want the index number 11 or 12, not "bee"
    • By Manudelavega
      As far as I now there is 2 way to define how to format a numeric into a string using the floating point representation (%f):
      - Setting the number of significant digits (%_2f)
      - Setting the number of digits or precision (%.2f)
      However I often find myself in the need of a way to define the width of the string. For example I always want 3 digits maximum. Using significant digits won't work if the number is 0.0012 since this only has 2 significant digits, so the string will be 0.0012 even though I would like to see 0.00 (so 0 if we hide trailing zeros).
      On the other hand, using digits of precision won't work if I have a number like 123.45 since it has 2 digits of precision, so the string will be 123.45 even though I would like to see 123.
      Now the obvious brutal way would be to use a string subset and only keep the first 3 digits (I guarantee that my number is never bigger than 999). But I really hope there is a more elegant way. I can't imagine that nobody has run into this requirement before. How did you tackle it?
    • By Manudelavega
      I have been trying to understand what's going on with my tree control and I'd like to share this with the community to see if somebody has seen this behavior before. Maybe there is something obvious that I am not seeing...
      I attached the VI (LV2011) with instructions inside (will take you 20s to perform the experiment, I dismantled the VI to its bare minimum). Please don't comment on the overall architecture (state machine...) since I modified the VI just for the sake of posting it here and removed all advanced features.
      Long story short, after programmatically modifying the value of the tree, I modify its value a second time by clicking directly on one of the tree items. I then expect the NewVal value given through the left node of the value change event case to match the value of the tree terminal. Depending on the code that first modified the value programmatically, sometimes this expectation is met and sometimes it isn't. Run the code, it's easier to understand that way...
      Thanks for your feedback!
      Tree value issue.vi
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.