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.
I have looked at the escape sequences and put the ` char in next to the characters in the end of the URL
Help would be much appreciated
Variable within URL called in function
-
- Posts: 3
- Joined: 31 Jul 2021, 11:30
Re: Variable within URL called in function
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.
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.
Re: Variable within URL called in function
Specifically, your function call should look like this to properly insert the contents of the clipboard between the two literal string segments:
Alternatively, without the dots:
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.
Code: Select all
buttonFunc("https://duckduckgo.com/?q=" . clipboard . "&t=chromentp&atb=v101-1&ia=`web")
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.
-
- Posts: 3
- Joined: 31 Jul 2021, 11:30
Re: Variable within URL called in function
- notedPosting your code, rather than an image of your code, eases the debugging for readers.
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")
Re: Variable within URL called in function
I agree that this is probably an error in your code on line 82.
-
- Posts: 3
- Joined: 31 Jul 2021, 11:30
Re: Variable within URL called in function
Oh that was me! Ha! must've been me trying (almost) everything to fix the illegal character error.
Ok, thanks again
Ok, thanks again
Who is online
Users browsing this forum: doodles333 and 272 guests