Jump to content

Return Row of _Arraysearch


Recommended Posts

I am not exactly sure if I am approaching this correctly but here it is...

 

I have a table like this like this which I write to an array:

 

Column 1     Column 2

03/15/2012   TOT-TRF 

12/22/2011   TOT-TRF  

04/28/2011   TOT-TRF   

02/13/2007   CON-POS  

11/09/1998   TOT-CNV 

07/21/1998   TOT-CNV 

01/07/1998   TOT-CNV

 

I was using arraysearch to find "TOT-TRF" Which I was able to do successfully... but need to check the date in column 1 to see if it is after 2010 and if so it will trigger an action. I was thinking of a few different methods but not sure which is the best way to approach it.  I know if I could get the row that "TOT-TRF" is in then I could check the first column to see if it is greater than 2010.  To try to prevent any confusion I wont go into the other methods I had in mind unless it comes to that point and no one can help with what I have provided.

 

Not sure how helpful this will be but here is some of the code

$oEventgTable               = _IETableGetCollection($oPhObj2, 3)
$oEventgTable2              = _IETableWriteToArray($oEventgTable, True)
_arraydisplay($oEventgTable2)

$DateoD = _ArraySearch($oEventgTable2, "TOT-TRF",0,0,0,0,1,1)
msgbox(0,"",$DateoD)
if not @error Then
   $p11 = 1
   Else
   $p11 = 0
EndIf
I have to check a lot of these tables so I am trying to do this the quickest way possible.  Thanks ahead of time for any suggestions! Edited by blkshadow82
Link to comment
Share on other sites

Hi,

Don't use the _ArraySearch function, it's limited to search in one column.

Make your own search like this :

;... _IE* functions here.
 
Local $iFoundIndex = -1
 
For $i = 0 To UBound($oEventgTable2) -1
    If $oEventgTable2[$i][1] <> "TOT-TRF" Then ContinueLoop
 
    ;we found TOT-TRF, now check the year if upper than 2010 (after 2010??)
    If Number(StringRight($oEventgTable2[$i][0], 4)) > 2010 Then
        $iFoundIndex = $i
        ExitLoop
    EndIf
Next
 
If $iFoundIndex > -1 Then
    ConsoleWrite("Record found at the index: " & $i & @CrLf)
EndIf

Br, FireFox.

Link to comment
Share on other sites

I know that functions like the arraybinarysearch said that it was faster.

This algorithm works only on a sorted array.

Yours is sorted by date, but the first thing you're searching for is not sorted so you can't apply the algorithm on it.

Br, FireFox.

Link to comment
Share on other sites

yea that's kind of what I thought. One more thing. I need my script to check if there are these values as well: "TRA-ADD" "PRT-DOD" "PRT-HCD" I tried adding them like this If $oEventgTable2[$r][1] <> "TOT-TRF" or "TRA-ADD" or "PRT-DOD" or "PRT-HCD" Then ContinueLoop

It didn't seem to work. It seemed to skip all of them. Is there a better way to do this then doing a loop for each individual value?

and thanks FireFox for all your help so far.

Link to comment
Share on other sites

If $oEventgTable2[$r][1] <> "TOT-TRF" or "TRA-ADD" or "PRT-DOD" or "PRT-HCD" Then ContinueLoop
;is (because a string is 0 converted to expression)
If $oEventgTable2[$r][1] <> "TOT-TRF" or 0 or 0 or 0 Then ContinueLoop
;result can be (if $oEventgTable2[$r][1] = "TOT-TRF")
If 1 or 0 or 0 or 0 Then ContinueLoop ;True
;or (if $oEventgTable2[$r][1] <> "TOT-TRF")
If 0 or 0 or 0 or 0 Then ContinueLoop ;False

;should be
If $oEventgTable2[$r][1] <> "TOT-TRF" Or $oEventgTable2[$r][1] <> "TRA-ADD" Or $oEventgTable2[$r][1] <> "PRT-DOD" Or $oEventgTable2[$r][1] <> "PRT-HCD" Then ContinueLoop
All clear? :)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

oh yea forgot that minor detail.. But for some reason it is still skipping all of them.... It works fine when I only use one variable. I have a ton of if thens and loops so maybe I am doing something wrong somewhere else.. I'll try to figure it out. Thanks Firefox

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...