Update Variable after Form closing/opening

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
dlaurora
Posts: 31
Joined: Wed Oct 26, 2016 10:43 am

Update Variable after Form closing/opening

Post by dlaurora » Sat Apr 06, 2019 2:51 pm

Hello everyone,

Do you know if there is any way to update a variable inside a form when it opens and close, like a counter variable to be used to know how many time the program has been used or to edit a number like 1000 and when we open the program it pas to 1001?

jvierra
Posts: 13881
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Variable after Form closing/opening

Post by jvierra » Sat Apr 06, 2019 3:50 pm

You can change any variable on open and close by adding the changes to the form "Load" an "FormClosed" events. Just change and save the variable as needed.

User avatar
dlaurora
Posts: 31
Joined: Wed Oct 26, 2016 10:43 am

Re: Update Variable after Form closing/opening

Post by dlaurora » Sat Apr 06, 2019 5:51 pm

So, if for example, create a variable. let say $count with a value of 1, and close the form, next time I open it, can change it to 2, and maintains the new value?

Not sure if below syntax it's correct.

Code: Select all

$formGeneradorCodigoQR_Load={
	$TextboxCount.text = $count
}

$formGeneradorCodigoQR_close = {
	$count = $count + 1
}

jvierra
Posts: 13881
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Variable after Form closing/opening

Post by jvierra » Sat Apr 06, 2019 6:22 pm

You would have to save the value somewhere Variables in programs are not saved after a program closes.

User avatar
dlaurora
Posts: 31
Joined: Wed Oct 26, 2016 10:43 am

Re: Update Variable after Form closing/opening

Post by dlaurora » Sat Apr 06, 2019 6:52 pm

Thank you for you advise, i will try to following this steps from https://www.sapien.com/blog/2018/03/22/ ... nal-files/

perhaps I can save the data into a txt file, update it each time it close and the get the last result once I open again the form, thanks!

Locked