Jump to content

Faster search


Go to solution Solved by LionSin,

Recommended Posts

Hello everyone,

I have a question and I did strugle 1 week to try and solve it but I cannot figure it out.

Backstory

At work I have aloot of the same machines with complicated names : Siemens-0839378, We use a generic name so we don't remmember the exact name and numbers, something like S78T

Specific tools fit in specific machines, example, Tool number 873937398 only works on our S78T

I want to make a file.ini with all the complexe machine names and what tool works on it, I have the complete list of tools and machines.

 example :

 Siemens-0839378 - Tool number 873937398 - Tool number 783937399    <--- 2 or more different plates work on some machines.

 Siemens-0839377 - Tool number 873937397

So in a simple inputbox when I type in 873937398, I want to get a msgbox that says the machine it works on.

 

It's a head scratcher for me... 

I did find a solution but will take ages to do it that way

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Width=900, Height=150
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Siemens auto search","Please scan tool number or input manual",""," ","900","150","-1","-1")
Select
    Case @Error = 0 ;OK - The string returned is valid

    Case @Error = 1 ;The Cancel button was pushed

    Case @Error = 3 ;The InputBox failed to open

EndSelect
#EndRegion --- CodeWizard generated code End ---





If $sInputBoxAnswer = "873937351" Then

    #Region --- CodeWizard generated code Start ---
;SpashImage features: Title=Yes, Always On Top
$test = SplashImageOn("Compatible machine is ","C:\Capture.jpg","-1","-1","-1","-1",0)
Sleep(5000)
SplashOff()
#EndRegion --- CodeWizard generated code End ---


EndIf

So doing this for all 128 machines and 490 tools.. will take forever..

 

Thank you anticipated.

Link to comment
Share on other sites

How about your create a simple SQLite DB to manage this  (Table = Machine number , Tool number)

You could query in both direction -> What tools runs on a specific machine or What machines can take a specific tool.

 

Link to comment
Share on other sites

2 hours ago, LionSin said:

So doing this for all 128 machines and 490 tools.. will take forever..

Who holds the knowledge of these associations?

Just you, in your head?

Or is there a document or documents that contain it?

Once you have a document you could then write a load script, into SQLite as suggested by @Nine.

If it’s just in your head, then make a document to import.

Code hard, but don’t hard code...

Link to comment
Share on other sites

3 hours ago, LionSin said:

Siemens-0839378 - Tool number 873937398 - Tool number 783937399    <--- 2 or more different plates work on some machines.
Siemens-0839377 - Tool number 873937397


...128 machines and 490 tools.

So, you'll have a text file with 128 lines, right?  Each line contains the machine number plus the parts that work with that machine.  Then you just need the script to tell you which lines contain the number that you've entered into the input box.

Surely it would not take much time to read the 128 lines into an array and search the array one iteration at at time.  Then you'll end up with a list of lines containing the search term.  You just have to make sure you don't find one number inside another number (-:  Here's a quick view of what I mean:

$r = ""
$s = FileRead (FileOpen ("textfile.txt", 128))
$t = StringSplit ($s, @CRLF, 1)
$u = InputBox ("Type number...", "Type number of machine or part")
For $v = 1 to $t[0]
If StringInStr ($t[$v], $u) Then
$r = $r & $t[$v] & @CRLF & @CRLF
EndIf
Next
MsgBox (0, "Matching lines", $r, 0)

If your images have the same file names as the machine numbers, and if the machine numbers is always the first item on each line, and if the thing that delimits the machine numbers and part numbers is " - ", then you can e.g. replace the If-Then-EndIf with something crude like this:

If StringInStr ($t[$v], $u) Then
$x = StringSplit ($t[$v], " - ", 1)
$machinename = $x[1]
SplashImageOn ("Machine: " & $machinename, $machinename & ".jpg")
MsgBox (0, "Matching line", $t[$v], 0)
SplashOff ()
EndIf

Personally I would rather create an HTML page from the results, so that it opens in the browser, so you can include images of the tools and an image of the machine, and use coloured text to highlight useful content, etc.  MsgBox and SplashOn are quite limited.

PS. I get the impression from you post that when you say "faster search", you mean smaller script (i.e. less code).  Right?

Edited by leuce
Link to comment
Share on other sites

Post the file that contains the list of machine/tools would help us help you.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Well if your db looks as what you posted above but with much more entries

Siemens-0839378 - Tool number 873937398 - Tool number 783937399
Siemens-0839377 - Tool number 873937397

then try this, should work fast (db in script is this @ScriptDir & "\siemensdb.txt", change it)

; preset vars
Local $hOpen, $arSplitMachines[0], $sSearchForToolID = "", $arSplitTools[0], $sMachineID = ""
Local $sToolString = "Tool number ", $nToolStringLen = StringLen($sToolString)

; open and read the db to array
$hOpen = FileOpen(@ScriptDir & "\siemensdb.txt")
$arSplitMachines = StringSplit(FileRead($hOpen), @CRLF, 1)
FileClose($hOpen)

; ask for the tool id
$sSearchForToolID = InputBox("", "Search for Tool ID")
if @error Then Exit

; search db
For $i = 1 To $arSplitMachines[0]
    if $arSplitMachines[$i] = "" Then ContinueLoop

    ; create array containing each tool
    $arSplitTools = StringSplit($arSplitMachines[$i], ' - ', 1)

    ; if the machine has no tools continue with the next machine
    if $arSplitTools[0] < 2 Then ContinueLoop

    ; starting from index 2 because index 1 is the machine name
    For $iS = 2 To $arSplitTools[0]
        if $arSplitTools[$iS] = "" Then ContinueLoop

        ; check if queried element is a "Tool Number ", if not check next item
        if StringLeft($arSplitTools[$iS], $nToolStringLen) <> $sToolString Then ContinueLoop

        ; check if ID matches the search string
        if StringTrimLeft($arSplitTools[$iS], $nToolStringLen) = $sSearchForToolID Then
            $sMachineID = $arSplitTools[1]
            ExitLoop 2
        EndIf
    Next

Next

if $sMachineID = "" Then
    MsgBox(0, "", "Couldnt find")
Else
    MsgBox(0, "Found", $sMachineID)
EndIf

 

Link to comment
Share on other sites

  • 1 year later...
  • Solution

Sorry for maga late reply.

The issue was solved old school style.. 

Each tool was assigned a "" color "" and each station has a small card on it showing the colors that it can use.

Ex :  Siemens-0839378 <-- Machine has a "" pink "" card

Tools Have a pink strip on them. 

Tool number 873937398

Tool number 783937399

Thank you all for the suggestions and kind help.

 

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