object removeAt Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
noname
Posts: 406
Joined: 19 Nov 2013, 09:15

object removeAt

21 Nov 2017, 10:06

Image

To filter non existing files i used two different methods but i cannot find why one gives a wrong result (4 files ).
Is it allowed to store the result of the filtering in the same object name ?
m:=exist_mp3(m)

Code: [Select all] [Expand] [Download] (getfiles.ahk)GeSHi © Codebox Plus

User avatar
Capn Odin
Posts: 1273
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: object removeAt  Topic is solved

21 Nov 2017, 10:28

RemoveAt shifts the indexes which makes your loop miss certain indexes.

Code: [Select all] [Download] GeSHi © Codebox Plus

lst := StrSplit("abcdefghijklm")
bool := True

loop % lst.Length() {
MsgBox, % lst[A_Index]
if(bool := !bool) {
lst.removeat(A_Index)
}
}
Notice how at the end the message box is blank because it skipped some elements.

To solve this you will need to use your own index variable.

Code: [Select all] [Download] GeSHi © Codebox Plus

lst := StrSplit("abcdefghijklm")
bool := True
i := 1
loop % lst.Length() {
MsgBox, % lst[i]
if(bool := !bool) {
lst.removeat(i)
} else {
i++
}
}
Please excuse my spelling I am dyslexic.
User avatar
noname
Posts: 406
Joined: 19 Nov 2013, 09:15

Re: object removeAt

21 Nov 2017, 10:40

Thank you ,Capn Odin ,i would never have thought about that!

Can you take a look at this solution , using m to store the result is this allowed or could it produce side effects?

Code: [Select all] [Download] GeSHi © Codebox Plus

m:=exist_mp3(m)

exist_mp3(z){
x:={}
loop, % z.length()
if FileExist(z[A_Index])
x.push(z[A_Index])
return x
}


Thanks in advance.
User avatar
Capn Odin
Posts: 1273
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: object removeAt

21 Nov 2017, 10:42

It is fine to overwrite a variable with the result of a function on the same variable.
Please excuse my spelling I am dyslexic.
User avatar
noname
Posts: 406
Joined: 19 Nov 2013, 09:15

Re: object removeAt

21 Nov 2017, 11:05

Thanks :)

Return to “Ask For Help”

Who is online

Users browsing this forum: fun_9990, tarantules, Xeo786 and 51 guests