Sign in to follow this  
Followers 0
harvester2001

Refresh array after one loop

11 posts in this topic

#1 ·  Posted (edited)

Hi

I need some help.

I try ping computers from targets.txt (I have computer name in lines) if they ping I want do something and after that remove pc name from targets.txt. It`s working but problem is when I put this inside loop, because I need run script until all computers will not be removed from the list (targets.txt). I don`t know how to "refresh" array :(

Please help :)

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

Local $PC_list = "\targets.txt"
Local $bTargets = FileReadToArray(@ScriptDir& $PC_list)

Do
   _check_ping()
   ;count_lines
   Local $file_count_lines = _FileCountLines(@ScriptDir& $PC_list)
   $i = $file_count_lines
   ConsoleWrite("na liście "&$i & @CRLF)
Until $i = 0
; IF &i = 0 then show MsgBox
MsgBox(1, "xXx", "Finish")

;PING
Func _check_ping()
   For $sPC In $bTargets
   $var = Ping($sPC, 250)
      If $var Then
         ConsoleWrite($sPC &"online"& @CRLF)
         ;Do something

         ;Delete $sPC from targets.txt
         Local $_Array
         _FileReadToArray ( @ScriptDir& "\targets.txt", $_Array )
         $_Array = _DeleteArrayElementWithStringInstr ( $_Array, $sPC )
         _FileWriteFromArray ( @ScriptDir& "\targets.txt", $_Array, 1 )
         Sleep(200)
      Else
         ConsoleWrite($sPC &"offline"& @CRLF)
      EndIf
   Next
EndFunc

;DELETE LINE FROM TXT
Func _DeleteArrayElementWithStringInstr ( $_Array, $_String )
    Local $_Item
    For $_Element In $_Array
        If StringInStr ( $_Element, $_String ) <> 0 Then
            _ArrayDelete ( $_Array, $_Item )
        Else
            $_Item+=1
        EndIf
    Next
    Return ( $_Array )
EndFunc ;==> _DeleteArrayElementWithStringInstr ( )

 

Edited by harvester2001

Share this post


Link to post
Share on other sites



If you don't really need to destroy your "targets.txt" file, then you could use an array to track what's going on, keeping your file safe instead.

Something like this should work (not tested)

Local $PC_list = "\targets.txt"
Local $aTargets = FileReadToArray(@ScriptDir & $PC_list)
If @error Then
    MsgBox(0, "Error", "Error on reading file.")
    Exit
EndIf

Local $iToBePinged = UBound($aTargets) ; total nr of pc to ping
Local $aIndex[$iToBePinged + 1] = [$iToBePinged] ; counter in element [0]

; initialize index
For $i = 1 To $aIndex[0]
    $aIndex[$i] = $i - 1
Next

Do
    For $i = $aIndex[0] To 1 Step -1 ; scans all remaining pc
        If Ping($aTargets[$aIndex[$i]], 250) Then
            ConsoleWrite($aTargets[$aIndex[$i]] & " online" & @CRLF)
            ; Do something

            ; adjust indexes
            $aIndex[$i] = $aIndex[$aIndex[0]]
            $aIndex[0] -= 1
        Else
            ; ConsoleWrite($aTargets[$aIndex[$i]] & " offline" & @CRLF)

        EndIf
    Next
Until Not $aIndex[0]

MsgBox(0, "xXx", "Finish")

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Work like a charm, thank you very much :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

But this work wery unstable. The loop works, after a few runs exit code. No specific error.

Any ideas how to improve?

 

This is all code, maybe somebody need this.

Script read information about configuration from computers in network.

 

P.S.

I somebody know how to get display resolution (from remote computer) plz give me know :)

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <FileConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>

Local $PC_list = "\targets.txt"
Local $log_success = "\success.txt"
Local $log_error = "\error.txt"


Local $aTargets = FileReadToArray(@ScriptDir & $PC_list)
If @error Then
    MsgBox(0, "Error", "Error on reading file targets.txt")
    Exit
EndIf

Local $iToBePinged = UBound($aTargets) ; total nr of pc to ping
Local $aIndex[$iToBePinged + 1] = [$iToBePinged] ; counter in element [0]

; initialize index
For $i = 1 To $aIndex[0]
    $aIndex[$i] = $i - 1
Next

Do
    For $i = $aIndex[0] To 1 Step -1 ; scans all remaining pc
        If Ping($aTargets[$aIndex[$i]], 250) Then
            ConsoleWrite($aTargets[$aIndex[$i]] & " online" & @CRLF)
            ; Do something
               czytam_zdalny_pc()
               Sleep(200)
            ; adjust indexes
            $aIndex[$i] = $aIndex[$aIndex[0]]
            $aIndex[0] -= 1
            ConsoleWrite($i & " remained " & @CRLF)
        Else
            ConsoleWrite($aTargets[$aIndex[$i]] & " offline" & @CRLF)
            Sleep(100)
        EndIf
    Next
Until Not $aIndex[0]

MsgBox(0, "INWENTARYZATOR", "Finished gathering information ")


Func czytam_zdalny_pc()

   $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $aTargets[$aIndex[$i]] & "\root\cimv2")
   If IsObj($objWMIService) Then
         ;Get System
         $colItem = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
         For $objItem in $colItem
             ;ConsoleWrite( $objItem.CSName & " " & $objItem.Caption & " " & $objItem.Version & @CRLF)
             Local $systemOS = $objItem.CSName & " " & $objItem.Caption & " " & $objItem.Version
         Next

         ;ConsoleWrite(@CRLF)

         ;Get Ram
         $colItem = $objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
         For $objItem in $colItem
             ;ConsoleWrite( "Total RAM " & $objItem.TotalPhysicalMemory & @CRLF)
             Local $RAM = Int($objItem.TotalPhysicalMemory /1048576)
         Next

         ;Get PC Model
         $colItem = $objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystemProduct")
         For $sOS in $colItem
             ;ConsoleWrite(" Vendor: " & $sOS.Vendor & " SN: " & $sOS.IdentifyingNumber & " Name: " & $sOS.Name & @CRLF)
         Next

         ;ConsoleWrite(@CRLF)

         ; Wpisuje do pliku
         FileWriteLine(@ScriptDir & $log_success, $aTargets[$aIndex[$i]] & _
         " Vendor: " & $sOS.Vendor & " SN: " & $sOS.IdentifyingNumber & " Name: " & $sOS.Name & _
         " System: " & $systemOS & " RAM: " & $RAM &" mb "& _
         @CRLF)


         ;console log
         ConsoleWrite($aTargets[$aIndex[$i]] & " I read data" & @CRLF)
       Else
           ;Msgbox($MB_OK,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" )
           ConsoleWrite($aTargets[$aIndex[$i]] & " No WMI Objects Found" & @CRLF)
       Endif
EndFunc

 

Edited by harvester2001

Share this post


Link to post
Share on other sites

Help me plz.

I do something like that, its stable but one problem, its not delete last row and loop never end.

I need loop working until last localization answer for ping.

#include <File.au3>
#include <Array.au3>


For $i = 0 to _FileCountLines(@ScriptDir& "\targets.txt")
   Dim $array = FileReadToArray(@ScriptDir& "\targets.txt")
   For $i = UBound($array) -1 To 0 Step -1
      Sleep(200)
      If Ping($array[$i], 250) Then
         ;ONLINE
         ConsoleWrite($array[$i] & "online" & @CRLF)
         Sleep(200)
         $iIndex = _ArraySearch($array, $array[$i], 1, 0, 0, 1)
         Sleep(200)
         ; And if found - delete
         If Not @error Then
             _ArrayDelete($array, $iIndex)
          EndIf
          Sleep(200)
          _FileWriteFromArray(@ScriptDir& "\targets.txt", $array, 1)
      Else
         ;OFFLINE
         ConsoleWrite($array[$i] & "offline" & @CRLF)
         Sleep(200)
      EndIf
   Next
Next

 

Share this post


Link to post
Share on other sites

Maybe this?

#include <File.au3>
#include <Array.au3>
Dim $array = FileReadToArray(@ScriptDir & "\targets.txt")
For $i = UBound($array) - 1 To 0 Step -1
    Sleep(200)
    If Ping($array[$i], 250) Then
        ;ONLINE
        ConsoleWrite($array[$i] & "online" & @CRLF)
        Sleep(200)
        ; And if found - delete
        If Not @error Then
            _ArrayDelete($array, $i)
        EndIf
        Sleep(200)
    Else
        ;OFFLINE
        ConsoleWrite($array[$i] & "offline" & @CRLF)
        Sleep(200)
    EndIf
Next
_FileWriteFromArray(@ScriptDir & "\targets.txt", $array)

In your script you were reusing the $i variable in the second loop, so the value never gets updated for the first loop.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thx, but  loop end when check all locations from list.

I need loop to working untill  locations respond successfully to ping.

If  location is offline loop should check another locations and after finish, check again locations which were offline.

In brief: I want send something for this locations, but if they offline this aplications should wait until they will be online.

Sorry for my english.

Share this post


Link to post
Share on other sites

Try this.

#include <File.au3>
#include <Array.au3>
Dim $array = FileReadToArray(@ScriptDir & "\targets.txt")
Global $ReadError = @error
While $ReadError = 0
    For $i = UBound($array) - 1 To 0 Step -1
        Sleep(200)
        If Ping($array[$i], 250) Then
            ;ONLINE
            ConsoleWrite($array[$i] & "online" & @CRLF)
            Sleep(200)
            ; And if found - delete
            If Not @error Then
                _ArrayDelete($array, $i)
            EndIf
            Sleep(200)
        Else
            ;OFFLINE
            ConsoleWrite($array[$i] & "offline" & @CRLF)
            Sleep(200)
        EndIf
    Next
    If UBound($array) > 0 Then
        _FileWriteFromArray(@ScriptDir & "\targets.txt", $array)
    Else
        ExitLoop
    EndIf
    $array = FileReadToArray(@ScriptDir & "\targets.txt")
    $ReadError = @error
WEnd

If FileReadToArray reads an empty file it will set the @error macro and the While loop will end. If the $array array is empty, it exits the loop as well, which would only happen if all the Pings return as valid.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

harvester2001,

Another way to look at the problem.  The loop is controlled by a switch and the source file is not altered.

#include <array.au3>
#include <date.au3>

Local $aPingList = StringSplit(FileRead(@ScriptDir & '\targets.txt'), @CRLF, 3), $again = True

While $again

    $again = False

    For $1 = 0 To UBound($aPingList) - 1

        If $aPingList[$1] = '' Then ContinueLoop
        Ping($aPingList[$1], 250)
        If @error Then
            ConsoleWrite('!  ' & StringFormat('%10s %30s was not reachable', _Now(), $aPingList[$1]) & @CRLF)
            $again = True ; loop again
        Else
            ConsoleWrite('>  ' & StringFormat('%10s %30s was     reachable', _Now(), $aPingList[$1]) & @CRLF)
            ;
            ; go do your other stuff
            ;
            $aPingList[$1] = '' ;   clear entry
        EndIf

    Next
WEnd

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question related to strings items in an Array and sorting. Maybe someone can advice me how to solve the issue.
      I have an Array of strings, every item of the Array is as following:
      INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]  INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x I want to sort the item in the array by date and time, is there any function which allows me to sort by date/time?
      Thanks in advance
    • Rimoun
      By Rimoun
      Hello everyone
      I would like to have some help regarding my issue.
      I am trying to extract some information from excel sheet, I use _Excel_RangeFind then I get the array for the value then I check the array. In case the array is true the next will be to get some information based on the extracted array if no array because the value is not found it gives a messages box that the value is not found.
      My problem that the button works for one time only if i tried any value which exist in the sheet it gives me that value not found.
      I suspect that there is a problem regarding While loop.
      here is my code
      #include <GUIConstantsEx.au3> #include <WinAPI.au3> #Include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <ExcelConstants.au3> if FileExists ("result.txt") Then Sleep (100) Else readxl() EndIf Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel Error", "Error opening workbook '" & $oWorkbook & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $lab1 = _Excel_RangeRead($oWorkbook, Default,"B1") Local $lab2 = _Excel_RangeRead($oWorkbook, Default,"C1") Local $lab3 = _Excel_RangeRead($oWorkbook, Default,"D1") Local $lab4 = _Excel_RangeRead($oWorkbook, Default,"E1") Global $sResult1,$sResult2,$sResult3,$sResult4,$sResult5,$sResult6 Global $asKeyWords = stringsplit (FileRead (@ScriptDir & "\result.txt"),@CRLF) Global Const $xlUp = -4162 ;~ _Main() Local $hGUI, $hList, $hInput, $aSelected, $sChosen, $hUP, $hDOWN, $hENTER, $hESC Local $sCurrInput = "", $aCurrSelected[2] = [-1, -1], $iCurrIndex = -1, $hListGUI = -1 $hGUI = GUICreate("Rimo System", 253, 270, 192, 124) Global $hInput = GUICtrlCreateInput("", 24, 48, 169, 21) Global $Label1 = GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25) GUICtrlSetFont(-1, 14, 800, 0, "MS Serif") Global $Input2 = GUICtrlCreateInput("", 72, 144, 161, 21) Global $Input3 = GUICtrlCreateInput("", 72, 176, 161, 21) Global $Input4 = GUICtrlCreateInput("", 72, 208, 161, 21) Global $Input5 = GUICtrlCreateInput("", 72, 240, 161, 21) $Input6 = GUICtrlCreateInput("", 72, 272, 161, 21) $Input7 = GUICtrlCreateInput("", 72, 304, 161, 21) $Button1 = GUICtrlCreateButton("Get Info", 72, 88, 89, 33) $Label2 = GUICtrlCreateLabel("Label2", 16, 144, 36, 17) GUICtrlSetData( -1,$lab1) $Label3 = GUICtrlCreateLabel("Label3", 16, 176, 36, 17) GUICtrlSetData( -1,$lab2) $Label4 = GUICtrlCreateLabel("Label4", 16, 208, 36, 17) GUICtrlSetData( -1,$lab3) $Label5 = GUICtrlCreateLabel("Label5", 16, 240, 36, 17) GUICtrlSetData( -1,$lab4) $Label6 = GUICtrlCreateLabel("", 16, 272, 36, 17) $Label7 = GUICtrlCreateLabel("", 16, 304, 36, 17) $Button2 = GUICtrlCreateButton("Cancel", 112, 416, 121, 25) GUISetState(@SW_SHOW, $hGUI) Global $sSearch = guictrlread ($hInput) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() $hESC = GUICtrlCreateDummy() Dim $AccelKeys[4][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER], ["{ESC}", $hESC]] GUISetAccelerators($AccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button2 Exit Case $Button1 Global $aResult = _Excel_RangeFind($oWorkbook, guictrlread($hInput) ,"A2:A2000") Global $aExtract = _ArrayExtract($aResult, 0, 0, 2, 2) if _elementExists($aExtract,0) Then getdata() Else MsgBox(0,"","Value Does Not Exist") EndIf Case $hESC If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 Else ExitLoop EndIf Case $hUP If $hListGUI <> -1 Then ; List is visible. $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $hListGUI <> -1 Then ; List is visible. $iCurrIndex += 1 If $iCurrIndex > _GUICtrlListBox_GetCount($hList) - 1 Then $iCurrIndex = _GUICtrlListBox_GetCount($hList) - 1 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $hListGUI <> -1 And $iCurrIndex <> -1 Then ; List is visible and a item is selected. $sChosen = _GUICtrlListBox_GetText($hList, $iCurrIndex) EndIf Case $hList $sChosen = GUICtrlRead($hList) EndSwitch Sleep(10) $aSelected = _GetSelectionPointers($hInput) If GUICtrlRead($hInput) <> $sCurrInput Or $aSelected[1] <> $aCurrSelected[1] Then ; Input content or pointer are changed. $sCurrInput = GUICtrlRead($hInput) $aCurrSelected = $aSelected ; Get pointers of the string to replace. $iCurrIndex = -1 If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 EndIf $hList = _PopupSelector($hGUI, $hListGUI, _CheckInputText($sCurrInput, $aCurrSelected)) ; ByRef $hListGUI, $aCurrSelected. EndIf If $sChosen <> "" Then GUICtrlSendMsg($hInput, 0x00B1, $aCurrSelected[0], $aCurrSelected[1]) ; $EM_SETSEL. _InsertText($hInput, $sChosen) $sCurrInput = GUICtrlRead($hInput) GUIDelete($hListGUI) $hListGUI = -1 $sChosen = "" EndIf WEnd GUIDelete($hGUI) Func _CheckInputText($sCurrInput, ByRef $aSelected) Local $sPartialData = "" If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ") $aSelected[0] -= StringLen($aSplit[$aSplit[0]]) If $aSplit[$aSplit[0]] <> "" Then For $A = 1 To $asKeyWords[0] If StringLeft($asKeyWords[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] And $asKeyWords[$A] <> $aSplit[$aSplit[0]] Then $sPartialData &= $asKeyWords[$A] & "|" EndIf Next EndIf EndIf Return $sPartialData EndFunc ;==>_CheckInputText Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List) Local $hList = -1 If $sCurr_List = "" Then Return $hList EndIf $hListGUI = GUICreate("", 280, 160, 23, 62, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI) $hList = GUICtrlCreateList("", 0, 0, 170, 150, BitOR(0x00100000, 0x00200000)) GUICtrlSetData($hList, $sCurr_List) GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible. GUISetState(@SW_SHOWNOACTIVATE, $hListGUI) Return $hList EndFunc ;==>_PopupSelector Func _InsertText(ByRef $hEdit, $sString) #cs Description: Insert A Text In A Control. Returns: Nothing #ce Local $aSelected = _GetSelectionPointers($hEdit) GUICtrlSetData($hEdit, StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString & StringTrimLeft(GUICtrlRead($hEdit), $aSelected[1])) Local $iCursorPlace = StringLen(StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString) GUICtrlSendMsg($hEdit, 0x00B1, $iCursorPlace, $iCursorPlace) ; $EM_SETSEL. EndFunc ;==>_InsertText Func _GetSelectionPointers($hEdit) Local $aReturn[2] = [0, 0] Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL. If IsArray($aSelected) Then $aReturn[0] = $aSelected[0] $aReturn[1] = $aSelected[1] EndIf Return $aReturn EndFunc ;==>_GetSelectionPointers Func GUISetControlsVisible($hWnd) ; By Melba23. Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0) Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1)) For $i = 3 To $iLastControlID $aControlGetPos = ControlGetPos($hWnd, '', $i) If IsArray($aControlGetPos) = 0 Then ContinueLoop $hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3]) _WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2) _WinAPI_DeleteObject($hCreateRect) Next _WinAPI_SetWindowRgn($hWnd, $hRectRgn, True) _WinAPI_DeleteObject($hRectRgn) EndFunc Func _elementExists($array, $element) If $element > UBound($array)-1 Then Return False ; element is out of the array bounds Return True ; element is in array bounds EndFunc Func getdata() ;~ Local $sResult1 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","B")) ;~ Local $sResult2 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","C")) ;~ Local $sResult3 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","D")) ;~ Local $sResult4 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","E")) ;~ Local $sResult5 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","F")) ;~ Local $sResult6 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","G")) guictrlsetdata($Input2,$sResult1) guictrlsetdata($Input3,$sResult2) guictrlsetdata($Input4,$sResult3) guictrlsetdata($Input5,$sResult4) guictrlsetdata($Input6,$sResult5) guictrlsetdata($Input7,$sResult6) _Excel_Close($oExcel,Default,True) EndFunc Func readxl() Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) LOcal Const $xlUp = -4162 With $oWorkbook.ActiveSheet ; process active sheet $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column $iLastCell = .Cells($iRowCount + 1, "B").End($xlUp).Row ProgressOn("Copying Cells", "Copying Cells progress", "0%") For $i = 2 to $iLastCell Local $total = Int(($i/$iLastCell)*100) Local $sResult3 = _Excel_RangeRead($oWorkbook, Default, "A" & $i) FileWriteLine("result.txt",$sResult3) ProgressSet(($i/$iLastCell)*100, $total & "%") Next ;~ FileWrite("result.txt",$sResult3) ProgressSet(100, "Done", "Complete") Sleep (1500) ProgressOff() _Excel_Close($oExcel,Default,True) EndWith EndFunc  
    • hcI
      By hcI
      Hello, i'm making a little script that lets users enter a question and if the script can't answer to, it ask what would be the answer (a bit like siri on IPhones). And I try to display the "supposed array" I still have an error.. I searched on Google and got nothing looked in the help file too.. I'm here to know if someone have a solution to my error please.
      Here is where $a and $b should become arrays :
      Dim $dossier = @AppDataDir & "\Siri2" Dim $chemin = $dossier & "\data.ini" Global $a = _InfoRead($chemin, 0) Global $b = _InfoRead($chemin, 1) with this function :
      Func _InfoRead($path, $mode = 0) If DirGetSize($dossier) = -1 Then Return SetError(-4) If Not FileExists($chemin) Then Return SetError(-5) Local $readed = IniReadSection($path, "data") If @error Then Return SetError(-3) $size = $readed[0][0] Local $return[$size] For $i = 1 To $size Step 1 $return[$i - 1] = $readed[$i][$mode] Next Return $return EndFunc and the thing that i don't understand is that, after _InfoRead return affected to $a, I can't use _ArrayDisplay because of  error 1 "$aArray is not an array" (and same fpr the variable $b)..
      Can please someone help me to understand why is it doing this ?

      -hcI
    • JayHawkfl
      By JayHawkfl
      Super simple super quick script I made to randomize teams for mixed doubles. Haven't coded for a while so it felt good to write anything. 
       
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> Local $arraySize = 2 local $array1[50] = ["Doug","Julio"] local $array2[50] = ["Hannah","Sheila"] Local $oBook #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Doubles Team Mixer", 615, 438, 192, 124) $Bachround = GUICtrlCreatePic("C:\Users\a607150\Pictures\2.jpg",0,0,615,438) $Input1 = GUICtrlCreateInput("", 64, 128, 121, 175) $Input2 = GUICtrlCreateInput("", 364, 128, 121, 175) $Button1 = GUICtrlCreateButton("Serve",216,140,121,42) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $array1 = GUICtrlRead($input1) $array1 = StringSplit($array1,",") $array2 = GUICtrlRead($input2) $array2 = StringSplit($array2,",") _ArrayDelete($array1,0) _ArrayDelete($array2,0) _ArrayShuffle($array2) $oBook = _Excel_Open(Default, Default, Default, Default, True) $oWorkBook = _Excel_BookNew($oBook, 1) _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,"Guys","A1") _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,"Gals","B1") _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,$array1,"A2") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing $array1 to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,$array2,"B2") EndSwitch WEnd  
    • jjohn
      By jjohn
      Hi all,
      I have the following code, basically, it populates an array with unique characters found in a string, but it turns out only one character is in the array, i don't want to think it is due to a bug of autoit at this point, so i need your help on why, please
      Dim $sx[0] Dim $cn $ss = "Xx" ConsoleWrite(StringLeft($ss, 1) & " " & StringRight($ss, 1) & @CRLF) ConsoleWrite(StringLeft($ss, 1) = StringRight($ss, 1) & @CRLF) ;here show X <> x ConsoleWrite(@CRLF) ;the following is to populate array $sx with different unique characters in $ss For $b = 1 To StringLen($ss) $flg = 0 For $a = 0 To UBound($sx) - 1 ;if asc(StringMid($ss,$b,1)) = asc($sx[$a]) Then ;if this line is used instead of the next, everything is fine If StringMid($ss, $b, 1) = $sx[$a] Then If StringMid($ss, $b, 1) = "x" Then ConsoleWrite("<<->>" & StringMid($ss, $b, 1) & " " & $sx[$a] & @CRLF) $flg = 1 ExitLoop EndIf Next If $flg = 0 Then $cn = $cn + 1 ReDim $sx[$cn] $sx[$cn - 1] = StringMid($ss, $b, 1) EndIf Next ConsoleWrite(UBound($sx) & @CRLF);list the ubound of $sx ;list what is in array $sx For $a = 0 To UBound($sx) - 1 ConsoleWrite($sx[$a] & @CRLF) Next same code in a file is attached as uniqueChar2Array.au3