Jump to content

Help with find value in array using another array as reference


Go to solution Solved by Subz,

Recommended Posts

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

2023-05-31_15-45-33.png.f582ca742c4bf66f21d548d60cd72c40.png

$mydata2

image.png.369b3b83eae4247215ddd1bbd9b5cd41.png

 

#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

  • Solution

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

 

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...