Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed please: Assign variable to left hand side of an object definition

Status
Not open for further replies.

PaulSc

MIS
Aug 21, 2000
148
GB
Hello everybody,
Im after a bit of guidance/pointers please on how to do something in PowerShell....

I have a function which displays the status of system services using a traffic light graphic...

What I'm trying to do is to call the function with a number of parameters most of which are then used for substitution of variables i.e. "folder/subfolder/trafficlight"+$trafficlightnumber+".jpg" etc
however I also have a number of PictureBox's on a WPF form which I need to set the .Imagelocation tag

my "plan" is to call my function SERVICERunning "10" "green" "1" "1"
and these in turn would generate a value of $trafficLight10 Trafficligt_green.jpg $outputBox1 $ServiceCheck1

SERVICEStopped "11" "Red" "2" "6"
would generate a value of $trafficLight11 Trafficlight_red.jpg $outputBox2 $ServiceCheck6 etc

What I'd then like to be able to do is build up the following

$TrafficLightxx.ImageLocation = "\\folder\subfolder\TrafficLightRed.jpg" (Where xx is the number passed through from the function (i.e 10 or 11)
$OutputBoxy.Font = 'consolas,12' etc (where Y is 1 or 2..)

These reference WPF.PictureBoxes, RichTextBox etc and I have (so far!) 8 traffic lights, 2 output boxes

Ive tried Params and [Ref} tags and I can see in debug mode that its passing the values through but when it tries to set the associated property it reports that its not found for the object...

Any suggestions as to how to set a dynamic/pass thru value for the name of the object on the left of a definition please or if indeed it can be done..?

Sample of what Ive tried....

Code:
Function ServiceRunning  {

    Param([String]$xxvariable1xx,[String]$xxvariable2xx,[String]$xxvariable3xx,[String]$xxvariable4xx)
    $WhatTrafficLight = -join('$TrafficLight',$xxvariable1xx)
    $WhatOutputBox = -join('$OutputBox',$xxvariable3xx)
    $WhatCheck = -join('$ServiceCheck',$xxvariable4xx)
    [Ref]$TrafficLight.ImageLocation = "\\folder\subfolder\Light_"+$xxvariable2xx+"_Small.png"
    [Ref]$WhatOutputBox.SelectionColor=[Drawing.Color]::Green
    [Ref]$WhatOutputBox.Font = 'Consolas,12,style=Bold'
    start-sleep -Seconds 1
    $msgText = -join([Ref]$WhatCheck[2].ToUpper(),"`t"," RUNNING","`t","(",[Ref]$WhatCheck[1],")") 
    Add-ToOutputBox1 -Message $msgText
    [System.Windows.Forms.Application]::DoEvents()
}

Thanks.

PaulSc
 
Are you looking for something like this?

Code:
New-Variable -name ("TrafficLight"+$xxvariablexx)


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top