3 Replies - 568 Views - Last Post: 09 May 2013 - 10:35 PM Rate Topic: -----

#1 hurdlinghurdles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-May 13

Retaining form control values after form close

Posted 09 May 2013 - 03:32 PM

Hi guys,

I have a formInputs with several textboxes. When I close formInputs(taking me to my mainform) I want the values of the textboxes to be retained somehow so that when I open formInputs again the values are still there.

The only way I have thought of doing this is by using savefiledialog to save the values to a file and then get the values from the file upon form startup. Is there a simpler way to do this?
Is This A Good Question/Topic? 0
  • +

Replies To: Retaining form control values after form close

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3593
  • View blog
  • Posts: 12,360
  • Joined: 12-December 12

Re: Retaining form control values after form close

Posted 09 May 2013 - 03:50 PM

See Application.Settings, where you can save and retrieve values.

There is a more direct route though. Click a textbox and go to the Properties window. At the top expand ApplicationSettings, and click PropertyBinding, then the build option (...). Select Text, the down-arrow next to (none), and new. Make up a name (txtKeepUser or whatever). Leave the default scope as User.

Do this for other textboxes. Then exiting and re-starting the application should recall the values (Text) for these controls.

Note: I haven't tested this myself for a published application, only in debug mode.

This post has been edited by andrewsw: 09 May 2013 - 03:54 PM

Was This Post Helpful? 1
  • +
  • -

#3 hurdlinghurdles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-May 13

Re: Retaining form control values after form close

Posted 09 May 2013 - 04:55 PM

Thank you, that worked great. Is there a similar way to do this with variables declared in the code?
I have a variable that increments by +1 every time a user clicks a button and would like to retain its value.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3593
  • View blog
  • Posts: 12,360
  • Joined: 12-December 12

Re: Retaining form control values after form close

Posted 09 May 2013 - 10:35 PM

Controls have a general Tag property that you might treat in a similar way. If you name it, for example, btnKeepTag, then in code something like:

My.Settings.btnKeepTag = CInt(My.Settings.btnKeepTag) + 1

My.Settings.Save

having given it an initial value of "0" could work. But it might be simplest to do this via the Project menu, Project Properties.. and Settings. See the link I provided earlier. This way you can define it as an Integer rather than having to convert Object -> String -> Integer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1