Jump to content

Recommended Posts

Posted

Gday,

I wondered if anyone can give me a little nudge in the right direction here :)

I need to sort out something, but so far ( goofing with the prog's help files and forum a bit ) I cant get any further then deleting duplicate strings from 1 text file and I managed to to merge all text files in one dir and take the duplicates out. Works like a charm, but it's not what I'm looking for.

I need to sort out several list of tools depending on the kind a work a person needs to do.

Lets say the first four list (.txt files where each tool is on a new line) are:

1.txt =

A

B

C

D

2.txt =

C

D

E

F

3.txt =

E

F

G

H

4.txt =

G

H

I

J

Where each char stand for a different tool. It has to be dynamic where values can be entered in a GUI, but I'm trying to get a static example first,

Lets say someone has tools from 1.txt, 2.txt and 3.txt and for his next assignment he doesn't need 3.txt anymore but needs tools from 1.txt, 2.txt and 4.txt.

My thought is I need to merge 1 2 and 3 in one file/value and delete the duplicates so I can see what he has now (ReadToArray, Unique,WriteFromArray etc )

Then I would have A B C D E F G H as inventory

Now the trouble begins : / Then I need to delete values from 3.txt ,( problem here is E F would also be in 2.txt so I cant delete those.) so it should leave A B C D E F.

Now I should be able to get this value and use ReadToArray, Unique,WriteFromArray etc to add 4.txt and delete any duplicates. So we would end with A B C D E F G H I J

Any Idea's ?

Greetings -C-

Posted

Hi 'C.'

Sounds a bit weird. Why do you have to have the seperated lists with their repeated values in the first place?

And then: The whole thing smells like a task for the embedded SQLite, doesn't it?

It's certainly possible to sort it out with arrays (merging, sorting, comparing each item with its successor, delete if equal) but that doesn't really smell sensible.

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Posted

Hi 'C.'

Sounds a bit weird. Why do you have to have the seperated lists with their repeated values in the first place?

And then: The whole thing smells like a task for the embedded SQLite, doesn't it?

It's certainly possible to sort it out with arrays (merging, sorting, comparing each item with its successor, delete if equal) but that doesn't really smell sensible.

Every list contains tools for a different assigment, Employees pick up these tools before going to work.

I someone has four different assignments he/she will get the tools from four lists. If there is a nanometer in every list they will "theoretically" recieve four nanometers, and that would be a waste of tools, time and space.

Thats why I want to filter the repeated values out. So they recieve only what they need. and only have to return what they don't need for the next day.

Since my SQL skills stink, i avoided it. But I'm gonne give it a go anyway :)

Tnx

-C-

  • 2 weeks later...
Posted

How do you sort out the duplicates of 1 .txt file?

Thanks, Reinn! :)

Try something like

$Array1 = FileReadToArray($somefile)
$array1 = _ArrayUnique($Array1)
_ArrayDelete($Array2,0)
FileWriteToArray($somefile,$Array2)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
  • 3 weeks later...
Posted

So here's my nudge. . .

An array of all available tools where each element is set to a '0' value. Read the required tool list and increment the value of the required elements. Print out a list of all non-0 values. This will make your list. For jobs that require two of the same tool (i.e. 7/16 box wrench), your elements would need to have both listed.

Posted

Hello, MisterC

Dictionaries can be helpful here.

#Region ============== FUNCTIONS ==============

; This function is only a stub for FileRead.
; It mimics what FileRead would return if the
; four text files actually existed on the system.
Func MockFileRead( $sPath ) 
    Switch $sPath
        Case "1.txt" 
            return StringSplit( "ABCD", "", 2 )
        Case "2.txt" 
            return StringSplit( "CDEF", "", 2 )
        Case "3.txt" 
            return StringSplit( "EFGH", "", 2 )
        Case "4.txt"
            return StringSplit( "GHIJ", "", 2 )     
    EndSwitch
EndFunc

Func AddUniqueToolsToToolBox( $arrTools, ByRef $dctToolBox )
    For $tool in $arrTools
        If Not ( $dctToolBox.Exists( $tool )) Then
            $dctToolBox.Add( $tool, "" )
        EndIf
    Next
EndFunc

Func DumpToolBox( $dctToolBox )
    For $key in $dctToolBox.Keys
        ConsoleWrite( $key )
    Next
    ConsoleWrite( @CRLF )
EndFunc

#EndRegion
;

; ============== MAIN ==============
Dim $dctProjectToolBox      = ObjCreate( "Scripting.Dictionary" ) 

Dim $arrToolsInFileOne      = MockFileRead( "1.txt" )
Dim $arrToolsInFileTwo      = MockFileRead( "2.txt" )
Dim $arrToolsInFileThree    = MockFileRead( "3.txt" )

AddUniqueToolsToToolBox( $arrToolsInFileOne, $dctProjectToolBox )
AddUniqueToolsToToolBox( $arrToolsInFileTwo, $dctProjectToolBox )
AddUniqueToolsToToolBox( $arrToolsInFileThree, $dctProjectToolBox )

DumpToolBox( $dctProjectToolBox )   ; Console: ABCDEFGH 

Dim $arrToolsInFileFour     = MockFileRead( "4.txt" )
AddUniqueToolsToToolBox( $arrToolsInFileFour, $dctProjectToolBox )

DumpToolBox( $dctProjectToolBox )   ; Console: ABCDEFGHIJ

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