Sign in to follow this  
Followers 0
sumit

please help in this code of mine.

3 posts in this topic

Guys this is a part of the code from my program. My problem is that this program as long as $msg = 0. my program pings to 203.81.72.254. That is it keeps on sending pinging packets. I want to reduce the no. of times my program pings. I want that my program should only ping after 100 seconds and still when user selects $msg = $prefsitem etc. it should take required action.

Here is the actual code

CODE
While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

$ping = ping("203.81.72.254",1000)

if $ping then

ContinueLoop

Else

ExitLoop

Endif

Case $msg = $prefsitem

$oIE = _IECreate("about:blank")

WinSetState("about", "", @SW_MAXIMIZE)

Case $msg = $aboutitem

MsgBox(64, "about:", "MPT Broadband Internet Access Client")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

I tried something like this

CODE
While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

sleep(100000) ; this is the additional step

$ping = ping("203.81.72.254",1000)

if $ping then

ContinueLoop

Else

ExitLoop

Endif

Case $msg = $prefsitem

$oIE = _IECreate("about:blank")

WinSetState("about", "", @SW_MAXIMIZE)

Case $msg = $aboutitem

MsgBox(64, "about:", "MPT Broadband Internet Access Client")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

but here the program stops responding to user action for $msg = $prefsitem etc. because it goes to sleep.

Please suggest.

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Perhaps:

Select
    Case $msg = 0
        
        If (TimerDiff($stamp) / 1000) > 100 Then
            $ping = Ping("203.81.72.254", 1000)
            If $ping Then
                $stamp = TimerInit()
                ContinueLoop
            Else
                ExitLoop
            EndIf
        Else
            ContinueLoop
        EndIf
    Case $msg = $prefsitem
        $oIE = _IECreate("about:blank")
        WinSetState("about", "", @SW_MAXIMIZE)
    Case $msg = $aboutitem
        MsgBox(64, "about:", "MPT Broadband Internet Access Client")
    Case $msg = $exititem
        ExitLoop
EndSelect

Store a timestamp after successful ping, don't ping again until 100 seconds have passed.

EDIT: You should probably dim $stamp = 0 at the top of your script

Edited by weaponx

Share this post


Link to post
Share on other sites

Perhaps:

Select
    Case $msg = 0
        
        If (TimerDiff($stamp) / 1000) > 100 Then
            $ping = Ping("203.81.72.254", 1000)
            If $ping Then
                $stamp = TimerInit()
                ContinueLoop
            Else
                ExitLoop
            EndIf
        Else
            ContinueLoop
        EndIf
    Case $msg = $prefsitem
        $oIE = _IECreate("about:blank")
        WinSetState("about", "", @SW_MAXIMIZE)
    Case $msg = $aboutitem
        MsgBox(64, "about:", "MPT Broadband Internet Access Client")
    Case $msg = $exititem
        ExitLoop
EndSelect

Store a timestamp after successful ping, don't ping again until 100 seconds have passed.

EDIT: You should probably dim $stamp = 0 at the top of your script

Thanks a lot buddy. I am really greatful for this

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