So I have the code below and it functions the way I want to, it's just a little slow. What I think is slowing it down is the string split into new lines creates a bunch of empty elements that all still get checked in the loop. I've tried to search and can't find anything to remove these to speed up the script. Any help would be appreciated. The purpose of the code is to just check to sets of numbers from different sources against each other and then pop up with a message of the missing elements
F5::
clipboard =
Clipsaved =
ClipNew =
sendinput,{control down}c
sleep,50
sendinput,{control up}
Clipwait
clipboard:= regexreplace(clipboard,"\D","`n")
vText := % clipboard
oArray := StrSplit(vText, "`n")
Haystack := drugset
Missed:= []
clipboard :=
Maxx := oArray.MaxIndex()
for index, element in oArray
{
Progress, %a_index%/%Maxx%,%a_index%/%Maxx%,%a_index%/%Maxx%
sleep,15
If InStr(Haystack, element)
{
}
Else
{
sleep,50
Missed.Push(element)
Clipsaved := % element
ClipNew=`n%ClipSaved%`n%clipboard%
clipboard = %ClipNew%
}
sleep,50
}
Progress,off
MsgBox,,Missed GPIs have been added to clipboard, % join(Missed)
join( strArray )
{
s := ""
for i,v in strArray
s .= ", " . v
return substr(s, 3)
}
return
I tried to do the oArray.Remove("") but that didn't do anything. Another thing I was thinking was that maybe there was a better way to create the array to begin with?
Thank you for looking
Remove empty elements from pseudoarray?
- jackdunning
- Posts: 126
- Joined: 01 Aug 2016, 18:17
- Contact:
Re: Remove empty elements from pseudoarray?
I could be wrong, but it seems that all the Sleep commands could be causing your script to slow down much more than the StrSplit() function. I don't see empty array elements alone slowing things down very much.
However, you could also use the Continue command to skip empty array elements in the For-loop.
However, you could also use the Continue command to skip empty array elements in the For-loop.
Jack Dunning
I have a passion for helping new users grow maniacal about AutoHotkey Windows scripting.
Jack's AutoHotkey Blog
Free AutoHotkey Scripts and Apps for Learning Script Writing and Generating Ideas
AutoHotkey Books
AutoHotkey Library Bundles
Jack's Motley Assortment of AutoHotkey Tips
I have a passion for helping new users grow maniacal about AutoHotkey Windows scripting.
Jack's AutoHotkey Blog
Free AutoHotkey Scripts and Apps for Learning Script Writing and Generating Ideas
AutoHotkey Books
AutoHotkey Library Bundles
Jack's Motley Assortment of AutoHotkey Tips
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Remove empty elements from pseudoarray?
remove all Sleep commands, what are they there for?
and this doesn't look right
and this doesn't look right
Code: Select all
If InStr(Haystack, element)
{
}
Else
Re: Remove empty elements from pseudoarray?
MThis doesn't look right either:
I believe that Functions should declared outside of SubRoutines... or maybe I've been doing this AHK thing all wrong. I also noticed some Assignments in Expression form := with a Forced Expression % which isn't needed with :=
Try this:
Code: Select all
join(strArray)
{
s := ""
for i,v in strArray
s .= ", " . v
return substr(s, 3)
}
return
Try this:
Code: Select all
F5::
clipboard := Clipsaved := ClipNew := ""
sendinput,{control down}c
sleep,50
sendinput,{control up}
Clipwait
clipboard := regexreplace(clipboard,"\D","`n")
vText := clipboard
oArray := StrSplit(vText, "`n")
Haystack := drugset
Missed:= []
clipboard :=
Maxx := oArray.MaxIndex()
for index, element in oArray {
Progress, %a_index%/%Maxx%,%a_index%/%Maxx%,%a_index%/%Maxx%
sleep,15
If InStr(Haystack, element)
Continue
Else {
sleep,50
Missed.Push(element)
Clipsaved := element
ClipNew=`n%ClipSaved%`n%clipboard%
clipboard = %ClipNew%
}
sleep,50
}
Progress,off
MsgBox,,Missed GPIs have been added to clipboard, % join(Missed)
return
join(strArray) {
s := ""
for i,v in strArray
s .= ", " . v
return substr(s, 3)
}
Re: Remove empty elements from pseudoarray?
This will read and write to the clipboard for every missing element. The clipboard is a lot slower than a regular variable.frexum wrote: ↑21 Nov 2018, 13:33Code: Select all
ClipNew=`n%ClipSaved%`n%clipboard% clipboard = %ClipNew%
It looks like you just want to find the lines that do not contain the number stored in 'drugset'. Perhaps you could just use RegExReplace to remove the undesired lines? (Instead of looping)
Edit
Updating the progress bar for every element may also be slowing you down. Updating that less often should speed things up a bit.Code: Select all
Progress, %a_index%/%Maxx%,%a_index%/%Maxx%,%a_index%/%Maxx%
not related to speed... and A.B. already mentioned it, but you can do this instead:Code: Select all
If InStr(Haystack, element) { } Else {...
Code: Select all
If !(InStr(Haystack, element)) ; if not in string
{
...
}
Re: Remove empty elements from pseudoarray?
Thank you everyone for all your comments. The adding sleep every few lines was probably a bad habit from starting programming. Removing all of those sped the code up a TON! I will work on your other suggestions. Thanks again!
Who is online
Users browsing this forum: Billykid, Google [Bot], haomingchen1998, mikeyww and 266 guests