Jump to content

Recommended Posts

Hello everyone, i'm not so expert in autoit, but in these day, I spent some hours to create a script with imagesearch.. I have no syntax error and no logical error (cause the script has worked for some hours..).

So i tried to upgrade it and add another function, and there, the script started to give me:

if $result[0]="0" then return 0
if $result^ ERROR

So i surfed in the threads and i found the fix for it.

ANYWAY, the error was just for the last function, the other one was working fine.. just the last one (tested in a new file) gives that error, even if they're using the same library (ImageSearch.au3)

If i try to test the last one in the main project, no error but just don't work that function..

In that moment i fixed the $result error with:

If (IsArray($result) = False) Then Return 0

But now, all the functions are not working.. i tried adding a msgbox to see if the image was found or not, but it always says not found..

What could be the problem?
Anyway thanks for the helping and sorry for my bad english

Link to post
Share on other sites
5 hours ago, Earthshine said:

Show all code for help. What you have showed us is nothing and all we can do is guess

Of course

#include <ImageSearch.au3>
#include <GDIPlus.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

HotKeySet ("p", "quitme")

While 1

    $fileA = "C:\Users\fabry\Desktop\ImmaginiScript\Ricerca.png"


    _GDIPlus_Startup()

    $hImageA =_GDIPlus_ImageLoadFromFile($fileA) ;this is the file to search
    $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)

    $x = 0
    $y = 0

    sleep(150)
    $result = _ImageSearch($hBitmapA, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then

        ;~ dostuff
    
        endif

    $fileB = "C:\Users\fabry\Desktop\ImmaginiScript\Inizio.png"


    _GDIPlus_Startup()

    $hImageB =_GDIPlus_ImageLoadFromFile($fileB) ;this is the file to search
    $hBitmapB = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageB)

    $x = 0
    $y = 0

    ;~  sleep(100)

    $result = _ImageSearch($hBitmapB, 1, $x, $y, 100, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
    
        EndIf
    $fileC = "C:\Users\fabry\Desktop\ImmaginiScript\Preparazione.png"


    _GDIPlus_Startup()

    $hImageC =_GDIPlus_ImageLoadFromFile($fileC) ;this is the file to search
    $hBitmapC = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageC)

    $x = 0
    $y = 0
    sleep(300)
    $result = _ImageSearch($hBitmapC, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        endif
    $fileD = "C:\Users\fabry\Desktop\ImmaginiScript\SetPreimpostati.png"

    _GDIPlus_Startup()

    $hImageD =_GDIPlus_ImageLoadFromFile($fileD) ;this is the file to search
    $hBitmapD = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageD)

    $x = 0
    $y = 0
    sleep(550)
    $result = _ImageSearchArea($hBitmapD, 1, 1220, 875, 1440, 984, $x, $y, 70, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        EndIf
    $fileE = "C:\Users\fabry\Desktop\ImmaginiScript\Set1.png"

    _GDIPlus_Startup()

    $hImageE =_GDIPlus_ImageLoadFromFile($fileE) ;this is the file to search
    $hBitmapE = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageE)

    $x = 0
    $y = 0
    sleep(200)
    $result = _ImageSearch($hBitmapE, 1, $x, $y, 10, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        $fileCurv = "C:\Users\fabry\Desktop\ImmaginiScript\Curvatura.png"

        _GDIPlus_Startup()

        $hImageCurv =_GDIPlus_ImageLoadFromFile($fileCurv) ;this is the file to search
        $hBitmapCurv = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageCurv)

        $x = 0
        $y = 0

        $result = _ImageSearchArea($hBitmapCurv, 1, 824, 463, 1781, 953, $x, $y, 50, 0) ;Zero will search against your active screen
            If $result > 0 Then
            call ("Curvatura")
        ;~  Sleep (100)
            EndIf

        Call ("Distrutto")
        
    else

    $fileF = "C:\Users\fabry\Desktop\ImmaginiScript\Set2.png"

    _GDIPlus_Startup()

    $hImageF =_GDIPlus_ImageLoadFromFile($fileF) ;this is the file to search
    $hBitmapF = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageF)

    $x = 0
    $y = 0
    sleep(200)
    $result = _ImageSearch($hBitmapF, 1, $x, $y, 20, 0) ;Zero will search against your active screen
    If $result > 0 Then
    
    ;~  dostuff
    
    $fileCurv = "C:\Users\fabry\Desktop\ImmaginiScript\Fuoco.png"

    _GDIPlus_Startup()

    $hImageCurv =_GDIPlus_ImageLoadFromFile($fileCurv) ;this is the file to search
    $hBitmapCurv = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageCurv)

    $x = 0
    $y = 0

    $result = _ImageSearchArea($hBitmapCurv, 1, 824, 463, 1781, 953, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        call ("Curvatura")
    ;~  Sleep (100)
        EndIf

        sleep(100)
        ;~ call("Distrutto")
    EndIf

    _GDIPlus_ImageDispose($hImageCurv)
    _GDIPlus_Shutdown()
    
    
    _GDIPlus_ImageDispose($hImageF)
    _GDIPlus_Shutdown()
    EndIf

    _GDIPlus_ImageDispose($hImageE)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageD)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageC)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageB)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageA)
    _GDIPlus_Shutdown()

WEnd


Func Curvatura()

    ;~  dostuff

EndFunc

Func Distrutto()

    $fileH = "C:\Users\fabry\Desktop\ImmaginiScript\Distrutto.png"


    _GDIPlus_Startup()

    $hImageH =_GDIPlus_ImageLoadFromFile($fileH) ;this is the file to search
    $hBitmapH = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageH)

    $x = 0
    $y = 0

    sleep(150)
    $result = _ImageSearch($hBitmapH, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~ dostuff
        endif

    _GDIPlus_ImageDispose($hImageH)
    _GDIPlus_Shutdown()
endFunc

Func quitme()
    Exit
EndFunc

Some sleep/comment lines are written cause i was doing some tests..

Probably the code is not indented perfectly, i'm sorry for this..

I've slimmed down a little the code, by eliminating all the action inside the if, so it's easy to read i think.. anyway inside them there's just MouseMove, MouseClick, Sleep and Send commands

 

Anyway, the problems i said in the first message started with Func Distrutto().

Now, when i start the code in the SciTE the console says

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\fabry\Desktop\ImmaginiScript\Script.au3" /UserParams    
+>15:06:28 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000410  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0410)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\fabry\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\fabry\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\fabry\Desktop\ImmaginiScript\Script.au3
+>15:06:28 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\fabry\Desktop\ImmaginiScript\Script.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>15:07:03 AutoIt3.exe ended.rc:0
+>15:07:03 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 35.08

And even is the code is running i can modify it.

(i stopped the code with Hotkey)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By WhaleJesus
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <file.au3> ; Create Data Folder if it doesn't exist yet If FileExists(@ScriptDir & "\Data") Then Else ShellExecute(@ScriptDir) DirCreate(@ScriptDir & "\Data") EndIf ; Playlist Name & location input Global $playlistnameinput = InputBox("Playlist", "Enter The playlist name", _ "Name") Global $playlistlocationinput = InputBox("Location", "Specify where you would like the playlist folder to be stored", @ScriptDir & "\Playlists\" & $playlistnameinput) ; Create file in Data folder and other vars Global $sDataFile = @ScriptDir & "\Data\Data.txt" Global $DataHandle = FileOpen($sDataFile, 1) Global $DataFileLine = FileReadLine($sDataFile, 1) FileClose($DataFileLine) MsgBox(0, "", $DataFileLine, 10) ; Prove it exists If FileExists($sDataFile) Then _FileWriteToLine($DataHandle, $DataFileLine, $playlistnameinput, True, True) $DataFileLine += 1 _FileWriteToLine($DataHandle, 1, $DataFileLine, True) Else MsgBox($MB_SYSTEMMODAL, "Error", "File " & $sDataFile & "Does not exist") EndIf Global $sPDataFile = @ScriptDir & "\Data\" & $playlistnameinput & "_Data.txt" Global $PDataHandle = FileOpen($sPDataFile, 1) If FileExists($sPDataFile) Then _FileWriteToLine($PDataHandle, 1, $playlistnameinput, True, True) _FileWriteToLine($PDataHandle, 2, $playlistlocationinput, True, True) Else MsgBox($MB_SYSTEMMODAL, "Error", "File " & $sPDataFile & "Does not exist") EndIf _FileWriteToLine stopped working and i don't know what it is in my code that's causing this, please help
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
    • By DannyJ
      If I run this code, it works perfectly
      $CmdPid = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit " & 'Get-ChildItem',@DesktopDir, @SW_SHOW) But this code
      $CmdPid = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit " & 'Get-RDUserSession',@DesktopDir, @SW_SHOW) I get this error:
      Get-RDUserSession : The term 'Get-RDUserSession' is not recognized as the name of a cmdlet, function, script file, or o perable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga in. If I try run the command Get-RDUserSession  in normal PowerShell (started from windows start menu) the command works perfectly.
      But If I run with AutoIt I get the above mentioned error .
      Any ideas?
    • By Automania
      Hi all,
      I haven't used AutoIt in more than 10 years and I am sure a lot has improved since that long time. I hope you can give me some suggestions on my approach.
      Task: I need to extract user data (for around 1700 users) from a website tool. That tool shows an output in a table on the website. However, no export feature is available and I need the data in an Excel file, such as:
      username, serial number (of a laptop), ID number (of laptop) and some more
       
      With my knowledge from 2009 I would do this:
      1) use _IEextract with each username in the url to get the whole source code of the website with the user's data summary
      2) Work with lots of regexpressions to extract each data piece, save them into variables/array
      3) Write variable values into an Excel file
      4) rinse repeat 1700 times
       
      The relevant line for step 3 looks like this:
      <td class="resultcell"><span class="new">2021-03-23 11:05:00</span></td><td class="resultcell">Hostname-1234</td><td class="resultcell"><a href="?&Search=Search&result=summarized%20history&field=serial%20numbers&criteria=123456">123456</a></td><td class="resultcell">0987654/td><td class="resultcell"><a href="?&Search=Search&result=summarized%20history&field=usernames&criteria=myusername">myusername</a> and so on.. so here it would be Hostname-1234, 0987654 and myusername that I would need to extract.

      Although this may work it does not appear very efficient and would take a while. So I am happy for an alternate approach. Preferably, without using additional exe binary files due to company policies besides AutoIt itself.
    • By SEuBo
      Hi!
      I am just getting started with C and C++. I have created a pretty simple C code which is calling a dll function.
      When I compile and run, I get the appropriate Output. So it works fine.

       
      Now I would want to transform that to AutoIt. -> I would like to call the "RfcOpenConnection" function from AutoIt - but whatever I try with DLLCall, I can not get it to work. 
      Can someone point me in the right direction? DLL, C Sourcecode and compiled exe are attached too large to be attached, so they're uploaded here: 
      https://drive.google.com/file/d/12CUSsISl0mojiMCNxKjps1Sdoox3JlCX/view?usp=sharing
       
      Thanks a bunch!
×
×
  • Create New...