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

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1+ System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • nacerbaaziz
      By nacerbaaziz
      can we  create a list box with  Columns?
      welcome everybody
      Dears I have a question if you let me
      can we  create a list box with  Columns?
      i know we can create a list view with Columns
      but my question is about the list box
      I'm waiting your responses
      Thank you in advance
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
    • KING_NK
      By KING_NK
      #RequireAdmin
      Global $x=0
      Global $y=0
      Func Start()
      While 1
      AutoItSetOption('MouseCoordMode',0)
      AutoItSetOption('SendKeyDelay',10)
      WinActivate('XXX')
      MouseClick('Primary',852,62,1,10)
      sleep(2200)
      MouseClick('Primary',880,196,1,10)
      Send('260',0)      -----------------------> $a as 260
      MouseClick('Primary',880,196,1,0)
      sleep(2200)
      MouseClick('Primary',1019,194,1,10)
      Sleep(2200)
      Send('98',0) ------------------------->$b as 98
      sleep(1000)
      Wend
      EndFunc
       
       
      I want to use Different number in every loop in the place of $a and  $b.
      Is it possble?If it possible Kindly help me
    • amphoric
      By amphoric
      Hi,
      I am struggling converting my 1D array to a 2D array and then showing that in my List View. Below is my current code, where I would like to take the array from the input box, and have that displayed as a list within the list view this is a list of computer names, and then update the 2nd column of each line once I have ran a ping and a registry change on each computer name, with either 'Completed' and 'Failed'
      I have checked out the AutoIt Arrays page here: https://www.autoitscript.com/wiki/Arrays , but unfortunately I cannot get my head around it. Any help would be greatly appreciated.
      I hope this makes sense.
      Thanks
       
      #include <Date.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #Region ### $Form1 = GUICreate("Title", 515, 533, -1, -1) GUISetBkColor(0xFFFFFF) $Pic2 = GUICtrlCreatePic("Images\pic.jpg", 16, 16, 212, 28) $Label1 = GUICtrlCreateLabel("Label", 240, 16, 271, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "") $Combo1 = GUICtrlCreateCombo("", 256, 406, 241, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE)) $Label2 = GUICtrlCreateLabel("Please select the location", 45, 401, 210, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $ChangeButton = GUICtrlCreateButton("Change", 286, 487, 75, 25) $RePromptButton = GUICtrlCreateButton("Re-prompt User", 366, 487, 139, 25) $Checkbox1 = GUICtrlCreateCheckbox("I have ensured that my selection is correct.", 10, 487, 273, 25) GUICtrlSetFont(-1, 10, 400, 0, "") $ManLocation = GUICtrlCreateLabel("Please enter the location:", 59, 448, 189, 20, $SS_RIGHT) GUICtrlSetFont(-1, 10, 800, 0, "") GUICtrlSetState(-1, $GUI_HIDE) $ManLocInput = GUICtrlCreateInput("", 256, 445, 241, 24) GUICtrlSetState(-1, $GUI_HIDE) $Label5 = GUICtrlCreateLabel("for this device:", 138, 418, 109, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Label3 = GUICtrlCreateLabel("Asset Number:", 98, 72, 107, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Input1 = GUICtrlCreateInput("", 215, 69, 241, 24) $AddMulti = GUICtrlCreateLabel("Add Multiple Assets", 356, 55, 98, 13, $SS_RIGHT) GUICtrlSetFont(-1, 8, 400, 6, "") GUICtrlSetColor(-1, 0x808080) GUICtrlSetCursor (-1, 0) $List1 = GUICtrlCreateListView("", 16, 104, 481, 278) $Add = GUICtrlCreateButton("Add", 461, 68, 35, 25) GUISetState(@SW_SHOW) #EndRegion ### ;### StartForm ### $FormaMultiple = GUICreate("Title", 277, 418, -1, -1) GUISetBkColor(0xFFFFFF) $Label1 = GUICtrlCreateLabel("Please add 1 asset number per line.", 8, 11, 253, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $OK = GUICtrlCreateButton("OK", 56, 375, 75, 25) $Edit1 = GUICtrlCreateEdit("", 20, 40, 233, 329) $Cancel = GUICtrlCreateButton("Cancel", 136, 375, 75, 25) GUISetState(@SW_HIDE) ;### EndForm ### ;### Add List View Columns START ### ;### Add List View Columns END ### ;### Read Locations START ### ;Read the LOCAL ini file SECTIONS Global $aSections = IniReadSectionNames("Locations.ini") ;If the above succeeded, convert the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1] If(Not @Error) Then GUICtrlSetData($Combo1, _ArraytoString($aSections, "|", 1), $aSections[1]) ;### Read Locations END ### ;### Require Admin START ### ;#RequireAdmin ;### Require Admin END ### While 1 $nMsg = GUIGetMsg() ;### Data Validation START ### ;Set Checkbox = ENABLE/DISABLE if not GUICtrlRead($Combo1) = "" AND GUICtrlRead($Combo1) = "Not In List" then if not GUICtrlRead($ManLocInput) = "" Then If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) Else If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) EndIf Else if GUICtrlRead($Combo1) = "" Then If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) Else If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) EndIf EndIf ;Set Button = ENABLE/DISABLE If GUICtrlRead($Checkbox1) = 1 Then If Not ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_ENABLE) Else If ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_DISABLE) EndIf ;### Data Validation END ### Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $Add Case $AddMulti GUISetState(@SW_SHOW, $FormaMultiple) Case $Cancel GUISetState(@SW_HIDE, $FormaMultiple) Case $OK $sText = GUICtrlRead($Edit1) $aText = StringSplit($sText, @CRLF, 1) $bText = _ArrayToString($aText, ";", 1, -1) $cText = StringStripWS($bText, $STR_STRIPALL ) $dText = StringReplace($cText,";;",";") GUICtrlSetData($Input1, $dText) GUICtrlSetData($Edit1, "") GUISetState(@SW_HIDE, $FormaMultiple) For $i = 1 To $aText[0] Next Case $Combo1 ; If the combo is actioned Switch GUICtrlRead($Combo1) Case "Not In List" ; Show the manual input controls GUICtrlSetState($ManLocation, $GUI_SHOW) GUICtrlSetState($ManLocInput, $GUI_SHOW) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") Case Else ; Hide them GUICtrlSetState($ManLocation, $GUI_HIDE) GUICtrlSetState($ManLocInput, $GUI_HIDE) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") EndSwitch Case $ChangeButton ChangeReg() Case $RePromptButton RemoveReg() EndSwitch WEnd Func ChangeReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & " Changed to: " & GUICtrlRead($Combo1)) Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg Func RemoveReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & "CLEARED") Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg1