Jump to content

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


taralex
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Developers

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

  • Moderators

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.

Link to comment
Share on other sites

  • Developers

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:

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

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...