Variable and .visible fonction

Ask your PowerShell-related questions, including questions on cmdlet development!
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 4 years and 2 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
adminmicro
Posts: 13
Last visit: Wed Dec 06, 2023 8:31 am

Variable and .visible fonction

Post by adminmicro »

Hello,

I have a loop to test file dates on a server list
For each server I want to display an image in the GUI PowerShell Studio

My script in my loop is :
$icoActivation = '$' + $node + 'KoStatus'
$icoActivation.Visible = $true
And the error is : The properties "Visible" is not existe for this object

Do you have an idea for me?

Regards
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Variable and .visible fonction

Post by jvierra »

That is correct. The variable is a string and strings do not have a "visible" property.

$icoActivation = '$' + $node + 'KoStatus'
$icoActivation.GetType()


Why would you want a string to be visible. I suspect you have an icon object that is what you really want to make visible,
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Variable and .visible fonction

Post by jvierra »

Your use of $node seems to indicate that this is a TreeView question. See the following article section for help using images with nodes.

https://info.sapien.com/index.php/guis/ ... #imagelist
User avatar
adminmicro
Posts: 13
Last visit: Wed Dec 06, 2023 8:31 am

Re: Variable and .visible fonction

Post by adminmicro »

Thanks for your help

$icoActivation.Visible is a picturebox
I have a picturebox for each node (Picturebox for services OK, Picturebox for service Ko)
The name type for the picturebox is %ServerName%SrvOk (For exemple Poller01srvok)

Since I'm using a foreach loop, I'm looking for how to indicate the variable with the visible function

foreach ($node in $listAPE)
{
$sqlnetAPE = Get-Item ......
if ($sqlnetAPE -eq $sqlnet)
{
$icoActivation = '$' + $node + 'srvok'
$icoActivation.Visible = $true
}
else
{
$icoActivation = '$' + $node + 'srvKo'
$icoActivation.Visible = $true
}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Variable and .visible fonction

Post by jvierra »

The following line turns the picturebox into a string.
$icoActivation = '$' + $node + 'srvok'

To find a control by string name:


$form.Controls[$node + 'srvok'].Visible = $true
User avatar
adminmicro
Posts: 13
Last visit: Wed Dec 06, 2023 8:31 am

Re: Variable and .visible fonction

Post by adminmicro »

Thanks for your help

It works very well

Just for information, be careful to put the name of the form so that it works ($form for my is $formservicesstatus)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Variable and .visible fonction

Post by jvierra »

adminmicro wrote: Thu Jan 23, 2020 6:53 am Thanks for your help

It works very well

Just for information, be careful to put the name of the form so that it works ($form for my is $formservicesstatus)
There is no way for us to know the name of your form.
User avatar
adminmicro
Posts: 13
Last visit: Wed Dec 06, 2023 8:31 am

Re: Variable and .visible fonction

Post by adminmicro »

No problem, This is just a clarification for other readers.
Regards
This topic is 4 years and 2 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