2013-03-21 29 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)})