kemo1987 Posted May 31, 2023 Share Posted May 31, 2023 Hello, i have 2 arrays $mydata & $mydata2 i want to search on $mydata with code and if the code exist insert offer price to Col4 here what i have done but with no luck with looping it using $mydata2 array values For $i = UBound($mydata) - 1 To 1 Step -1 If Number($mydata[$i][0]) = 33004 Then $mydata[$i][4]=10000 Next Thanks alot $mydata $mydata2 expandcollapse popup#region --- Internal functions Au3Recorder Start --- Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) EndFunc #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include<file.au3> #include <INet.au3> ; needed for get source (hmtl) #include <String.au3> ; needed for stringbetween #include<Array.au3> ; #include <Date.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> #include <File.au3> #include <Array.au3> #include <OutlookEX 1.7.0.1/OutlookEx.au3> HotKeySet("{DEL}", "_Quit") ; quit option = DEL ;==================================== Global $brname="agouza" Global $htfilename="agouzaold.htm" Global $exfilename= "agouzaold.xls" Global $path = "D:\Desktop\Autoit project\" ;==================================== _movetosheet() Func _movetosheet() Local $oExcel =_Excel_Open() $datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\agouzaold.xls") $datawb.worksheets("agouzaold").select $LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count $mydata = _Excel_RangeRead($datawb, Default, Default ) _ArrayColDelete($mydata, 0) _ArrayColDelete($mydata, 0) _ArrayColDelete($mydata, 1) _ArrayColDelete($mydata, 1) _ArrayColDelete($mydata, 1) _ArrayColDelete($mydata, 2) _ArrayColDelete($mydata, 3) _ArrayColDelete($mydata, 3) _ArrayColDelete($mydata, 3) _ArrayColDelete($mydata, 3) _ArrayColDelete($mydata, 3) _ArrayColDelete($mydata, 4) _ArrayColDelete($mydata, 4) _ArraySwap($mydata, 0, 2, True) _ArraySwap($mydata, 0, 1, True) _ArraySwap($mydata, 0, 3, True) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, 0) _ArrayDelete($mydata, UBound($mydata) - 1) _ArrayDelete($mydata, UBound($mydata) - 1) _ArrayColInsert($mydata, 4) _Excel_BookClose($datawb) sleep(1000) Local $oExcel =_Excel_Open() $datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\Data\Offers.xlsx") $datawb.worksheets("Sheet1").select $LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count $mydata2 = _Excel_RangeRead($datawb, Default, Default ) _ArrayColDelete($mydata2, 3) _Excel_BookClose($datawb) sleep(1000) If IsArray($mydata2) Then _ArrayDisplay($mydata2) ;--------------------------------------------------------- ;-----Here For $i = UBound($mydata) - 1 To 1 Step -1 If Number($mydata[$i][0]) = 33004 Then $mydata[$i][4]=10000 Next ;-------------------------------------------------------------- For $i = UBound($mydata) - 1 To 1 Step -1 If Number($mydata[$i][3]) = 0 Then _ArrayDelete($mydata, $i) Next Local $filea = @ScriptDir & "\inc\snagouza.txt" Local $filesn _FileReadToArray($filea, $filesn) For $i = 1 To UBound($filesn) - 1 For $j = UBound($mydata) - 1 To 1 Step -1 If Number($mydata[$j][0]) = $filesn[$i] Then _ArrayDelete($mydata, $j) EndIf Next Next ;-------------------------------- If IsArray($mydata) Then _ArrayDisplay($mydata) EndFunc Link to comment Share on other sites More sharing options...
Solution Subz Posted May 31, 2023 Solution Share Posted May 31, 2023 Try looping within a loop or you could try _ArrayFind function ;~ Loop through $mydata2 For $i = 1 To UBound($mydata2)-1 If StringStripWS($mydata2[$i][0],7) = "" Then ContinueLoop ;~ Loop through $mydata For $j = 1 To UBound($mydata)-1 ;~ Check if $mydata[x][column 0] = $mydata2[x][column 0] and set $mydata[x][column 4] to $mydata2[x][column 1] If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2,7) Then $mydata[$j][4]=$mydata2[$i][1] Next Next kemo1987 and SkysLastChance 2 Link to comment Share on other sites More sharing options...
kemo1987 Posted June 1, 2023 Author Share Posted June 1, 2023 19 hours ago, Subz said: Try looping within a loop or you could try _ArrayFind function ;~ Loop through $mydata2 For $i = 1 To UBound($mydata2)-1 If StringStripWS($mydata2[$i][0],7) = "" Then ContinueLoop ;~ Loop through $mydata For $j = 1 To UBound($mydata)-1 ;~ Check if $mydata[x][column 0] = $mydata2[x][column 0] and set $mydata[x][column 4] to $mydata2[x][column 1] If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2,7) Then $mydata[$j][4]=$mydata2[$i][1] Next Next unfortunately, it didnt work with me No errors but it doesnt insert price value to col4 Link to comment Share on other sites More sharing options...
Nine Posted June 1, 2023 Share Posted June 1, 2023 (edited) There is a bug in @Subz code. Replace If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2,7) Then $mydata[$j][4]=$mydata2[$i][1] with If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2[$i][0],7) Then $mydata[$j][4]=$mydata2[$i][1] Edited June 1, 2023 by Nine kemo1987 and Subz 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
kemo1987 Posted June 1, 2023 Author Share Posted June 1, 2023 1 hour ago, Nine said: There is a bug in @Subz code. Replace If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2,7) Then $mydata[$j][4]=$mydata2[$i][1] with If StringStripWS($mydata[$j][0],7) = StringStripWS($mydata2[$i][0],7) Then $mydata[$j][4]=$mydata2[$i][1] Thanks alot it work perfect ❤️ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now