Problem with If InStr() Topic is solved
Problem with If InStr()
Hello!
I have a problem with:
If InStr(var2, var1)
My vars and matches are like this:
var1 := a
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
Second case is:
var1 := abab
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
The second var (var2) as the Msgbox display it is a list right?
how can i match only this:
var1 := a
var2 := a
b
e
aaaa
abab baba
aebaeb
bbbb aaaa
eeee
Second case:
var1 := abab
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
Please help.
Thank you!
I have a problem with:
If InStr(var2, var1)
My vars and matches are like this:
var1 := a
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
Second case is:
var1 := abab
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
The second var (var2) as the Msgbox display it is a list right?
how can i match only this:
var1 := a
var2 := a
b
e
aaaa
abab baba
aebaeb
bbbb aaaa
eeee
Second case:
var1 := abab
var2 := a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
Please help.
Thank you!
Re: Problem with If InStr()
Post your actual script. Below is one way to assign variables to a continuation section.
Explained: Continuation section
Code: Select all
var2 =
(
a
b
e
aaaa
abab
ababab
ababab baba
aebaeb
bbbb
eeee
)
Re: Problem with If InStr()
Here it is.
The base code is not mine, so i am going blind here.
The base code is not mine, so i am going blind here.
Code: Select all
#NoEnv
#SingleInstance, force
SetBatchLines, -1
<!a::
folderpath := "C:\Users\Stem75\Desktop\Clipboard_to_folder_name\"
;loop, Parse, folderpath
objWShell := ComObjCreate("WScript.Shell")
objFSO := ComObjCreate("Scripting.FileSystemObject")
objFolder := objFSO.GetFolder(folderpath)
objSubFolders := objFolder.SubFolders
For folder in objSubFolders
Folders .= Folder.name "`n"
ars := Folders
Folders := ""
ers := Clipboard ; Save the entire clipboard to a variable.
MsgBox % Folders
MsgBox % ars
MsgBox % ers
If InStr(ars, ers)
{
MsgBox, The string was found
If ( SubStr( Folders, 9, 4 ) + 1 > numb )
numb := SubStr( Folders, 9, 4 )
numb := SubStr("0000" (numb+1), -3)
StringReplace, Clip, Clipboard, `r`n, `n, all
FileCreateDir, C:\Users\Stem75\Desktop\Clipboard_to_folder_name\%clipboard%%numb%
}
Else
{
MsgBox, The string was not found
FileCreateDir, C:\Users\Stem75\Desktop\Clipboard_to_folder_name\%clipboard%
}
Exit
Re: Problem with If InStr() Topic is solved
Code: Select all
find = a
str =
(
aaaa
a
b
e
aaaa
abab baba
aebaeb
bbbb aaaa
eeee
)
MsgBox, 64, Position, % pos := lineInstr(str, find)
lineInstr(str, find) {
Return Instr("`n" str "`n", "`n" find "`n")
}
Re: Problem with If InStr()
Is this applicable to my script or is it theory?
should i replace something or paste it somewhere?
When i hit run it gives me 6 i don't understand how to use this, sorry.
But thank you for your replay. If you can give me a better example or explanation i'll be thankful because i am on baby steps here.
should i replace something or paste it somewhere?
When i hit run it gives me 6 i don't understand how to use this, sorry.
But thank you for your replay. If you can give me a better example or explanation i'll be thankful because i am on baby steps here.
Re: Problem with If InStr()
I was actually working with your original post. Instead of Instr, you could try lineInstr, and put that function definition (lines 16-18) at the bottom of your script. If you have trouble, feel free to describe it here.
Re: Problem with If InStr()
AAAAAAAHHH!!!
All right i get it. Thank you it works.
This is the script for anyone who wants to use it for creating folders from clipboard.
All right i get it. Thank you it works.
This is the script for anyone who wants to use it for creating folders from clipboard.
Code: Select all
#NoEnv
#SingleInstance, force
SetBatchLines, -1
<!a::
folderpath := "C:\Users\Stem75\Desktop\Clipboard_to_folder_name\"
;loop, Parse, folderpath
objWShell := ComObjCreate("WScript.Shell")
objFSO := ComObjCreate("Scripting.FileSystemObject")
objFolder := objFSO.GetFolder(folderpath)
objSubFolders := objFolder.SubFolders
For folder in objSubFolders
Folders .= Folder.name "`n"
ars := Folders
Folders := ""
ers := Clipboard ; Save the entire clipboard to a variable.
MsgBox % ers
MsgBox % ars
If Instr("`n" ars "`n", "`n" ers "`n")
{
MsgBox, The string was found
If ( SubStr( Folders, 9, 4 ) + 1 > numb )
numb := SubStr( Folders, 9, 4 )
numb := SubStr("0000" (numb+1), -3)
StringReplace, Clip, Clipboard, `r`n, `n, all
FileCreateDir, C:\Users\Stem75\Desktop\Clipboard_to_folder_name\%clipboard%%numb%
}
Else
{
MsgBox, The string was not found
FileCreateDir, C:\Users\Stem75\Desktop\Clipboard_to_folder_name\%clipboard%
}
Exit
Re: Problem with If InStr()
Could you use %userprofile% rather than hardcoding Stem75 ?
So much universe, and so little time. GNU Sir Terry.
Re: Problem with If InStr()
Yes, better to just use A_Desktop in place of all of C:\Users\Stem75\Desktop, but there is a built-in variable for just the username: A_UserName
Re: Problem with If InStr()
And can you use A_Desktop and add the \Clipboard_to_folder_name\ in the end?boiler wrote: ↑20 Jan 2022, 17:09Yes, better to just use A_Desktop in place of all of C:\Users\Stem75\Desktop, but there is a built-in variable for just the username: A_UserName
or A_UserName and add the \Clipboard_to_folder_name\ in the end?
Re: Problem with If InStr()
Yes. Like this:
Code: Select all
folderpath := A_Desktop "\Clipboard_to_folder_name\"
If you use this, then it would be:
Code: Select all
folderpath := "C:\Users\" A_UserName "\Desktop\Clipboard_to_folder_name\"
The biggest advantage to A_Desktop is it works no matter what drive the user might have his/her desktop folder located.
Re: Problem with If InStr()
Hmmm!!! That was a lesson.
And a nice tip in the end. To tell you the truth, i never thought that someone would have the desktop in an other drive.
And a nice tip in the end. To tell you the truth, i never thought that someone would have the desktop in an other drive.
Re: Problem with If InStr()
Would recommend a different argument order. lineInStr(haystack, needle) follows ahk conventions and order of importance.mikeyww wrote: ↑20 Jan 2022, 12:43Code: Select all
lineInstr(str, find) { Return Instr("`n" str "`n", "`n" find "`n") }
For the OP I think you may want to learn arrays soon, as newline separated lists/strings aren't the easiest to work with.
Code: Select all
A := new biga() ; requires https://www.npmjs.com/package/biga.ahk
array := ["aaaa", "a", "b", "e", "aaaa", "abab"]
msgbox, % A.includes(array, "abab")
; => true
msgbox, % A.indexOf(array, "abab")
; => 6
https://biga-ahk.github.io/biga.ahk/#/?id=indexof
Re: Problem with If InStr()
I think i made it better.
Code: Select all
; Quick make folders (semi-sequential) from Clipboard - Stem75
#NoEnv
#SingleInstance, force
SetBatchLines, -1
MyLabel:
<!a:: ; shortcut key ( alt+A )
folderpath := "C:\Test"
objWShell := ComObjCreate("WScript.Shell")
objFSO := ComObjCreate("Scripting.FileSystemObject")
objFolder := objFSO.GetFolder(folderpath)
objSubFolders := objFolder.SubFolders
For folder in objSubFolders
Folders .= Folder.name "`n"
fff := Folders
Folders := ""
ccc := Clipboard
nnnnnn := Min(SubStr( nnn, -3)) ; This i think you can also put it as SubStr( nnn, -3)
If nnnnnn is Number
{
numb := Format("{:04}", nnnnnn+1) ; or SubStr("0000" (numb+1), -3)
}
Else
{
numb := 0000
}
If Instr("`n" fff "`n", "`n" ccc "`n")
{
FileCreateDir, C:\Test\%clipboard% %numb%
nnn = %clipboard% %numb%
nnnnnn =
numb =
}
Else
{
FileCreateDir, C:\Test\%clipboard%
nnn = %clipboard%
nnnnnn =
numb =
}
If Instr("`n" fff "`n", "`n" nnn "`n")
{
MsgBox 8213, Clipboard to quick Folder, %nnn%`nFolder allready exists
IfMsgBox Retry
Goto MyLabel
IfMsgBox Cancel
Exit
}
Exit