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?

Cheers,

Mahbod

image.png.e5e3eaa14f5455aa4b7bab1838226aa2.png

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):

Example.png.89f243d252b3587a729bf3c1c2de9a0c.png

 

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):

Example2.png.c281bd7e8b31fd52e8024c60e4e8467c.png

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) 

Cheers, 

Mahbod 

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.

Cheers,

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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