taralex Posted November 1, 2008 Share Posted November 1, 2008 This is total b*shit, guys, tell me, where I suck.I'm using a console application to read some value and return it to me. I get the correct value ok, at least when displayed in a message box, but then, when I use it in an IF statement (or any other comparison for that matter), I get some crap, have a look, here's the script:$id = Run(@ComSpec & " /c C:\temp\GetValue.exe ChannelName", "C:\temp", @SW_HIDE, 2)While 1 $line = StdoutRead($id) If @error Then ExitLoop If $line <> "" then $ChannelValue = $line sleep(50)Wend MsgBox (0, "", $ChannelValue)If $ChannelValue <> 500 Then MsgBox (0, "", "ChannelValue is something else") $ChannelValue = 1EndIfThe problem is, I see 500 in the message box, but then, the "ChannelValue is something else" is also displayed How come that StdoutRead function returns a value that I couldn't compare? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 1, 2008 Developers Share Posted November 1, 2008 Have you checked the exact content of $ChannelValue? Try testing with Number($ChannelValue) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 1, 2008 Moderators Share Posted November 1, 2008 (edited) 1st, even if it has a string value of 500 it's still a string. If (Number($ChannelValue) <> 500) Then would be more like it. $id = Run(@ComSpec & " /c C:\temp\GetValue.exe ChannelName", "C:\temp", @SW_HIDE, 2) While 1 $line = StdoutRead($id) If @error Then ExitLoop If $line <> "" then $ChannelValue = $line sleep(50) Wend ; Strip any line feeds/carriage returns from end of string. $ChannelValue = StringRegExpReplace($ChannelValue, "[\r\n]+\z", "") MsgBox (0, "", Number($ChannelValue)) If (Number($ChannelValue) <> 500) Then MsgBox (0, "", "ChannelValue is something else") $ChannelValue = 1 EndIf Edit: There's a good chance that StdoutRead() may be adding a CRLF or CR or LF to the end of your string btw. Adding a way to strip that in the code above. Edited November 1, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
taralex Posted November 1, 2008 Author Share Posted November 1, 2008 Jos, thanx a lot, converting it to the numeric representation helped! I thought AutoIt took care about types conversion automatically... Link to comment Share on other sites More sharing options...
Developers Jos Posted November 1, 2008 Developers Share Posted November 1, 2008 Jos, thanx a lot, converting it to the numeric representation helped! I thought AutoIt took care about types conversion automatically...That depends on the exact content of the string ... add any Space/Tab/CRLF or other ïnvisible character and it obviously won't work anymore.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 1, 2008 Moderators Share Posted November 1, 2008 That depends on the exact content of the string ... add any Space/Tab/CRLF or other ïnvisible character and it obviously won't work anymore.Jos Man, I'm losing it!!! I didn't even see your post Jos. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 1, 2008 Developers Share Posted November 1, 2008 Man, I'm losing it!!! I didn't even see your post Jos.Did that happy before today ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now