I'm tryng to return $true or $false from a function, and I get an array . If I remove the listBox messages it works as expected. Does anyone know why?
function TestEmptyFields()
{
$empty= $false
$listBox1.Items.Add("Testing fields")
if ($txtPrtName.get_text()-eq "")
{
$listBox1.Items.Add("Empty name")
$empty= $true
}
elseif ($txtPrtIP.get_text() -eq "")
{
$listBox1.Items.Add("Empty Ip")
$empty= $true
}
else
{
$empty= $false
}
$listBox1.Items.Add($txtPrtName.get_text())
$listBox1.Items.Add($txtPrtIP.get_text())
return $empty
}
But it works fine like this:
function TestEmptyFields()
{
if($txtPrtName.get_text()-eq "")
{
return $true
}
elseif ($txtPrtIP.get_text() -eq "")
{
return $true
}
else
{
return $false
}
}
$empty= $truebut directlyreturn $trueinstead? Apart from that it is not that easy to help you debug this if we do not have the parts where$txtPrtName,$txtPrtIPand$listBox1get assigned/declared. I would also recommend you not to process global variables in a function but make them parameters of that function.