usd
価格と価格を取り、eur
いくつかの計算を行う価格設定関数を作成しようとしています。しかし、実行しようとすると次のエラーが発生します。
[System.Object []]に 'op_Division'という名前のメソッドが含まれていないため、メソッドの呼び出しに失敗しました。行:11文字:5
コード:
function Get-Pricing($USD, $EUR) {
[hashtable]$Return = @{}
$USDGBP = [math]::Round((Invoke-RestMethod "https://api.exchangeratesapi.io/latest?base=USD").rates.GBP,2)
$EURGBP = [math]::Round((Invoke-RestMethod "https://api.exchangeratesapi.io/latest?base=EUR").rates.GBP,2)
$USDEx = ($USD * $USDGBP)
$EUREx = ($EUR * $EURGBP)
$ReturnedPrice = ((( $EUREx + 0.25 ) * 0.32 ) + $EUREx )
$PriceIndex = (((( $USDEx / $ReturnedPrice ) * 0.5 ) + (( $EUREx / $ReturnedPrice ) * 1.5 ) + 1 ) / 3)
$PriceCM = (( $ReturnedPrice / $EUREx ) * $PriceIndex )
$Return.PriceIndex = $PriceIndex
$Return.PriceCM = $PriceCM
Return $Return
}
[float]$a = 23.83
[float]$b = 16.11
Write-Host $a -ForegroundColor Red
Write-Host $b -ForegroundColor Red
$Pricing = Get-Pricing($a, $b)
Write-Host "A: "$Pricing.PriceIndex -ForegroundColor Cyan
Write-Host "B: "$Pricing.PriceCM -ForegroundColor Cyan
PowerShellのコマンド呼び出し構文は、Cスタイルの構文を使用する他の言語とわずかに異なります。パラメーター引数を名前でバインドする必要があります。
Get-Pricing -USD $a -EUR $b
または位置によって:
Get-Pricing $a $b
しかし、これを行うと:
Get-Pricing ($a, $b)
\______/
|
# PowerShell just sees a single argument here
...効果的に2項目の配列を$USD
パラメーターに渡し、パラメーターには何も渡しません$EUR
。
パラメーターを明示的に入力すると、ランタイムバインダーは何が問題なのかを通知できます。
PS C:\> function Get-Pricing([float]$USD, [float]$EUR) {
>> # ...
>> }
PS C:\> Get-Pricing($a,$b)
Get-Pricing : Cannot process argument transformation on parameter 'USD'. Cannot convert the "System.Object[]" value of type
"System.Object[]" to type "System.Single".
At line:1 char:12
+ Get-Pricing($a,$b)
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Pricing], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Pricing
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加