Page 1 of 1

Storing Data in a Collection

Posted: Thu Jan 28, 2010 1:29 am
by tconley@semprautilities.com
I have create a varible in my form load that is meant to hold the working data while the script runs but it seems to not get updated correctly what am i doing wrong? It is suppose to be update when the submit button is clicked but It seems to not be holding the data properly.

Code: Select all


$FormEvent_Load={
$ServerName.Focus()
$DataStore = @() 
}

$handler_Submit_Click={
SubmitData
ClearData
}

Function SubmitData {
$Temp ="" | Select-Object Server_Name, Asset_Tag, Serial_Number, Issue
$Temp.Server_Name = $ServerName.Text
$Temp.Asset_Tag = $AssetTag.Text
$Temp.Serial_Number = $SerialNumber.Text
$Temp.Issue = $Issue.Text
$DataStore = $DataStore + $Temp
$Display.Text = $DataStore | ft -auto |Out-String
return $DataStore
}

uploads/16537/ServerRoomDailyCheck.zip

Storing Data in a Collection

Posted: Thu Jan 28, 2010 1:29 am
by tconley@semprautilities.com
I have create a varible in my form load that is meant to hold the working data while the script runs but it seems to not get updated correctly what am i doing wrong? It is suppose to be update when the submit button is clicked but It seems to not be holding the data properly.

Code: Select all


$FormEvent_Load={
$ServerName.Focus()
$DataStore = @() 
}

$handler_Submit_Click={
SubmitData
ClearData
}

Function SubmitData {
$Temp ="" | Select-Object Server_Name, Asset_Tag, Serial_Number, Issue
$Temp.Server_Name = $ServerName.Text
$Temp.Asset_Tag = $AssetTag.Text
$Temp.Serial_Number = $SerialNumber.Text
$Temp.Issue = $Issue.Text
$DataStore = $DataStore + $Temp
$Display.Text = $DataStore | ft -auto |Out-String
return $DataStore
}

uploads/16537/ServerRoomDailyCheck.zip

Storing Data in a Collection

Posted: Thu Jan 28, 2010 11:57 am
by tconley@semprautilities.com
no it actually very common in powershell. You can define all of the different element and then add them to a custom object. I use it all of the time I just haven't used it with a form my regular scripts have no problem.

$temp = "" | select-object element1, element2

then you can add the values to the element

$temp.element1="a"
$temp.element2="b"look at this link
http://get-powershell.com/2008/03/04/cr ... m-objects/

code excerpt

Code: Select all

 $votes = @()
 foreach ($v in Get-Content votes.txt)
     {    
         $vote = "" | Select-Object v1,v2,v3,v4;
         $vote.v1,$vote.v2,$vote.v3,$vote.v4 = $v.split(",")
         $votes = $votes + $vote
     } 

tconley@semprautilities.com2010-01-28 20:02:29

Storing Data in a Collection

Posted: Thu Jan 28, 2010 1:14 pm
by jvierra
Declare $datastore as $global:datastore

It looks like it is going out of scope.

Remember that the form and it's events happen on different threads and cannot see each others data. I thing using a global may fix this. Can't test it right now.
jvierra2010-01-28 21:14:43