Powershell v5.0 > 3.0 Help

This topic contains 2 replies, has 1 voice, and was last updated by Profile photo of Chris Eves Chris Eves 5 months ago.

  • Author
    Posts
  • #65287
    Profile photo of Chris Eves
    Chris Eves
    Participant

    Good morning all,
    I am working on a project for work and I have hit a snag.

    My home version of Powershell is V5.0, Works is 3.0

    I have a button that resets all data on the form.
    It works at home but not at work. 🙁

    Here is the code:

    #Clear Button
    $btnClear  = New-Object System.Windows.Forms.Button
    $btnClear.Location = New-Object System.Drawing.Size(($cboPriority.Left + $cboPriority.Width + 137),($cboPriority.Top - 3))
    $btnClear.Size = New-Object System.Drawing.Size(140,30)
    $btnClear.BackColor = "RED"
    $btnClear.ForeColor = "White"
    $btnClear.Text = "CLEAR MDS - ALL"
    
    ##Main Page##
    #Clears All Text.
    $btnClear.Add_Click{$txtLoginName.Clear()}
    $btnClear.Add_Click{$txtBuilding.Clear()}
    $btnClear.Add_Click{$txtFloor.Clear()}
    $btnClear.Add_Click{$txtDesk.Clear()}
    $btnClear.Add_Click{$txtContactNo.Clear()}
    $btnClear.Add_Click{$txtAltContact.Clear()}
    $btnClear.Add_Click{$txtDescription.Clear()}
    $btnClear.Add_Click{$txtTMPSE.Clear()}
    $btnClear.Add_Click{$txtReportedContact.Clear()}
    $btnClear.Add_Click{$txtReportedBy.Clear()}
    
    #Sets ComboBoxes to Please Select, Select and None on Main Page
    $btnClear.Add_Click{$cboCustomer.SelectedIndex = 0}
    $btnClear.Add_Click{$cboSpecialHandling.SelectedIndex = 0}
    $btnClear.Add_Click{$cboPriority.SelectedIndex = 0}
    
    $Rincewind.Controls.Add($btnClear)
    
    

    The problem occurs with the { }
    At home it works, Work nope. I cannot update Powershell on work computers.
    Is there a better way to do this?

  • #65290
    Profile photo of Chris Eves
    Chris Eves
    Participant

    Forgot the error... Would help!!

    At c:\Users\****\Documents\Rincewind\Rincewind.ps1:1408 char:20
    +$btnClear.Add_Clear{$txtLoginName.Clear()}
    +
    Unexpected token '{' in expression or statement.

  • #65305
    Profile photo of Chris Eves
    Chris Eves
    Participant

    Found a different solution.

    Function MakeNewForm{
      $Rincewind.Close()
      $Rincewind.Dispose()
      CreateForm
    }
    
    #Clear Button
    $btnClear  = New-Object System.Windows.Forms.Button
    $btnClear.Location = New-Object System.Drawing.Size(($cboPriority.Left + $cboPriority.Width + 137),($cboPriority.Top - 3))
    $btnClear.Size = New-Object System.Drawing.Size(140,30)
    $btnClear.BackColor = "RED"
    $btnClear.ForeColor = "White"
    $btnClear.Text = "CLEAR MDS - ALL"
    
    CreateForm
    
    $Rincewind.Controls.Add($btnClear)
    

You must be logged in to reply to this topic.