PrimalForms questions
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.
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.
- etherknight
- Posts: 18
- Last visit: Thu Apr 10, 2014 5:56 pm
PrimalForms questions
My raw PS script does a copy-item to copy some files and then does a get-childitem to list the files just backed up. I can associate the copy-item with a button. But how do I also associate a text box to show the resulting get-item, since the latter must wait for the former to finish to give results?
PrimalForms questions
Hi - here is a zip with a complete solution as a PrimalForms project(PFF).
http://www.sapien.com/forums/uploads/24 ... extBox.zip
The trick is here:
http://www.sapien.com/forums/uploads/24 ... extBox.zip
The trick is here:
Code: Select all
$handler_GetFiles_Click={
$textbox1.Text = dir c: | Out-String
}
PrimalForms questions
I attached the complete project as a zip file. Look closely at the code and run it in PrimalForms. It does exactly what you are looking for.
A TextBox object is a WIndows Control. It is one of many WIndows Controls available to the WIndows FOrms system under Net Framwork.
A $ in front text name is a designation that it is a variable in PowerShell.
PrimalForms names variables automatically but ther names can be changed as needed.
All of this is demonstrated in the ZIP file demo of how to do this task. Please study the file in the ZIP file attached above.
A TextBox object is a WIndows Control. It is one of many WIndows Controls available to the WIndows FOrms system under Net Framwork.
A $ in front text name is a designation that it is a variable in PowerShell.
PrimalForms names variables automatically but ther names can be changed as needed.
All of this is demonstrated in the ZIP file demo of how to do this task. Please study the file in the ZIP file attached above.
PrimalForms questions
Here is what it looks like after exporting to PowerGui v2
Code: Select all
########################################################################
# Code Generated By: SAPIEN Technologies, Inc., PrimalForms 2009 v1.1.8.0
# Generated On: 6/4/2010 5:07 PM
# Generated By: jvierra
########################################################################
#----------------------------------------------
#region Application Functions
#----------------------------------------------
function OnApplicationLoad {
#Note: This function runs before the form is created
#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
#Important: Form controls cannot be accessed in this function
#TODO: Add snapins and custom code to validate the application load
return $true #return true for success or false for failure
}
function OnApplicationExit {
#Note: This function runs after the form is closed
#TODO: Add custom code to clean up and unload snapins when the application exits
$script:ExitCode = 0 #Set the exit code for the Packager
}
#endregion
#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function GenerateForm {
#----------------------------------------------
#region Import Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
#endregion
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
[System.Windows.Forms.Application]::EnableVisualStyles()
$form1 = New-Object System.Windows.Forms.Form
$textbox1 = New-Object System.Windows.Forms.TextBox
$quit = New-Object System.Windows.Forms.Button
$GetFiles = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
# User Generated Script
#----------------------------------------------
$FormEvent_Load={
#TODO: Initialize Form Controls here
}
$handler_quit_Click={
#TODO: Place custom script here
$form1.Close();
}
$handler_GetFiles_Click={
$textbox1.Text = dir c: | Out-String
}
#----------------------------------------------
# Generated Events
#----------------------------------------------
$Form_StateCorrection_Load=
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
#----------------------------------------------
#
# form1
#
$form1.Controls.Add($textbox1)
$form1.Controls.Add($quit)
$form1.Controls.Add($GetFiles)
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$form1.ClientSize = New-Object System.Drawing.Size(526,412)
$form1.add_Load($FormEvent_Load)
#
# textbox1
#
$textbox1.Multiline = $True
$textbox1.Size = New-Object System.Drawing.Size(479,322)
$textbox1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$textbox1.Name = "textbox1"
$textbox1.Location = New-Object System.Drawing.Point(24,58)
$textbox1.TabIndex = 2
#
# quit
#
$quit.TabIndex = 1
$quit.Name = "quit"
$quit.Size = New-Object System.Drawing.Size(75,23)
$quit.UseVisualStyleBackColor = $True
$quit.Text = "&Quit"
$quit.Location = New-Object System.Drawing.Point(428,13)
$quit.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$quit.add_Click($handler_quit_Click)
#
# GetFiles
#
$GetFiles.TabIndex = 0
$GetFiles.Name = "GetFiles"
$GetFiles.Size = New-Object System.Drawing.Size(75,23)
$GetFiles.UseVisualStyleBackColor = $True
$GetFiles.Text = "Get Files"
$GetFiles.Location = New-Object System.Drawing.Point(32,13)
$GetFiles.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$GetFiles.add_Click($handler_GetFiles_Click)
#endregion Generated Form Code
#----------------------------------------------
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($Form_StateCorrection_Load)
#Show the Form
return $form1.ShowDialog()
} #End Function
#Call OnApplicationLoad to initialize
if(OnApplicationLoad -eq $true)
{
#Create the form
GenerateForm | Out-Null
#Perform cleanup
OnApplicationExit
}
- etherknight
- Posts: 18
- Last visit: Thu Apr 10, 2014 5:56 pm
PrimalForms questions
Wow, that's not even close to what I am seeing (in PowerGUI or any other script editor):
Code: Select all
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 6/4/2010 1:23 PM
# Generated By: mbaker
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$textbox1 = New-Object System.Windows.Forms.TextBox
$quit = New-Object System.Windows.Forms.Button
$GetFiles = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$handler_quit_Click=
{
#TODO: Place custom script here
}
$FormEvent_Load=
{
#TODO: Place custom script here
}
$handler_GetFiles_Click=
{
$textbox1.Text = Get-ChildItem c: | Out-String
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 526
$System_Drawing_Size.Height = 412
$form1.ClientSize = $System_Drawing_Size
$form1.add_Load($FormEvent_Load)
$textbox1.Multiline = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 479
$System_Drawing_Size.Height = 322
$textbox1.Size = $System_Drawing_Size
$textbox1.DataBindings.DefaultDataSourceUpdateMode = 0
$textbox1.Name = "textbox1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 24
$System_Drawing_Point.Y = 58
$textbox1.Location = $System_Drawing_Point
$textbox1.TabIndex = 2
$form1.Controls.Add($textbox1)
$quit.TabIndex = 1
$quit.Name = "quit"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$quit.Size = $System_Drawing_Size
$quit.UseVisualStyleBackColor = $True
$quit.Text = "&Quit"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 428
$System_Drawing_Point.Y = 13
$quit.Location = $System_Drawing_Point
$quit.DataBindings.DefaultDataSourceUpdateMode = 0
$quit.add_Click($handler_quit_Click)
$form1.Controls.Add($quit)
$GetFiles.TabIndex = 0
$GetFiles.Name = "GetFiles"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$GetFiles.Size = $System_Drawing_Size
$GetFiles.UseVisualStyleBackColor = $True
$GetFiles.Text = "Get Files"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 32
$System_Drawing_Point.Y = 13
$GetFiles.Location = $System_Drawing_Point
$GetFiles.DataBindings.DefaultDataSourceUpdateMode = 0
$GetFiles.add_Click($handler_GetFiles_Click)
$form1.Controls.Add($GetFiles)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
PrimalForms questions
Here is what I am doing in PowerShell (sans a GUI interface):
Code: Select all
Copy-Item $Source $Destination
Write-Host ("Following source files copied to " + $Destination + ":")
Get-ChildItem $Server1Destination -Name -Recurse | ForEach-Object {write-host $_}
The project I upload is a primalforms project just extract the file from teh zip and open it in PrimalForms. It will not open or execute in PowerShell or in PrimalScript.
You cannot display a textbox in PrimalScript only a complete form. PrimalFOrms lets you design and test complete forms that can be exported to PrimalScript.
Please read the help and examples for PrimalForms. YOu need to understand more than just PrimalScript coding. You need to understand the fundamental and exteme differences between these products.
Start by using the zip I uploaded and understanding how that works and how to move it to PrimaScript or PrimalGUI.
- etherknight
- Posts: 18
- Last visit: Thu Apr 10, 2014 5:56 pm
- etherknight
- Posts: 18
- Last visit: Thu Apr 10, 2014 5:56 pm
PrimalForms questions
I did. I figured that out at the fourth reply. Then you went off about how PrimalGUI/PowerGUI is not PrimalForms (which was never an issue at all) and seemed to have gotten stuck there. Then you insert PrimalScript into the conversation for some reason (I am still not really sure what that was all about). PowerGUI is just my text editor for the exported PS1 file, nothing more. I could have used NotePad++...doesn't really make any difference.I opened the PFF file in Primalform, exported the Powershell PS1 file, then opened said PowerShell file in a script editor to look at the code. It looked much different that what you posted. But I have since figure that out as well....so thank you for your efforts.etherknight2010-06-04 15:57:34
PrimalForms questions
You named the topic here I didn't. Look at the name of the topic.
You wrote about PrimalGUI I didn't.
You have not been very clear about what you are asking.
This is an exact copy of your original post. You chose the topic.
Topic: PrimalForms questions Posted: 04 Jun 2010 at 14:38
My raw PS script does a copy-item to copy some files and then does a get-childitem to list the files just backed up. I can associate the copy-item with a button. But how do I also associate a text box to show the resulting get-item, since the latter must wait for the former to finish to give results?
The answer I gave is exactly the correct answer to your initial question. Assign the textbox "Text" property with the text you want on the button click event.
$textBox1.Text = Get-ChildItem c: | Out-String
The full project for PrimalForms and an exported full text copy of this is in the ZIP file I posted. Please look closely at this ZIP file and try and understand what it contains.
Here is the ZIP again.
uploads/2491/Demo-TextBox.zip
jvierra2010-06-07 08:54:48
You wrote about PrimalGUI I didn't.
You have not been very clear about what you are asking.
This is an exact copy of your original post. You chose the topic.
Topic: PrimalForms questions Posted: 04 Jun 2010 at 14:38
My raw PS script does a copy-item to copy some files and then does a get-childitem to list the files just backed up. I can associate the copy-item with a button. But how do I also associate a text box to show the resulting get-item, since the latter must wait for the former to finish to give results?
The answer I gave is exactly the correct answer to your initial question. Assign the textbox "Text" property with the text you want on the button click event.
$textBox1.Text = Get-ChildItem c: | Out-String
The full project for PrimalForms and an exported full text copy of this is in the ZIP file I posted. Please look closely at this ZIP file and try and understand what it contains.
Here is the ZIP again.
uploads/2491/Demo-TextBox.zip
jvierra2010-06-07 08:54:48
PrimalForms questions
I will further explain how this wotks so you can try it yourself:
Create a form in PrimalForms or by hand. Add a button and a textbox and change textbox to "multiline". Eport this to a file.
Edit file and add the code I posted into the click event. Run the file in PowerShell:
Here is teh file content and the added line highlighted in red.
I have cut and pasted the code from above into PowerShell V2 and run it. It works exactly as I have described.
Create a form in PrimalForms or by hand. Add a button and a textbox and change textbox to "multiline". Eport this to a file.
Edit file and add the code I posted into the click event. Run the file in PowerShell:
Here is teh file content and the added line highlighted in red.
Code: Select all
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 6/7/2010 11:56 AM
# Generated By: jvierra
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$textBox1 = New-Object System.Windows.Forms.TextBox
$button1 = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick=
{
#TODO: Place custom script here
$textBox1.Text = Get-ChildItem c: | Out-String
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 292
$System_Drawing_Size.Height = 273
$form1.ClientSize = $System_Drawing_Size
$textBox1.Multiline = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 258
$System_Drawing_Size.Height = 192
$textBox1.Size = $System_Drawing_Size
$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$textBox1.Name = "textBox1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 23
$System_Drawing_Point.Y = 63
$textBox1.Location = $System_Drawing_Point
$textBox1.TabIndex = 1
$form1.Controls.Add($textBox1)
$button1.TabIndex = 0
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 138
$System_Drawing_Size.Height = 28
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = "button1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 21
$System_Drawing_Point.Y = 23
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
I have cut and pasted the code from above into PowerShell V2 and run it. It works exactly as I have described.