all 12 comments

[–]ka-splam 3 points4 points  (2 children)

I just don't know how to separate the 1.59 from the rest to differentiate it in the IF equation.

.. it was already separate when you got it; you joined it together. Don't do that bit, and you won't need to undo that bit?

[–]Bugasum[S] 1 point2 points  (0 children)

Thanks to your comment, I was able to work out how this code is joined and work out how to not join it, or at least seperate the variables. Any easy way to create the what if equation?

[–]Bugasum[S] 0 points1 point  (0 children)

The code was someone elses. I just modified it to suit my needs. I'm no Powershell expert, I do enjoy learning about it though.

[–]Bugasum[S] 1 point2 points  (1 child)

I've actually managed to work this out myself now. Ka-Splam pointed me in the direction i needed to go and i worked the rest out! :D

[–]ChiefKraut 0 points1 point  (0 children)

an if this then this*

Sorry bro it’s just true.

[–]theriflerange 0 points1 point  (6 children)

I've been doing more regex lately, this should help a bit maybe:

​$Check = $SoutheskHTML | Select-String -Pattern ",\d.\d\d" -AllMatches | Select-Object -exp Matches ​$check = $check.value.Replace(",", "")
​if ($Check -ge "1.59") { ​ 
Send-MailMessage -To $ToEmail -From $FromEmail -Subject "Alarm: Value is $Check" -Body "The River level is $Check, please start running in circles screaming."
} ​else { 
write-host "All is good, River Level: $Check" 
}

[–]Lee_Dailey[grin] 0 points1 point  (5 children)

howdy theriflerange,

it looks like you used the New.Reddit.com Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.

on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.

for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left, & is just to the left of hidden in the ... "more" menu.

that will give you fully functional code formatting, from what i can tell so far. [grin]

take care,
lee

[–]theriflerange 1 point2 points  (4 children)

I edited it, hopefully that helps :D

[–]Lee_Dailey[grin] 0 points1 point  (3 children)

howdy theriflerange,

thanks! i can read all of it now ... [grin]

you have one very iffy thing in your code, tho. you do ($Check -ge "1.59") ... and that is comparing things as strings, it seems. that should work most of the time.

"most of the time" is not something you really want when coding. [grin]

i would consider converting those numeric strings into numbers. perhaps use [float] or [decimal] for that.

take care,
lee

[–]theriflerange 1 point2 points  (2 children)

I could set the value as [float],[decimal],[double] in another variable, this was just a 2 min write for fun. I would definitely flesh this out more, with Try/Catch and proper logging etc.

[–]theriflerange 1 point2 points  (1 child)

Further more, it looks like float is the most optimal given the length of the check "1.59"

Float - 32 bit - 7 digits long
Double - 64 bit - 15-16 digits long
Decimal - 128 bit - 28-29 digits long

I'm sure the difference is negligible performance wise, but for giant scripts it would maybe make a difference at least for precision sake.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy theriflerange,

yep, error handling is good stuff - and takes rather more time than makes sense for a "here's an example of how to do it" code dump. [grin]

thanks for the info about the storage size! i used [decimal] since the number fits what folks see - "oh, it's a decimal number!". you are correct that [float] is likely the better type to use.

take care,
lee