Variable within URL called in function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
slapdash_Metrologist
Posts: 3
Joined: 31 Jul 2021, 11:30

Variable within URL called in function

31 Jul 2021, 13:23

I'm sure I'm making an elementary mistake somewhere, but I can't seem to get around it.
I'm evolving an internet search function that takes an input from highlighted text and searches it in various places. It works nicely, but attempting to collapse the repeated code into a function is proving to be a headache.
It throws up an error when I put the URL in as the fuctions argument. It complains that I'm missing characters before another, or that there's an illegal character if I try something else.
URL_in_VAR.png
URL_in_VAR.png (60.02 KiB) Viewed 381 times
URL_in_VAR2.png
URL_in_VAR2.png (23.77 KiB) Viewed 381 times
I have looked at the escape sequences and put the ` char in next to the characters in the end of the URL
:headwall:
Help would be much appreciated
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Variable within URL called in function

31 Jul 2021, 13:40

When you call your function, use an expression. If you have a literal string such as a URL, then quote it.

Posting your code, rather than an image of your code, eases the debugging for readers. It sometimes may get you a faster answer as well as revisions that might help you.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Variable within URL called in function

31 Jul 2021, 14:02

Specifically, your function call should look like this to properly insert the contents of the clipboard between the two literal string segments:

Code: Select all

buttonFunc("https://duckduckgo.com/?q=" . clipboard . "&t=chromentp&atb=v101-1&ia=`web")
Alternatively, without the dots:

Code: Select all

buttonFunc("https://duckduckgo.com/?q=" clipboard "&t=chromentp&atb=v101-1&ia=`web")

The & around variables are only used when legacy syntax is called for (with exceptions that don't apply here), and as mikeyww pointed out, expression syntax is used in function call parameters.
slapdash_Metrologist
Posts: 3
Joined: 31 Jul 2021, 11:30

Re: Variable within URL called in function

31 Jul 2021, 14:47

Posting your code, rather than an image of your code, eases the debugging for readers.
- noted
Thanks for the responses. I'll have to get used to the differences in syntax. I'll get there.

Code: Select all

buttonFunc("https://duckduckgo.com/?q=" clipboard "&t=chromentp&atb=v101-1&ia=`web")
That escape character before web") is to tell it that the next character is literal right? So why does it need to be told that if that section is enclosed in quotes?
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Variable within URL called in function

31 Jul 2021, 14:56

I agree that this is probably an error in your code on line 82.
slapdash_Metrologist
Posts: 3
Joined: 31 Jul 2021, 11:30

Re: Variable within URL called in function

31 Jul 2021, 14:59

Oh that was me! :oops: Ha! must've been me trying (almost) everything to fix the illegal character error.
Ok, thanks again

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333 and 272 guests