Output Box not displaying

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 5 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #37382
    Profile photo of Andy Smith
    Andy Smith
    Participant

    Evening all

    Any reason why the below will not display in the outputbox? It's just blank with no errors

    
     function graphics {
    
    $HostName=$InputBox.text;
     
    $card = get-wmiobject Win32_VideoController -ComputerName $HostName
    $graphics = $card.caption
    $outputBoxGcard.text=$graphics }
    
    $outputBoxGcard = New-Object System.Windows.Forms.TextBox
    $outputBoxGcard.Font = "Bartclays,8"
    $outputBoxGcard.Location = New-Object System.Drawing.Size(10,210)
    $outputBoxGcard.Size = New-Object System.Drawing.Size(150,60)
    $outputBoxGcard.TextAlign = "Center"
    $outputBoxGcard.MultiLine = $True
    $HardWare.Controls.Add($outputBoxGcard)
    
    
    $ButtonMon = New-Object System.Windows.Forms.Button
    $ButtonMon.Location = New-Object System.Drawing.Size(385,180)
    $ButtonMon.Size = New-Object System.Drawing.Size(50,30)
    $ButtonMon.Text = "Monitor Sizes"
    $ButtonMon.Add_Click({$outputBoxMon.Text=""})
    $ButtonMon.Add_Click({$outputBoxGcard.Text=""})
    $ButtonMon.Add_Click({monitors})
    $ButtonMon.Add_Click({graphics})
    $Hardware.Controls.Add($ButtonMon)
    
    
    #37384
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The 4 separate event handlers for $ButtonMon.Click look a little fishy. Might be something happening with order of execution there. Try making it a single script block:

    $ButtonMon.Add_Click({
        $outputBoxMon.Text=""
        $outputBoxGcard.Text=""
        monitors
        graphics
    })
    
    #37387
    Profile photo of Andy Smith
    Andy Smith
    Participant

    I removed them and still no joy 🙁

    #37396
    Profile photo of Andy Smith
    Andy Smith
    Participant

    If i remove the "| selec caption" i get the whole property display in the output box.. So it's baffling me why just the caption won't display

    #37398
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Are you running PowerShell v2, by chance? If $card is an array, in PSv2, you'd get nothing when you tried to do $card.Caption (because arrays don't have a Caption property.) In PSv3 or later, it'll enumerate the array for you and give you the Caption properties of the elements in the array.

    To be V2 compliant with arrays, you'd do this:

    $card = get-wmiobject Win32_VideoController -ComputerName $HostName
    $graphics = $card | Select-Object -ExpandProperty Caption
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.