Jump to content
Sign in to follow this  
taralex

I'm going crazy, 500 <> 500, is this possible?

Recommended Posts

taralex

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 = 1

EndIf

The problem is, I see 500 in the message box, but then, the "ChannelValue is something else" is also displayed :mellow:

How come that StdoutRead function returns a value that I couldn't compare?

Share this post


Link to post
Share on other sites
SmOke_N

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 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.

Share this post


Link to post
Share on other sites
taralex

Jos, thanx a lot, converting it to the numeric representation helped! I thought AutoIt took care about types conversion automatically...

Share this post


Link to post
Share on other sites
Jos

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 :mellow:


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
SmOke_N

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 :mellow:

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×