Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InStr() function missing parameters #263

Closed
xzeroun opened this issue Nov 8, 2022 · 7 comments · Fixed by #264
Closed

InStr() function missing parameters #263

xzeroun opened this issue Nov 8, 2022 · 7 comments · Fixed by #264
Assignees
Labels
bug something isn't working

Comments

@xzeroun
Copy link

xzeroun commented Nov 8, 2022

Description

When using InStr() function as the AHK documentation suggests, the AHK++ extension seems to have missed a parameter that is important to my code which is the occurrence parameter.

AHK Docs: InStr(Haystack, Needle , CaseSensitive := false, StartingPos := 1, Occurrence := 1)
AHK++ : InStr(Haystack, Needle [, CaseSensitive?, StartingPos])

Reproduction steps

Steps to reproduce the behavior:

Use AHK++ and try to set an occurrence parameter. Example code given below:

File = "C:\Test\Test\Test.txt"
var := StrSplit(File, "backslash")
MsgBox % var.count()
pos := InStr(File, "backslash",False, 1, var.count())
MsgBox % pos

Expected behavior

It should provide the character position in a string based on the var.count() result, which would be the last "" within the string's name.

Additional context

@xzeroun xzeroun added the bug something isn't working label Nov 8, 2022
@fade2gray
Copy link

InStr(Haystack, Needle [, CaseSensitive?, StartingPos]) requires a maximum of 4 parameters, and you are providing 5.

Try, pos := InStr(File, "", , var.count()).

@xzeroun
Copy link
Author

xzeroun commented Nov 8, 2022

Maybe I didn't make it clear enough. The basic InStr function from AHK uses 5 parameters. I need that 5th parameter for occurrence. StrSplit only provides me a way to get the count of the last backslash in a file path, not the position of that backslash within the string. So it tells me there are X amount of backslashes which I want to use var.count() because it gives me the last occurrence. Then I use pos := InStr(File, "backslash", False, 1, var.count()) to get the position of that last backslash.

My primary issue is that Ahk++ doesn't have the 5th parameter that AHK has by default. Does that make more sense?

@fade2gray
Copy link

fade2gray commented Nov 8, 2022

You have your start position and occurrence parameters in the wrong positions.

pos := InStr(File, "",,var.count(), 1)

See example #3.

And yes, the autocomplete is missing the 5th parameter.

@xzeroun
Copy link
Author

xzeroun commented Nov 8, 2022

InStr(Haystack, Needle , CaseSensitive := false, StartingPos := 1, Occurrence := 1) ????

The filepath can be 100 characters long, if I run a StrSplit(File, "backslash") its only going to return 4 or 5 even though the last backslash is going to be maybe character number 70 in the string. Please run my example code, it will maybe give you clarity to what Im asking for.

Regardless though, I can make this work in AHK Studio or Scite, its simply that Ahk++ doesn't pass through the occurence parameter all together.

@fade2gray
Copy link

fade2gray commented Nov 8, 2022

You have your start position and occurrence parameters in the wrong positions.

File = "C:\Test\Test\Test.txt"
var := StrSplit(File, "\")
MsgBox % var.count()
pos := InStr(File, "\",False, var.count(), 1)
MsgBox % pos

@fade2gray
Copy link

Scrap that.
Try, pos := InStr(File, "\",,1, var.count()-1)

var.count() gives you the number of strings that File is split into, not the number of backslashes.

@xzeroun
Copy link
Author

xzeroun commented Nov 8, 2022

Ahh... that was it the -1, well darn. I do believe the tab complete parameters in InStr() should be updated to include occurrence as of right now it only shows:

InStr(Haystack, Needle [, CaseSensitive?, StartingPos])

Which is not all of the parameters. Was a simple oversight on my end, oh well ty!

@xzeroun xzeroun closed this as completed Nov 8, 2022
@mark-wiemer mark-wiemer reopened this Nov 13, 2022
mark-wiemer pushed a commit that referenced this issue Nov 16, 2022
@mark-wiemer mark-wiemer mentioned this issue Nov 22, 2022
mark-wiemer added a commit that referenced this issue Nov 22, 2022
## 3.1.0 - 2022-11-21 🦃

Compiler:

-   New compiler options in settings: Choose base file, file icon, and "use [MPRESS](https://www.autohotkey.com/mpress/mpress_web.htm)"
-   Add "Compiler GUI" command in context menu to use the AHK GUI when compiling

Snippets:

-   Update snippets for AHK 1.1.35.00 and fix broken `InStr()` snippet ([#263](#263))

Grammar: Fix `#Requires` not being recognized ([#268](#268))

Editor: New AHK file icon (green square with white H)

Debugger: Minor debugger improvements

Formatter: Close the following bugs:

    -   Formatter incorrectly indents object literals ([#184](#184), [#222](#222))
    -   Nested one command code flow control ([#255](#255))

Miscellaneous:

-   Extension should start up faster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants