Progressbar visible set to false when sub form is loaded

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.
This topic is 8 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar visible set to false when sub form is loaded

Post by dan.potter »

:)
Attachments
test.zip
(25.73 KiB) Downloaded 128 times
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar visible set to false when sub form is loaded

Post by dan.potter »

test.zip
(25.73 KiB) Downloaded 153 times
forum ate my last post??
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Progressbar visible set to false when sub form is loaded

Post by jvierra »

dan.potter wrote:
test.zip
forum ate my last post??
Fixed.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Progressbar visible set to false when sub form is loaded

Post by jvierra »

It is never necessary to mess with scopt when calling between scrips and funcitons. Just pass the object.


in mainform
PowerShell Code
Double-click the code block to select all.
$button1_Click = {
	
	Call-sub_psf $progressbar1
	
}
In child form:
PowerShell Code
Double-click the code block to select all.
Param($pb)

$form1_Load={
    $pb.Visible=$false		
}
That is all and it was what I meant when I said use arguments.
User avatar
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Re: Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

You guys have to be kidding, it is so simple.
Thank you dan.potter and jvierra :D
Works perfectly :)
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar visible set to false when sub form is loaded

Post by dan.potter »

jvierra wrote:It is never necessary to mess with scopt when calling between scrips and funcitons. Just pass the object.


in mainform
PowerShell Code
Double-click the code block to select all.
$button1_Click = {
	
	Call-sub_psf $progressbar1
	
}
In child form:
PowerShell Code
Double-click the code block to select all.
Param($pb)

$form1_Load={
    $pb.Visible=$false		
}
That is all and it was what I meant when I said use arguments.
What is the drawback of changing the scope?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Progressbar visible set to false when sub form is loaded

Post by jvierra »

dan.potter wrote:
What is the drawback of changing the scope?
Harder to maintain. Less readable. Exposes variables to being clobbered.

Scoping should always be as narrow as possible. The whole point of passing arguments is to avoid exposure. In programming we pursue a policy of maximum "data hiding".

New programmers tend to make this mistake due to lack of experience and because it is an easy fix.

Think of the thing those new to Windows admin do which is to make everyone an admin. It takes some time too learn how to get the job done without creating issues.
This topic is 8 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked