Sign in to follow this  
Followers 0
SinoAlpha

SO STRANGE!

4 posts in this topic

#1 ·  Posted (edited)

this is a script i wrote yesterday...but i found a very strange problem...

#include <GUIConstants.au3>

GUICreate("ping - SinoAlpha", 600, 80)
GUISetState()
GUISetBkColor(0xE0FFFF)

GUICtrlCreateLabel("    Scan : 192.168.1.", 10, 15, 145)
GUICtrlCreateLabel("- 192.168.1.", 180, 15, 80)
GUICtrlCreateLabel("%", 525, 70, 25)
$x = GUICtrlCreateLabel("0", 500, 70, 25)
$progressbar1 = GUICtrlCreateProgress(10, 45, 500, 20)
$button = GUICtrlCreateButton("Scan", 520, 45, 70, 20)
$start = GUICtrlCreateInput("36", 150, 12, 25)
$end = GUICtrlCreateInput("255", 250, 12, 25)
$radio1 = GUICtrlCreateRadio("List every IP", 300, 10, 120, 20)
$radio2 = GUICtrlCreateRadio("Only the online host", 420, 10, 150, 20)

GUICtrlSetState($radio1, $GUI_CHECKED)
GUICtrlSetState($button, $GUI_FOCUS)

$file = FileOpen("c:\tmp.txt", 1)

$i = 0
$s = 0
$t = 0
$j = 0

Do
    
    $msg = GUIGetMsg()
    
    If $msg = $button Then
        
        If $j = 0 Then
            $s = GUICtrlRead($start)
            $ss = $s
            $t = GUICtrlRead($end)
            $j = 1
        EndIf
        
        If $i = -1 Then
            FileClose($file)
            Send("#r")
            WinWaitActive("run")
            Send("wordpad.exe - c:\tmp.txt{enter}")
            WinWaitActive("tmp.txt")
            WinWaitClose("tmp.txt")
            FileDelete("c:\tmp.txt")
            Exit
        EndIf
        
        $z = GUICtrlRead($radio1)
        
        GUICtrlSetData($button, "Pause")
        
        For $i = $s To $t
            
            $m = GUIGetMsg()
            
            If $file = -1 Then
                MsgBox(0, "ERROR", "CAN NOT CREATE THE TEMP FILE!")
                Exit
            EndIf
            
            $ip = "192.168.1." & $i
            $result = Ping($ip, 250)
            
            Select
                Case @error = 1
                    $output = "offline!"
                Case @error = 2
                    $output = "unreachable!"
                Case @error = 3
                    $output = "a bad destination!"
                Case @error = 4
                    $output = "Other errors"
                Case Else
            EndSelect
            
            If $result Then
                FileWrite($file, "The status of 192.168.1." & $i & " is " & $result & @CRLF)
            ElseIf $z = 1 Then
                FileWrite($file, "192.168.1." & $i & " is " & $output & @CRLF)
            EndIf
            
            If $m = $button Then;pause
                GUICtrlSetData($button, "Continue")
                $s = $i
                ExitLoop
            Else
                $y = Int((($i - $ss) / ($t - $ss)) * 100)
                GUICtrlSetData($x, $y)
                GUICtrlSetData($progressbar1, $y)
            EndIf
            
        Next
        
        If $i > $t Then;finish
            ;if $i > $t then echo the msgbox...but...dose 36 realy bigger then 255?!!
            MsgBox(0, "error", "if $i > $t then echo the msgbox" & @CRLF & "but , does $i really bigger then $t?" & @CRLF & "$i = " & $i & "  $t = " & $t);...HOW COULD THIS HAPPEN?!!!
            $i = -1
            GUICtrlSetData($button, "RESULT")
        EndIf
        
    EndIf
    
Until $msg = $GUI_EVENT_CLOSE

look at the bottom of the script... there is a "if $i > $t then"...but if you run this script...you can see in the msgbox : $i = 36 $t = 255... so... 36 is bigger then 255?!!

at last , i found that ,if we change 36 to 036, that will be no problem!

i think if the AU3 has just compare the first char of the number...

but...at most of the time, the compare of numbers is correct...

so...this is a bug??

Edited by SinoAlpha

Sino-Alpha

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

I think you have confused Autoit;

try $s and $t=number(guictrlread (etc)), as you are defining $i as a string otherwise (for $i=$s to $t)

Best, Randall

[PS not sure if that's the problem...... good luck!]

Edited by randallc

Share this post


Link to post
Share on other sites

Support mb?

Share this post


Link to post
Share on other sites

Hi,

I think you have confused Autoit;

try $s and $t=number(guictrlread (etc)), as you are defining $i as a string otherwise (for $i=$s to $t)

Best, Randall

[PS not sure if that's the problem...... good luck!]

Ohhhh, i'm so glad to see the result , it really work~~~~ :P

really thanks for your help! the Number is the key!

alpha~~:nuke:


Sino-Alpha

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  
Followers 0