0

如果使用 if elseif 语句,则无法让我的代码读取多个条件。不知道为什么它从不读取第二个条件。我已经尝试了大约十几种不同的方法。任何帮助,将不胜感激。这是我上次尝试的代码。我已经尝试了多个字符串!在前面等等。仍然不会阅读第二个声明。

if (($attachscreenshot = $false) -and ([bool]$textbox2))
{
    newmail0
}

elseif (($attachscreenshot = $true) -and ([bool]$textbox2))
{
    newmail3
}
    
elseif ($attachscreenshot = $false)
{
    newmail1
}

else
{
    newmail
}
4

3 回答 3

0

正如 Theo 的评论所说,使用-eq等来比较对象。但是,如果你想对一个字符串有条件,那就[string]::IsNullOrEmpty($screenshot)更干净了。要获得条件的反面,请使用-not($screenshot -eq $true)(例如)。

if (($screenshot -eq $false) -and ([bool]$textbox2)) {
    Write-Host "First condition met!"
}
elseif ($screenshot -eq $true) {
    Write-Host "Second condition"
}
else {
    Write-Host "Third condition!"
}
于 2020-09-16T20:06:34.510 回答
0

试试这个,它使逻辑更清晰一点。当然,前提是我理解你的逻辑!

if ($attachscreenshot -eq $false {
  if ([bool]$textbox2) { newmail0 }
  else { newmail1 } 
else {
    #$attachscreenshot is $true
    if ([bool]$textbox2) { newmail3 }
    else { newmail }
}

高温高压

于 2020-09-17T01:01:21.290 回答
0
if ($attachscreenshot -eq $false)
    {
        if (!$filePath)
        {
            stanmail
        }
        else
        {
            upmail
        }
    }
    if ($attachscreenshot -eq $true)
        {
        if (!$filePath)
        {
            screenmail
        }
            else
            {
                upscreenmail
            }       
    }
于 2020-09-18T13:57:35.437 回答