Sign in to follow this  
Followers 0
Jcreator

this script keeps having contradicting loop

17 posts in this topic

i used this code to take names for a text file called data and put the info of the image and it location from the data file into the gui interface but it only detect the lines with the info and it do not show the images . here is the code 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiComboBox.au3>
#include <GuiTab.au3>
#include <file.au3>
#include <array.au3>




_Main()


Func _Main()


Local $idTab1

$Form1 = GUICreate("Form1", 500, 334, 240, 182)
$Group1 = GUICtrlCreateGroup("Group1", 20, 12, 249, 314)
$idButton6 = GUICtrlCreateButton("Info", 50, 270, 185, 49)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

Global $fileMPA = "C:\T-in\MPA\data.txt"

FileOpen($fileMPA, 0)

   Global $line1 = FileReadLine($fileMPA , 1)

$imp = 0


$idTab1 = GUICtrlCreateTab(300, -3, 180, 330)
GUICtrlCreateTabItem("imglist1")
GUICtrlSetTip(-1, '#Region TAB1')
GUICtrlSetTip(-1, '#Region LIST')
Local $imglist1 = GUICtrlCreateList("", 307, 26, 164, 304)


$cline =_FileCountLines($fileMPA)

 While  $imp < $cline


$line2 = FileReadLine($fileMPA , $imp + 2)
 $imp = $imp + 7

if $line2 = ""  then

    ExitLoop

   else

 GUICtrlSetData(-1, ""& $line2 &"", "")

 endif

WEnd

GUICtrlCreateTabItem("imagelist2")
GUICtrlSetTip(-1, '#Region TAB2')
GUICtrlCreateTabItem("imagelist3")
GUICtrlSetTip(-1, '#Region TAB3')

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
            Global $whatnow = GUICtrlRead($imglist1)
Case $Msg = $idButton6

            $imp2 = 0
             While  $imp2 < 30


$line2 = FileReadLine($fileMPA ,$imp2 + 2)
$line3 = FileReadLine($fileMPA , $imp2 + 3)
$line7 = FileReadLine($fileMPA , 7)

 $imp2 = $imp2 + 7

if $line2 = ""  then  ExitLoop
            If GUICtrlRead($imglist1) = ""& $line2 &""  Then MsgBox($MB_SYSTEMMODAL, "img info" , $line3)
               WEnd
            EndSelect
$imp2 = 0
             While  $imp2 < 30


$line2 = FileReadLine($fileMPA ,$imp2 + 2)
$line3 = FileReadLine($fileMPA , $imp2 + 3)
$line7 = FileReadLine($fileMPA , 7)

 $imp2 = $imp2 + 7

    Select
Case GUICtrlRead($imglist1) = ""& $line2 &""
if $line2 = "" then ExitLoop
    $Pic1 = GUICtrlCreatePic(""& $line7 &"", 185, 28, 233, 230)

If GUICtrlRead($imglist1) then  ExitLoop
EndSelect
WEnd

    WEnd

 EndFunc   ;==>_Main

the data.txt file content is 

Hibiscus
Hibiscus is a hardy perennial which grows in variety of colors, sizes and fragrances. Actually they are tropical flowers which require ample sunlight and moisture to grow well. These flowers start blooming in late spring and continuously bloom through July and August.



C:\T-in\IMG\2.jpg

Lilies
There are different types of lily flowers which bloom in August including water lilies, tiger lilies and gold band lilies. Tiger lilies generate orange flowers having black spots. This lily blooms in delayed July and beginning of August. Gold band lily produce exotic white blooms. All varieties of lilies need enough space to grow and protection from summer sun.



C:\T-in\IMG\1.jpg

Turtlehead
Growing in humid areas, turtleheads are small flowers which bloom from July to September. They mostly produce flowers of white and pink color.



C:\T-in\IMG\3.jpg

Hydrangea
These are ever green bushes which produce flowers in different colors including white, purple, blue and pink. They are easy to grow bushes and can grow 3 to 10 feet tall. They require morning sun to grow but they should be protected from noon and afternoon sun.



C:\T-in\IMG\4.jpg

Dahlias
August proves to be the peak blooming season for dahlias. Dahlias come in colors like white, orange, yellow, red and purple. They can tolerate all types of soil and require full sun to grow.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I suggest using a 2 dimension Array holding the data from the textfile. Creeating array can be done also with regex, the rest of script is just a demo for easy solving with array:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <StaticConstants.au3>

$sFile = FileRead('flowers.txt')    ;change to your path
$aFlowers = StringSplit($sFile, '.jpg', 1)
If IsArray($aFlowers) Then
    For $j = $aFlowers[0] To 1 Step -1
        If StringStripWS($aFlowers[$j], 8) = '' Then
            _ArrayDelete($aFlowers, $j)
            $aFlowers[0] -= 1
        EndIf
    Next
    _ArrayColInsert($aFlowers, 1)
    _ArrayColInsert($aFlowers, 1)
    ;_ArrayDisplay($aFlowers)
    For $i = 1 To $aFlowers[0][0]
        $aSplit = StringSplit($aFlowers[$i][0], @CRLF, 1)
        For $j = $aSplit[0] To 1 Step -1
            If $aSplit[$j] = '' Then
                _ArrayDelete($aSplit, $j)
                $aSplit[0] -= 1
            EndIf
        Next
        ;_ArrayDisplay($aSplit, 'Split')
        If $aSplit[0] = 0 Then ExitLoop
        $aFlowers[$i][0] = $aSplit[1]
        #cs
            $sDescription = ''
            For $j = $aSplit[2] To $aSplit[0]; - 1
            if $aSplit[$j]<>'' Then $sDescription &= $aSplit[$j] & @CRLF
            Next
        #ce
        $aFlowers[$i][0] = $aSplit[1]
        $aFlowers[$i][1] = $aSplit[2]
        $aFlowers[$i][2] = $aSplit[$aSplit[0]] & '.jpg'
    Next
EndIf
;_ArrayDisplay($aFlowers)

Global $idPic =-999
$hMainGui=GUICreate('JPG-Viewer',640,480)
$idList=GUICtrlCreateList('',490,5,135,470)
For $i=1 to $aFlowers[0][0]
    GUICtrlSetData($idList,$aFlowers[$i][0])
Next
$idLblDescription=GUICtrlCreateLabel('Test',5,405,470,70);,$SS_LEFT)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idList
            $sVal = GUICtrlRead($idList)
            $iNo= _ArraySearch($aFlowers,$sVal)
            ConsoleWrite($iNo & ' '&$sVal & ': '& $aFlowers[$iNo][1]&@CRLF)
            GUICtrlSetData($idLblDescription,$aFlowers[$iNo][1])
            If $idPic <>-999 Then GUICtrlDelete($idPic)
            $idPic=GUICtrlCreatePic($aFlowers[$iNo][2],5,5,200,200)
    EndSwitch
WEnd

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

am still not good with the autoit yet so your script will take me some time to understand especially

StringStripW

but i will give it my time to understand it .am sooo thankful . you are a life saver ,and the way you write scripts is so clean . i hope someday i could help you with something.

for now i will give this script some time to see how can i edit it

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

May be @mikell or some one else of the StringRegExp experts, show a shorter way to get the 2 dimension array. Btw. there is a typo in your quote the func name is

Quote

StringStripWS

Strips the white space in a string.

, i use it to detect empty lines.

the pic's are visible in the testscript, i couldn't test it? And found typos in this line:

$idPic=GUICtrlCreatePic($aFlowers[$iNo][2],5,5,200,200)

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You could try something like the code below, so you get a 1D array
You can then use it in a For loop with step 3, or build a 2D array with 3 cols, etc

This code implies that the description is a one-liner string and that the data.txt is formatted exactly like the text in post #1 ... regular expression requirements   :)

#Include <Array.au3>

$txt = FileRead("C:\T-in\MPA\data.txt")

$res = StringRegExp($txt, '(?is)(c:\N+jpg)\s*(\N+)\R(\N+)', 3)
 _ArrayDisplay($res)
 
 #cs
Local $u = UBound($res), $flowers[$u/3][3]
For $i = 0 to $u-1 step 3
   $flowers[$i/3][0] = $res[$i+1]
   $flowers[$i/3][1] = $res[$i]
   $flowers[$i/3][2] = $res[$i+2]
Next
 _ArrayDisplay($flowers)
#ce

 

Edited by mikell

Share this post


Link to post
Share on other sites

@Jcreator But why format the text file like that? Why not line by line and separated by some character (comma would make sense except there is free text so pipes or tabs are often better)

Quote

c:\x\y.jpg|my title|This, some text, is the rest of the explanation.

... then use StringSplit or StringRegexp to split it in much the same way, but with easier regexps? :) 

Added benefit: file is easy to maintain in a spreadsheet software like excel.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@SadBunny: i think the textfile is generated from https://orchidflowers.wordpress.com/2012/12/13/list-of-perennials-which-bloom-all-year/

@Jcreator: now the script is shortened:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <StaticConstants.au3>
#include <GuiListBox.au3>

$sFile = FileRead('flowers.txt') ;change to your path
$aRes = StringRegExp($sFile, '(?is)(c:\N+jpg)\s*(\N+)\R(\N+)', 3)
Global $aFlowers[UBound($aRes) / 3 + 1][3], $j
For $i = 0 To UBound($aRes) - 1 Step 3
    $j += 1
    $aFlowers[$j][0] = $aRes[$i + 1]
    $aFlowers[$j][1] = $aRes[$i + 2]
    $aFlowers[$j][2] = $aRes[$i]
Next
$aFlowers[0][0] = $j
;_ArrayDisplay($aFlowers)

Global $idPic = -999
$hMainGui = GUICreate('JPG-Viewer', 640, 480)
$idList = GUICtrlCreateList('', 490, 5, 135, 470)
For $i = 1 To $aFlowers[0][0]
    GUICtrlSetData($idList, $aFlowers[$i][0])
Next
$idLblHeader = GUICtrlCreateLabel('Header', 5, 5, 470, 40);,$SS_LEFT)
GUICtrlSetFont(-1, 14, 800)
$idLblBody = GUICtrlCreateLabel('Body', 5, 395, 470, 70);,$SS_LEFT)
GUICtrlSetFont(-1, 10, 400)
$sFlower=_GUICtrlListBox_GetText($idList, 0)
_FindFlowerByName($sFlower)
_GUICtrlListBox_SelectString($idList, $sFlower)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idList
            $sVal = GUICtrlRead($idList)
            _FindFlowerByName($sVal)
    EndSwitch
WEnd

Func _FindFlowerByName($sFlower)
    Local $iNo = _ArraySearch($aFlowers, $sFlower)
    _FindFlowerByID($iNo)
EndFunc   ;==>_FindFlowerByName

Func _FindFlowerByID($iNo)
    ;ConsoleWrite($iNo & ': '& $aFlowers[$iNo][1]&@CRLF)
    GUICtrlSetData($idLblHeader, $aFlowers[$iNo][0])
    GUICtrlSetData($idLblBody, $aFlowers[$iNo][1])
    If $idPic <> -999 Then GUICtrlDelete($idPic)
    $idPic = GUICtrlCreatePic($aFlowers[$iNo][2], 5, 55, 200, 200)
EndFunc   ;==>_FindFlowerByID

@mikell: i hoped with StringRegExp a one liner is possible for creating and assigning a 2 dimension array, but seems not possible.

Edited by AutoBert

Share this post


Link to post
Share on other sites

Alas, yes indeed using StringRegExp the only arrays you can get are 1D arrays  :(
It's the user's task afterwards to manage it and build their own 2D array with n colummns

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I found a way to get small (not so  small as StringR egExp), easy readable script using stringreplace to get a working file   for the use of _FileReadToArray:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <StaticConstants.au3>
#include <GuiListBox.au3>

$sPath = 'flowers.txt' ;change to your path
$sFile = FileRead($sPath)
$sFile = Stringreplace($sFile,'.jpg'&@CRLF,chr(255)); row seperator placeholder
Do
    $sFile = Stringreplace($sFile,@CRLF&@CRLF,@CRLF)
Until not @extended
$sFile =Stringreplace($sFile,@CRLF,'|')             ;col seperator
$sFile =Stringreplace($sFile,Chr(255), '.jpg'&@CRLF);row seperator restored
$hFile=FileOpen($sPath&'.work',2)
$sFile='|'&$sFile                                   ;all other rows have this also
FileWrite($hFile,$sFile)
FileClose($hFile)
Global $aFlowers
_FileReadToArray($sPath&'.work',$aFlowers,$FRTA_COUNT,'|')
$aFlowers[0][2]=$aFlowers[0][1] ;saving colcount
$aFlowers[0][1]=$aFlowers[0][0] ;saving rowcount
_ArrayColDelete($aFlowers,0) ;col 0 has no data so deleting
;_ArrayDisplay($aFlowers)

Global $idPic = -999
$hMainGui = GUICreate('JPG-Viewer', 640, 480)
$idList = GUICtrlCreateList('', 490, 5, 135, 470)
For $i = 1 To $aFlowers[0][0]
    GUICtrlSetData($idList, $aFlowers[$i][0])
Next
$idLblHeader = GUICtrlCreateLabel('Header', 5, 5, 470, 40);,$SS_LEFT)
GUICtrlSetFont(-1, 14, 800)
$idLblBody = GUICtrlCreateLabel('Body', 5, 395, 470, 70);,$SS_LEFT)
GUICtrlSetFont(-1, 10, 400)
$sFlower=_GUICtrlListBox_GetText($idList, 0)
_FindFlowerByName($sFlower)
_GUICtrlListBox_SelectString($idList, $sFlower)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idList
            $sVal = GUICtrlRead($idList)
            _FindFlowerByName($sVal)
    EndSwitch
WEnd

Func _FindFlowerByName($sFlower)
    Local $iNo = _ArraySearch($aFlowers, $sFlower)
    _FindFlowerByID($iNo)
EndFunc   ;==>_FindFlowerByName

Func _FindFlowerByID($iNo)
    ;ConsoleWrite($iNo & ': '& $aFlowers[$iNo][1]&@CRLF)
    GUICtrlSetData($idLblHeader, $aFlowers[$iNo][0])
    GUICtrlSetData($idLblBody, $aFlowers[$iNo][1])
    If $idPic <> -999 Then GUICtrlDelete($idPic)
    $idPic = GUICtrlCreatePic($aFlowers[$iNo][2], 5, 55, 200, 200)
EndFunc   ;==>_FindFlowerByID

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

this last one did more then what i had in mind ^^ thank you so much i had to do some changes  the line For $i = 1 To $cline

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <StaticConstants.au3>
#include <GuiListBox.au3>

$sPath = 'flowers.txt' ;change to your path
$sFile = FileRead($sPath)
$sFile = Stringreplace($sFile,'.jpg'&@CRLF,chr(255)); row seperator placeholder
Do
    $sFile = Stringreplace($sFile,@CRLF&@CRLF,@CRLF)
Until not @extended
$sFile =Stringreplace($sFile,@CRLF,'|')             ;col seperator
$sFile =Stringreplace($sFile,Chr(255), '.jpg'&@CRLF);row seperator restored
$hFile=FileOpen($sPath&'.work',2)
$sFile='|'&$sFile                                   ;all other rows have this also
FileWrite($hFile,$sFile)
FileClose($hFile)
Global $aFlowers
_FileReadToArray($sPath&'.work',$aFlowers,$FRTA_COUNT,'|')
_ArrayColDelete($aFlowers,0) ;row 0 has no data so deleting
_ArrayDisplay($aFlowers)

Global $idPic = -999
$hMainGui = GUICreate('JPG-Viewer', 640, 480)
$idList = GUICtrlCreateList('', 490, 5, 135, 470)
$cline =_FileCountLines($sPath&'.work') ; i had to add this to make it work for me
For $i = 1 To $cline
    GUICtrlSetData($idList, $aFlowers[$i][0])
Next
$idLblHeader = GUICtrlCreateLabel('Header', 5, 5, 470, 40);,$SS_LEFT)
GUICtrlSetFont(-1, 14, 800)
$idLblBody = GUICtrlCreateLabel('Body', 5, 395, 470, 70);,$SS_LEFT)
GUICtrlSetFont(-1, 10, 400)
$sFlower=_GUICtrlListBox_GetText($idList, 0)
_FindFlowerByName($sFlower)
_GUICtrlListBox_SelectString($idList, $sFlower)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idList
            $sVal = GUICtrlRead($idList)
            _FindFlowerByName($sVal)
    EndSwitch
WEnd

Func _FindFlowerByName($sFlower)
    Local $iNo = _ArraySearch($aFlowers, $sFlower)
    _FindFlowerByID($iNo)
EndFunc   ;==>_FindFlowerByName

Func _FindFlowerByID($iNo)
    ;ConsoleWrite($iNo & ': '& $aFlowers[$iNo][1]&@CRLF)
    GUICtrlSetData($idLblHeader, $aFlowers[$iNo][0])
    GUICtrlSetData($idLblBody, $aFlowers[$iNo][1])
    If $idPic <> -999 Then GUICtrlDelete($idPic)
    $idPic = GUICtrlCreatePic($aFlowers[$iNo][2], 5, 55, 200, 200)
EndFunc   ;==>_FindFlowerByID

 

Share this post


Link to post
Share on other sites

am really thankful for all your help guys and am sorry for being slow at understanding the answer -.- still trying to learn this 

by the way the 

_FileReadToArray

was really useful and i tried to use it in another part of the script where it will show the flowers information and picture by typing the name of the flower 

script

#include <Misc.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiComboBox.au3>
#include <GuiTab.au3>
#include <file.au3>
#include <array.au3>

Global $sfPath = 'flowers.txt'
Global $aFlowers
_FileReadToArray($sfPath,$aFlowers,$FRTA_NOCOUNT,'|')
_ArrayColDelete($aFlowers,0) ;row 0 has no data so deleting

$Form1 = GUICreate("Search Flower Name",320, 480)
$input = GUICtrlCreateInput("", 60, 360, 209, 25)
$idss = GUICtrlCreateButton("Search", 130, 400, 73, 65)

GUISetState(@SW_SHOW)




Func Searchf()



Global $Fname = GUICtrlRead($input)


        For $iNo = 0 To UBound($aFlowers[0][0]) - 1 ;

           if $Fname = $aFlowers[$iNo][0] then

MsgBox($MB_SYSTEMMODAL, "","Flower nfo", ""& $aFlowers[$iNo][1] &"")

pic()

EndIf
        Next

EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE

            Exit
         Case $nMsg = $idss

        Searchf()

    EndSwitch
 WEnd

func pic()
   For $iNo = 0 To UBound($aFlowers[0][0]) - 1
   GUICtrlCreatePic($aFlowers[$iNo][2], 20, 30, 280, 280)
    Next
   EndFunc

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

@AutoBert i hope that you dont mind me using your code in a different script

and thanks to @mikell for trying to help too

 

Edited by Jcreator

Share this post


Link to post
Share on other sites

Just a quick off-topic friendly word of advice: use the Tidy tool (Tools -> Tidy AutoIt Source or Ctrl+T). It will format your code to make it much more readable, and while doing that it will also very clearly indicate potential syntax problems. This will assist you in writing proper code and catching problems early. I press it, like, every five seconds (it also saves your code, so for me it's pretty much a Ctrl+S replacement :)).

Also, "tidy"-ing your code before posting here on the forum will also go a long way to make it much easier to read for others.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

^^ @SadBunny thx for the  advice  but i cant seem to find this  Tools -> Tidy AutoIt if it exist 

Share this post


Link to post
Share on other sites

Are you using the full version of the Scite editor? If not, I suggest getting it, it is quite useful :dance:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

16 hours ago, Jcreator said:

i had to do some changes  the line For $i = 1 To $cline

ups, there was an error the last flower wasn't read. So i had just corrected an edited last post. Here only the snipet to see changes:

_FileReadToArray($sPath&'.work',$aFlowers,$FRTA_COUNT,'|')
$aFlowers[0][2]=$aFlowers[0][1] ;inserted=>saving colcount      
$aFlowers[0][1]=$aFlowers[0][0] ;inserted=>saving rowcount
_ArrayColDelete($aFlowers,0) ;col 0 has no data so deleting

in your func Searchf you are using ubound wrong, must be 

For $iNo = 0 To UBound($aFlowers) - 1 ;

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

@AutoBert thank you so much this was really helpful ^^

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

  • Similar Content

    • usmiv4o
      By usmiv4o
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.3 Author: usmiv4o Script Function: AutoIt script to check if files in directory are changed. It is usefull for security contra-inteligense measures. Function Name: LoadTripwireDB() Description: Loads database (text file tripwire.txt) and compare files in /test folder for changes. compares Hash (MD5) checksums. If they are not the same starts Initial() Function Name: Initial() Description: Checks directory and makes index of files and their MD5 checksums in text file (tripwire.txt) Function Name: Hush() Description: Checks file and returns its MD5 checksum. Requirement(s): Windows XP Return Value(s): On Success - Returns true. Files are the same as before. On Failure - return false. Example: LoadTripwireDB() #ce ---------------------------------------------------------------------------- #include <Crypt.au3> #include <File.au3> #include <Array.au3> $sDir = @ScriptDir & "\Test" $sFilePath = @ScriptDir & "\tripwire.txt" Func Hush(ByRef $sFile) $sRead = FileOpen( $sFile) $dHash = _Crypt_HashData($sRead, $CALG_MD5) ; Create a hash of the text entered. ConsoleWrite("Hash of file " & $sFile & " is " & $dHash & @CRLF) EndFunc ;ConsoleWrite("Files in Dir are " & $aScriptDir[0] & @CRLF) ;$sFilePath = @ScriptDir & "\Examples.txt" ;_FileWriteFromArray($sFilePath, $aScriptDir, 1) ;_ArrayDisplay($aScriptDir, "1D display") Func Initial() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 $dHash = _Crypt_HashData($i, $CALG_MD5) ;ConsoleWrite("File " & $aScriptDir[$i] & " is " & $dHash & @CRLF) ConsoleWrite($aScriptDir[$i] & ":" & $dHash & @CRLF) ;Hush($aScriptDir[$i]) ;FileWrite $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") EndIf FileWrite($hFileOpen, $aScriptDir[$i] & ":" & $dHash & @CRLF) Next EndFunc Func Monitor() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 Next EndFunc Func LoadTripwireDB() $comparison_ok = false $dArray = _FileListToArray($sDir) ;directory $dArray0 = UBound($dArray) - 1 $fArray = FileReadToArray($sFilePath) ;file $fArray0 = UBound($fArray) ;_ArrayDisplay($dArray, "files array") if $dArray0 = $fArray0 Then ; are file same as recorded in txt file? ;ConsoleWrite("files in monitoring dir: " & $dArray[0] & " = file recorded: " & $fArray0 & @CRLF & $fArray[0]& @CRLF) for $i = 1 To UBound($dArray) - 1 ;ConsoleWrite("i = " & $i & @CRLF) $dHash = _Crypt_HashData($i, $CALG_MD5) ;binary ;$dHash = BinaryToString($dHash) $ffhash = StringSplit( $fArray[$i-1],":") $fhash = $ffhash[2] ;ConsoleWrite("IsBinary $dHash " & IsBinary($dHash) & @CRLF) if $dHash = $fhash Then ;if compared hashes are equal ;ConsoleWrite($fhash & ":" & $dHash & " equal" & @CRLF) ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: yes " & @CRLF) Else ;if compared hashes are not equal ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: not " & @CRLF) ;MsgBox(0,"hash md5",$fhash & ":" & $dHash & " not equal") EndIf Next ;ConsoleWrite("hashes are equal" & @CRLF) $comparison_ok = true Else ConsoleWrite("number of files in monitoring dir are not same as recorded" & @CRLF) ConsoleWrite("directory: " & $dArray[0] &":"& "files: " & UBound($fArray) - 1 & @CRLF) EndIf Return $comparison_ok EndFunc #main if LoadTripwireDB() = true Then ConsoleWrite(" hashes are equal " & @CRLF) ElseIf LoadTripwireDB() <> true Then ConsoleWrite(" hashes are not equal " & @CRLF) ConsoleWrite(" hashes are not equal " & @CRLF) Initial() EndIf  
      tripwire.au3
      tripwire.txt
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt
    • 5ervant
      By 5ervant
      What's the best way to receive file from a desktop app?
      app.exe will execute a cmd with "au3file.exe /path/of/the/file.xml" and the au3file.exe will get and delete that. Or else? THE MOST IMPORTANT PART OF THE QUESTION
      And best way to transfer file to a desktop app?
      au3file.exe do a $_POST request and the app.exe MUST HAVE a local HTTP server that can receive $_POST, but it looks heavy 'cause the app must have a server such XAMPP. au3file.exe execute a cmd with "app.exe /path/of/the/file.xml" and the app.exe will now get that file and delete. Or else?