0

Can any one help me what is wrong in the below program. when i give 18,18 also this is giving as greater

function Is-Numeric ($Value) {
    return $Value -match "^[\d\.]+$"
}

function comparevalues ($val1,$val2)  {

    Write-Host $val1,$val2
    if (Is-Numeric($val1) -AND Is-Numeric($val2)) {
        Write-Host $val1,$val2
        if ($val1 -eq $val2) {
           return "equal"
        } ElseIF ($val1 -gt $val2) {
            return "greater"
        } Else {
            return "lesser"
       }
    } Else {
        return "notnumeric"
    }
}


$val = comparevalues(18,18)
Write-Host $val

output of the program is as

18 18
18 18
greater

Please help me hwy the output is wrong.

surendra
  • 551
  • 3
  • 13
  • 27
  • 2
    you are sending in an ARRAY, not two items. remove the parens AND the comma and it works. [*grin*] `comparevalues 18 18` is the correct way to call the function with TWO values. it's an embarrassingly easy [and common] error. – Lee_Dailey Oct 29 '18 at 18:03
  • Thanks Lee_Dailey...It worked... – surendra Oct 29 '18 at 18:19
  • you are most welcome! i've made that same error many times - and it took me 3 read-thrus before it realized what was wrong. [*grin*] – Lee_Dailey Oct 29 '18 at 18:23

0 Answers0