Starter Program to Produce Output

Sep 11, 2009 at 11:12 PM

I want to thank Joel for putting all this together.  It's pretty amazing, except I can't get it to do anything "useful".  Most of the tutorials work for me, but some won't run (I understand there's some versioning issues there), but the ones that do work, just display.  I can't do anything with input or output.  I was trying to write a simple little app to ping a host and report if it's online or not.  I've stripped it right down to base functionality, to just inform the user that the button was clicked.  The program will run, but when I click the button, I get an error.

 

function Test-Boots{
	Boots {
		StackPanel  $(
			TextBlock "Status: " -Name block
			TextBox -Text "127.0.0.1" -Name tbIPAddress -Width 200
			Button "Ping" -On_Click {
				$script:block.Inlines.Add("Success")
			}
		)
	} -Title "Boots Test" 
}

Test-Boots

You cannot call a method on a null-valued expression.
At line:2 char:30
+                 $script:block.Inlines.Add <<<< ("Success")
    + CategoryInfo          : InvalidOperation: (Add:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I tried treating block as an array as per the example:

$script:block[0].Inlines.Add("Success")

But since block is null in the first place, I get a related error:

Cannot index into a null array.
At line:2 char:19
+                 $script:block[ <<<< 0].Inlines.Add("Success")
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

I've also tried using the -OutVariable switch, as it shows up in a couple of the tutorial scripts, but apparently that is deprecated now, as I get an error about an Unknown Dependency Property.

I've got lots of ideas for some great things I could make with Boots, but I seem to be missing some basic information.  Could someone help me out?

 

 

Sep 12, 2009 at 3:44 PM

Have you tried to move the variable to global scope?
$script:block -> $global:block
There are some problems e.g. when using handlers in module. I ended up with all my variables (that are used in handlers) in global scope.

Coordinator
Sep 14, 2009 at 3:50 AM
Edited Sep 14, 2009 at 3:51 AM

thargreaves wrote:
function Test-Boots{
Boots {
StackPanel $(
TextBlock "Status: " -Name block
TextBox -Text "127.0.0.1" -Name tbIPAddress -Width 200
Button "Ping" -On_Click {
$script:block.Inlines.Add("Success")
}
)
} -Title "Boots Test"
}

Test-Boots

 

 

The problem is, you never actually define the $script:block variable.

function Test-Boots{
    Boots {
        StackPanel  $(
            TextBlock "Status: " | tee -var script:block
            TextBox -Text "127.0.0.1" -Name tbIPAddress -Width 200
            Button "Ping" -On_Click {
                $script:block.Inlines.Add("Success")
            }
        )
    } -Title "Boots Test"
}

 

Sep 14, 2009 at 3:41 PM

Thanks!  That did the trick.  I don't feel too dumb because I didn't even know that cmdlet existed :)

 

Coordinator
Sep 14, 2009 at 6:39 PM
Hehe :) instead of Tee-Object, you can just put it in the variable, and then output the variable, like:
$script:block = TextBlock "Status: "; $block 
Of course, it can be on more than one line, but I normally write it just like that (or use tee).