Jump to content

Recommended Posts

Hi All,

 

So I found this fantastic search function by @SmOke_N. It works as I wanted it to.

Can be found here: 

However, I find it to be abit slow... My "Search" file has over 100 lines and about 8 columns. 
Can this be optimised? Or is there a quicker method to search for a value in one folder then msgbox the value (result).
I tried an ArraySearch at first but I kept getting Error -1 ... I used it in a For _ Next loop like this:
 

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

Local $aArray[6][4]
Local $ArrayList
For $i = 0 To 5
    For $j = 0 To 3
        $aArray[$i][$j] = "Num" & $i & "." & $j
    Next
Next
_ArrayDisplay($aArray, "Looking for 'Num3.2'", Default, 8)
$FilePath = ("C:\Temp\Array.txt")
_FileWriteFromArray($FilePath,$aArray,Default,Default,",")
Local $list
_FileReadToArray($FilePath, $ArrayList, $FRTA_NOCOUNT, ",")

; Search by column (looking in col 2)
Local $iRow = _ArraySearch($ArrayList, "Num3.2", 0, 0, 0, 0, 1, -1, False) ; Search per row
MsgBox(-1, "$iRow", $iRow)
Local $iColumn = _ArraySearch($ArrayList, "Num3.2", 0, 0, 0, 0, 1, -1, True) ; Search per Column
MsgBox(-1, "$iRow", $iColumn)

MsgBox($MB_SYSTEMMODAL, "Found 'Num3.2'", "Tthe value is  " & $ArrayList[$iRow][$iColumn + 1])

No this bit of code works, but when I used my original file, It could not search up for the values. 
Anyways, main question is to optimise the _VLookUpAut function.. 

 

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Link to post
Share on other sites

In _ArraySearch you may need to adjust the $iCompare to get the correct result, when you've read your "original file" there might be hidden characters etc... which can cause the search to fail, try using partial or regex.

Link to post
Share on other sites

Like I already told you here, you should not parse the whole array after first finding the row (see example below to note how fast it is)

Also, using Case Sensitive search, will slightly accelerate the search.

Now, if you do not find the correct cell, you will have to understand why.  You should look inside the cells using Binary function to examine if there is hidden characters like @Subz suggested.  Then act appropriately. 

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

Local $aArray[500][8]
Local $ArrayList
For $i = 0 To UBound($aArray, 1) - 1
    For $j = 0 To UBound($aArray, 2) - 1
        $aArray[$i][$j] = "Num" & $i & "." & $j
    Next
Next
_ArrayDisplay($aArray, "Looking for 'Num3.2'", Default, 8)
$FilePath = ("Array.txt")
_FileWriteFromArray($FilePath,$aArray,Default,Default,",")
Local $list
_FileReadToArray($FilePath, $ArrayList, $FRTA_NOCOUNT, ",")

Local $hTimer = TimerInit()
Local $iRow = _ArraySearch($ArrayList, "Num3.2", 0, 0, 0, 0, 1, -1, False) ; Search per row
ConsoleWrite(TimerDiff($hTimer) & @CRLF)

Local $hTimer = TimerInit()
Local $iRow = _ArraySearch($ArrayList, "Num3.2", 0, 0, 1, 0, 1, -1, False) ; Search per row
ConsoleWrite(TimerDiff($hTimer) & @CRLF)

Local $hTimer = TimerInit()
Local $iColumn = _ArraySearch($ArrayList, "Num3.2", 0, 0, 1, 0, 1, $iRow, True) ; Search per Column
ConsoleWrite(TimerDiff($hTimer) & @CRLF)
MsgBox(0, "Location", $iRow & "/" & $iColumn)

 

Link to post
Share on other sites

@Nine , slow down buddy.. This topic was about optimisation.. the other topic was about "how to"... 
Now, take the script you provided in the other topic.. it's good but did not provide the result I wanted... it only provided the result as 3/2 ... where I needed the result as #32.

What I didn't mention and come back to you about was I found a solution after many hours searching, that's my fault. 

So the ArraySearch works. Flawless... When I posted this topic about optimisation, I realised something and went back to the drawing board... 

Read a few other topics and found the issue. @Nine appreciate the help on both topics... 

Where was the issue you say??? well it was in the "original file".. 
How did I figure it out?? Solution was to use Notepad++ use to check hidden symbols.. 

I got that original file corrected... 

Again, thanks @Nine for the help.. my main problem is sometimes I need to break away from staring at the code for hours, and when I do , I need to talk to someone and then it becomes an Eureka moment.... that's why I created these topics.. 

 

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...