Sign in to follow this  
Followers 0
TheGeneral

Problem with a function

8 posts in this topic

#1 ·  Posted (edited)

Func Check()
    While 1
        AdlibDisable()
        $msg = GUIGetMsg()
        Select
            
            Case $msg = $AddNick
                $value = GUICtrlRead($input1)
                GuiListAdd($value)
            Case $msg = $button2
                $dado = GUICtrlRead($input2)
                TopicoNicks($dado)
            Case $msg = $button3
                Call("MyFunc2")
            Case $msg = $button4
                $string = _GUICtrlListBox_GetCurSel($List1)
                _GUICtrlListBox_DeleteString($List1, $string)
            Case $msg = $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
        EndSelect
    WEnd
EndFunc;==>Check
Func MyFunc2()
    AdlibEnable("Check2", 50)
    $username = _GUICtrlListBox_GetText($List1, 0)
    If $username == 0 Then
        Call("Check")
    EndIf
    _GUICtrlListBox_DeleteString($List1, 0)
    $username = RegularExpression($username)
    $Contador = StringLen($username)
    $username = _StringToHex($username)
    $subject = GUICtrlRead($input3)
    $subject = RegularExpression($subject)
    $Contador2 = StringLen($subject)
    $subject = _StringToHex($subject)
    $message = GUICtrlRead($edit1)
    $message = RegularExpression($message)
    $Contador3 = StringLen($message)
    $message = _StringToHex($message)
    $hex = "504f5354202f707269766d73672e70687020485454502f312e310d0a557365722d4167656e743a204d6f7a696c6c612f



352e30202857696e646f77733b20553b2057696e646f7773204e5420362e303b20656e2d555329204170706c655765624b69



742f3532352e313920284b48544d4c2c206c696b65204765636b6f29204368726f6d652f302e332e3135342e392053616661



72692f3532352e31390d0a526566657265723a20687474703a2f2f666f72756d2e6a6f676f732e756f6c2e636f6d2e62722f



707269766d73672e7068703f6d6f64653d706f73740d0a43616368652d436f6e74726f6c3a206d61782d6167653d300d0a43



6f6e74656e742d547970653a206170706c69636174696f6e2f782d7777772d666f726d2d75726c656e636f6465640d0a4163



636570743a20746578742f786d6c2c6170706c69636174696f6e2f786d6c2c6170706c69636174696f6e2f7868746d6c2b78



6d6c2c746578742f68746d6c3b713d302e392c746578742f706c61696e3b713d302e382c696d6167652f706e672c2a2f2a3b



713d302e350d0a436f6f6b69653a20" & $Cookies & "0d0a4163636570742d4c616e67756167653a2070742d42522c70742c656e2d55532c656e0d0a4163636570742d436861



727365743a2049534f2d383835392d312c2a2c7574662d380d0a4163636570742d456e636f64696e673a20677a69702c6465



666c6174652c627a6970320d0a486f73743a20666f72756d2e6a6f676f732e756f6c2e636f6d2e62720d0a436f6e74656e74



2d4c656e6774683a203236320d0a436f6e6e656374696f6e3a204b6565702d416c6976650d0a0d0a757365726e616d653d" & $username & "26757365727375626d69743d456e636f6e747261722b75737525453172696f267375626a6563743d" & $subject & "266164646262636f646531383d2532333434343434342b2b2b2b266164646262636f646532303d31322668656c70626f



783d466f6e74652533412b25354273697a65253344782d736d616c6c253544746578746f2b70657175656e6f253542253246



73697a65253544266d6573736167653d" & $message & "26666f6c6465723d696e626f78266d6f64653d706f737426706f73743d454e56494152"
    $hex = _HexToString($hex)
    $numerofinal = 198 + $Contador + $Contador2 + $Contador3
    $hex = StringRegExpReplace($hex, "262", $numerofinal)
    TCPStartup()
    $ConnectedSocket = TCPConnect("200.98.249.130", 80)
    TCPSend($ConnectedSocket, $hex)
    While $recieved3 = ""
        $recieved3 = TCPRecv($ConnectedSocket, 100000)
        If $recieved3 <> "" Then
            FileWrite("information.txt", $recieved3)
            $recieve3 = ""
            TCPShutdown()
        EndIf
    WEnd
    $mensagem = GUICtrlCreateLabel("Mensagem Enviada", 650, 450)
    $i = TimerInit()
    While $diff < 58000
        GUICtrlDelete($contagem)
        $diff = TimerDiff($i)
        $time = 60000 - $diff
        $time = $time / 1000
        $time = Int($time)
        $contagem = GUICtrlCreateLabel($time, 40, 450)
        If $time = 57 Then
            GUICtrlDelete($mensagem)
        EndIf
        Sleep(1000)
    WEnd
    GUICtrlDelete($contagem)
    Call("MyFunc2")
EndFunc;==>MyFunc2

The whole script is attached.

The problem is: the first time $button3 is clicked everything goes ok. The function loops, and then Call Check again because there're no more usernames. But in the second time I click on $button3 it executes the function Myfunc2 until this line:

Func MyFunc2()
    AdlibEnable("Check2", 50)
    $username = _GUICtrlListBox_GetText($List1, 0)
    If $username == 0 Then
        Call("Check")
    EndIf
    _GUICtrlListBox_DeleteString($List1, 0)

And then goes to the beginning of MyFunc2, it calls the function check because it deleted the first string of the listbox , and I lose the action it should had done.

test.au3

Edited by TheGeneral

Share this post


Link to post
Share on other sites



nothing stands out, I have experienced funny things before. I always find putting in scaffolding helps see whats really going on.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I find out the problem is the timer:

$i = TimerInit()
    While $diff < 58000
        GUICtrlDelete($contagem)
        $diff = TimerDiff($i)
        $time = 60000 - $diff
        $time = $time / 1000
        $time = Int($time)
        $contagem = GUICtrlCreateLabel($time, 40, 450)
        If $time = 57 Then
            GUICtrlDelete($mensagem)
        EndIf
        Sleep(1000)
    WEnd
    GUICtrlDelete($contagem)

What's wrong with that?

Share this post


Link to post
Share on other sites

u know that it is a recursive function?

Just below GUICtrlDelete($contagem) you have Call("MyFunc2") so once button three is pressed, it can never leave the function.

Once in that function, it will never leave it, thus going back to _Main().


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

u know that it is a recursive function?

Just below GUICtrlDelete($contagem) you have Call("MyFunc2") so once button three is pressed, it can never leave the function.

Once in that function, it will never leave it, thus going back to _Main().

Did you see the

If $username == 0 Then

Call ("Check")

EndIf

?

Share this post


Link to post
Share on other sites

Yeah, but once check is finished, its going to go back to MyFunc2 unless it hits that Exit command.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Yeah, but once check is finished, its going to go back to MyFunc2 unless it hits that Exit command.

No, Adlib calls a function every 50ms, that have the option:

Case $GUI_EVENT_CLOSE

Exit

Btw, i solved the problem, just declared $time and $diff = "" before the end of the function

Share this post


Link to post
Share on other sites

cool. Sorry, didn't really understand what the program is doing, I was just following the logic.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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