Identify duplicates in .ini to stop script [infor] Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Identify duplicates in .ini to stop script [infor]

Post by Fisatec » 28 Sep 2022, 07:51

Hi @all,
At the moment I am trying to get a script working, which continuously numbers one determined column in a table.
This script should stop at any cell in this column containing the value 99 or at the last cell in this column.

Unfortunately I don't know, how to tell the script, that it reached the last cell, if there is no cell containing the value 99.

I was thinking about writing down any copied numbers in an .ini-file and check them for duplicates.
When the first duplicate is detected, the script should be stopped.

Code: Select all

#Space::
#IfWinActive ahk_class Infor ERP COM Produktion 
{ 
IniDelete, % A_ScriptDir "\count.ini", Reihenfolge
	
    Loop 
	{
	clipboard:=""
    Send ^c
    ClipWait
	IniWrite, % Clipboard, % A_ScriptDir "\count.ini", Reihenfolge
	IniRead, Zahl, % A_ScriptDir "\count.ini", Reihenfolge
	
	    If (clipboard < 99) 
	    {
	    clipboard:=""
	    Send {UP}
	    Send ^c
        ClipWait
	    x := Clipboard
	    x++	
	    Send {DOWN}{LEFT}{Enter}{LEFT}
        Send %x%
	    Send {DOWN}{LEFT}{Enter}{LEFT}
	    clipboard:=""
	    }
	
	    Else 
		{
	    Sleep 1000
	    ExitApp
	    }
    }  

}
One video shows a column with cells containing 99 and the other video shows my problem, when there are no cells containing the value 99.

https://www.veed.io/view/0e1a3c79-b1af-497d-9595-5a834c6d4983/showcase?sharingWidget=true
https://www.veed.io/view/c105d08f-1676-490b-954e-388f0d499bb9/showcase?sharingWidget=true


Best regards
Fisatec

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Identify duplicates in .ini to stop script [infor]

Post by Rohwedder » 28 Sep 2022, 10:30

Hallo,
perhaps:

Code: Select all

#IfWinActive ahk_class Infor ERP COM Produktion
#Space::
Reihenfolge := "|" ;initializes string Reihenfolge
Loop
{
	clipboard := ""
	Send ^c
	ClipWait
	Zahl := Trim(ClipBoard)
	IF (Zahl = 99) Or (Zahl = "")
		Break
	IF Instr(Reihenfolge, "|" Zahl "|")
		Break ;duplicate
	Reihenfolge .= Zahl "|" ;Stores Zahl in string Reihenfolge
	; ...
}
Return

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Identify duplicates in .ini to stop script [infor]

Post by Fisatec » 29 Sep 2022, 01:15

Hey @Rohwedder ,
I do not fully understand your posted Code.

Code: Select all

IF (Zahl = 99) Or (Zahl = "")
It is not possible to select an empty Cell. If the last cell in column is selected and DOWN is pressed, this selected cell will just stay selected instead of selecting the empty cell below.
So it is not possible to stop the script by empty clipboard.

That's why I want to check the .ini for duplicates and then force the script to stop.

There are values of both .ini's attached. The first .ini shows the correct values, when counting stops at cell with value 99.
Reihenfolge_1.jpg
Reihenfolge_1.jpg (8.75 KiB) Viewed 354 times
The second one shows a theoretically endless loop, when there is no cell containing the value 99, exiting the script manually
Reihenfolge_2.jpg
Reihenfolge_2.jpg (8.99 KiB) Viewed 354 times
Best regards
Fisatec

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Identify duplicates in .ini to stop script [infor]  Topic is solved

Post by Rohwedder » 29 Sep 2022, 01:43

I understand, since your table does not contain duplicates, a copied duplicate means the end of the column. But what I don't understand, why do you want to work with ini-files? In the following script all already copied "Zahl"s are entered in the string "Reihenfolge" and thus duplicates are recognized and break the loop:

Code: Select all

#IfWinActive ahk_class Infor ERP COM Produktion
#Space::
Reihenfolge := "|" ;initializes string Reihenfolge
Loop
{
	clipboard := ""
	Send ^c
	ClipWait
	Zahl := Trim(ClipBoard)
	IF (Zahl = 99) Or InStr(Reihenfolge, "|" Zahl "|")
		Break
	Reihenfolge .= Zahl "|" ;Stores Zahl in string Reihenfolge
	; ...
}

Code: Select all

Reihenfolge = |7|18|24|1|8|33|
Zahl = 4
MsgBox,% Instr(Reihenfolge, "|" Zahl "|") ;0 : (False), means no duplicate
Zahl = 18
MsgBox,% Instr(Reihenfolge, "|" Zahl "|") ;3 : (!False) , means duplicate

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Identify duplicates in .ini to stop script [infor]

Post by Fisatec » 29 Sep 2022, 03:16

Thank you very much, the script is working perfect now :)

Post Reply

Return to “Ask for Help (v1)”