String 将字符串转换为整数进行减法运算
这是我的密码String 将字符串转换为整数进行减法运算,string,powershell,int,String,Powershell,Int,这是我的密码 $fourCount = 0 $rowCount = 0 foreach($row in $ResultsTable){ if ($row.'RowType' -eq 6) { if ($fourCount -gt 0) { #Sort-Object {$row.'CheckDate'} - descending $remainAmount = $currentAmount - $checkAmount $ResultsTable.R
$fourCount = 0
$rowCount = 0
foreach($row in $ResultsTable){
if ($row.'RowType' -eq 6) {
if ($fourCount -gt 0) {
#Sort-Object {$row.'CheckDate'} - descending
$remainAmount = $currentAmount - $checkAmount
$ResultsTable.Rows[$rowCount - 1].'Final' = $remainAmount
$currentAmount = @()
$fourCount = 0
$remainAmount = 0
}
$checkAmount = [int]$row.'amount'
$rowCount = $rowCount + 1
} elseif ($row.'RowType' -eq 4) {
if($row.'current'.Length -eq $NULL) {
Continue
} else {
$currentAmount += [int]$row.'current'
$rowCount = $rowCount + 1
$fourCount++
}
} else {
Continue
}
}
我运行代码时遇到的问题是
方法调用失败,因为[System.Object[]]不包含
名为“op_减法”的方法
$remainAmount=$currentAmount-在第9行,您正在将$currentAmount初始化为空数组:
$currentAmount = @()
然后,您将[int]项累积到该数组中:
$currentAmount += [int]$row.'current'
$remainAmount = $currentAmount - $checkAmount
所以你得到的是一个[int]数组
最后,您尝试使用该数组执行减法运算:
$currentAmount += [int]$row.'current'
$remainAmount = $currentAmount - $checkAmount
但它失败了
错误消息中的[Type[]]语法表明它是一个数组,您不能对它执行减法运算。我明白了。。。。这解决了我的问题。刚刚将[0]添加到它运行的末尾。再次感谢你!