Jump to content
Sign in to follow this  
niubbone

Program Unknown error

Recommended Posts

niubbone

The program is a simple exercise with a GUI with 3 buttons:

1 opens the notepad and types time and date, then closes it.

2 after giving a first choice between 1 sum, 2 subtraction, 3 multiplication, 4 division, the program asks for 2 operators to execute the operation on, in the default windows calculator, then closes it.

3 Same as nr 1, but writes also OS

As u can see here I had various issues (no need to watch it, just if you care)

http://www.autoitscript.com/forum/index.php?showtopic=113437

Here's the source:

#include <GuiConstants.au3>
GUICreate("Multiselezione by NATTA",300,230)
GUISetState(@SW_SHOW)
$bottone1=GUICtrlCreateButton("Opzione 1",10,10)
GUICtrlCreateLabel("Aprire il notepad e scrivere l'ora e la data, poi chiuderlo"&@CRLF&"senza salvarlo",15,40)
$bottone2=GUICtrlCreateButton("Opzione 2",10,80)
GUICtrlCreateLabel("Aprire la calcolatrice e eseguire un calcolo a scelta tra"&@CRLF&"2 operatori con le 4 operazioni di base",15,110)
$bottone3=GUICtrlCreateButton("Opzione 3",10,150)
GUICtrlCreateLabel("Aprire il notepad, scrivere l'ora e la data, il sistema"&@CRLF&"operativo e chiudere senza salvare",15,180)

While 1
    $Scelta = GUIGetMsg()

    If $Scelta = $GUI_EVENT_CLOSE Then ExitLoop

Select
    Case $Scelta=$bottone1
        BlockInput(1)
        Run("notepad.exe")
        WinWaitActive("Senza nome - Blocco note")
        Send("Ora e data "&@CRLF&"{F5}")
        Sleep(1500)
        WinClose("Senza nome - Blocco note")
        WinWaitActive("Blocco note")
        Send("!n")
        BlockInput(0)
    Case $Scelta=$bottone2
        While 1
            While 1
        $operatore2=InputBox("Scegliere","1.Moltiplicazione"&@CRLF&"2.Divisione"&@CRLF&"3.Addizione"&@CRLF&"4.Sottrazione")
             If @error Then ExitLoop
             If Not StringIsInt($operatore2) or $operatore2<1 or $operatore2>4 Then
             Msgbox(0, "Errore", "Non hai inserito un numero intero")
             ContinueLoop
             Endif
                 ExitLoop
             Wend
             While 1
        $operatore1=InputBox("Inserire il primo operatore numerico","Primo Operatore:")
             If @error Then ExitLoop
             If Not StringIsInt($operatore1) Then
             Msgbox(0, "Errore", "Non hai inserito un numero intero")
             ContinueLoop
             Endif
                 ExitLoop
             Wend
             While 1
        $operatore3=InputBox("Inserire il primo operatore numerico","Secondo Operatore:")
             If @error Then ExitLoop
             If Not StringIsInt($operatore3) Then
             Msgbox(0, "Errore", "Non hai inserito un numero intero")
             ContinueLoop
             Endif
                 ExitLoop
             Wend
    BlockInput(1)
    Run("Calc.exe")
    WinWaitActive("Calcolatrice")
    AutoItSetOption("SendKeyDelay",400)
    Switch $operatore2
        Case 1
            Send($operatore1&"*"&$operatore3&"=")
        Case 2
            Send($operatore1&"/"&$operatore3&"=")
        Case 3
            Send($operatore1&"+"&$operatore3&"=")
        Case 4
            Send($operatore1&"-"&$operatore3&"=")
    EndSwitch
    BlockInput(0)
    Sleep(6000)
    WinClose("Calcolatrice")
    ExitLoop
    WEnd
    Case $Scelta=$bottone3
        BlockInput(1)
        Run("notepad.exe")
        WinWaitActive("Senza nome - Blocco note")
        Send("Ora e data"&@CRLF&"{F5}"&@CRLF&"Sistema operativo"&@CRLF&@OSVersion)
        Sleep(1500)
        Winclose("Senza nome - Blocco note")
        WinWaitActive("Blocco note")
        Send("!n")
        BlockInput(0)
EndSelect
WEnd

But at this point it's 2 days that i reached a point i can't understand a bug the code has.

The problem is that for example if I pick choice 3 (Sum) and I input 33 as first operator, and 33 as second operator, the program just types in the windows calculator 333, while the code to send to windows calculator is: Send($operatore1&"+"&$operatore3&"=")

How this is possible? I mean, I could understand bad manipulated variables, but there is a "+" and a "=" sent there as strings, unrelated to any other variable.... The correct keystrokes would be 33+33=, and also if the second operator it's changed into s single 3 it should be 33+3=. Instead, autoit doesn't types even the +...

I thought it was because autoit typed that too fast (also if there is WinWaitActive) so i put in the code AutoItSetOption("SendKeyDelay", 400) to be sure but the result it's the same....

How this is possible??? :idea:

Share this post


Link to post
Share on other sites
goldenix

next time make safe example. I tried this & it blocked my key input I was not able to write anything in notepad.

there is ctrl+alt+del to unblock it but still, ppl may have important unsaved stuff open & who knows !!!!


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites
niubbone

next time make safe example. I tried this & it blocked my key input I was not able to write anything in notepad.

there is ctrl+alt+del to unblock it but still, ppl may have important unsaved stuff open & who knows !!!!

I put BlockInput by purpose. I know also you can unlock it with ctrl+alt+canc. By the way Blockinput was active only while a program is open (notepad or calculator) and not in any other case, and those programs, close themselves automatically, unblocking input. Remove BlockInput Commands from the code if you find it annoying (you already knew it right?).

Any solution for the problem?

Share this post


Link to post
Share on other sites
niubbone

Try using flag ,1 in your send function to allow raw sending of the keys.

read it in the help file

Thanks! It worked! Didn't knew bout it. Sorry!

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  

×