2013-03-21 68 views
1

我需要下面的帮助;需要将文本框中的值转换为整数

这是CMD-让

Set-Datastore [-Datastore] <Datastore[]> [[-Name] <String>] [-CongestionThresholdMillisecond <Int32>] 

我将与 '-CongestionThresholdMillisecond' 参数一起使用一个文本框。我已经厌倦了不同的方式,但要么不能将字符串转换为int或者值小于5(不允许)。

$textBox417.Size = New-Object Drawing.Size (80,30) 
$textBox417.Location = New-Object System.Drawing.Size (100,140) 
$int = $textBox417.Value.ToString() 
$button = New-Object System.Windows.Forms.Button 
$button.Size = New-Object Drawing.Size (110,30) 
$button.Location = New-Object System.Drawing.Size (50,180) 
$button.add_click({Set-Datastore -Name $label438.Text -CongestionThresholdMillisecond $int}) 

非常感谢!

回答

1

看起来你指的是不存在的属性。尝试改变Value属性Text属性

$int = $textBox417.Text 
+0

我第一次尝试,它似乎传递0。设置的数据存储:无法验证的参数变量“CongestionThresholdMillisecond”。 0参数小于允许的最小值 的范围5.提供大于5的参数,然后再次尝试该命令。 – Shamza 2013-03-21 17:16:29

+0

在将它传递给命令之前打印$ int,是否获得与文本框中相同的值? – 2013-03-21 17:22:29

+0

如上所述得到'0'。即使尝试'$ int = $ textBox417.value -as [int]'仍然会得到0. – Shamza 2013-03-21 17:34:52

0

如果你能得到正确的数量从文本框很容易串更改为int。

$string = '123' 
$string.gettype() 
([int]$string).gettype() 

那么,为什么不能这样做

... 
$button.add_click({Set-Datastore -Name $label438.Text -CongestionThresholdMillisecond ([int]$int)})