Jump to content
News about the LabVIEW Wiki! Read more... ×
IpsoFacto

Setting Object Default Value Programmatically

Recommended Posts

Is it possible (using Scripting, I assume) to modify the default value of an object programmatically? I have an object whose default value is loaded at runtime to represent some system settings and I've created a UI to modify those settings. Currently I manually take the settings and copy them into the object and right-click -> Set as Default Value, than save it. Was wondering if there was a way to do this programmatically?

Share this post


Link to post
Share on other sites

You can set the default value of a control using scripting.  But I don't think this is what you want.  Very few scripting functions work in the run-time engine.  Scripting is generally a thing that makes LabVIEW code, or edits LabVIEW code.  These are not the types of things you do in a run-time engine.  In a built EXE for C++ you wouldn't generate new source code that is compiled and then used in that EXE.  It would be something like self modifying code, and probably should be avoided.

 

But what you can do is use a function like the OpenG Write Panel to INI, and Read Panel From INI.  This will take the control values for every control on your front panel, and save them to a human readable INI file.  Then on startup of your program you can use the Read Panel From INI and it will set the control values to what they were last saved to.  Where you save the INI is up to you, but you may get into some permissions issues if you try writing and reading to files under Program Files, which is why most programs are gravitating to using the Application Data folder, or ProgramData for all users.

 

These two wonderful OpenG functions can be found in the Variant Configuration package.

  • Like 1

Share this post


Link to post
Share on other sites

Hooovahh,

 

Thanks for the reply. Unfortunately my settings object has in it's class data other objects. I tried collapsing the objects to XML however one of these objects can grow rather large and I get the 1803 error when expanding it from XML.

Share this post


Link to post
Share on other sites

My preference would be to have a "Set to Default" method of the class that initialises the object with reasonable defaults that you call on teh startup of your application. Then your settings UI can call methods on the object to tweak teh settings as the user desires.

 

As a general rule I dislike the "Default Value" properties of controls because they can be very hard to control and enforce over the development lifetime of an application.

Edited by ak_nz
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

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