Error when pulling the URL and using strReplace on it Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Error when pulling the URL and using strReplace on it

01 Dec 2021, 02:27

Hey guys using this code to get the browsers URL, find a word, swap it with another word, then reload the page with the new URL.
Forum Link to URL grabber: viewtopic.php?f=6&t=3702

Was wondering if there is anything obviously wrong here. I get an error that says "the following variable contains an illegal character" and the name of the variable is the actual URL instead of replacedURL. Also, if I run the code outside of a browser so that it returns no URL the program gets to stringreplacecount, shows a 0, then exits. I'm guessing the problem is simple syntax 🤔

Code: Select all

in main.ahk
----------------------
+1::sort("time")
+2::sort("prem")
+3::sort("size")

in functions.ahk
-------------------
sort(type){
	
URL := getURL() ;we now have the url in the variable "URL" from the geturl code in that link I posted above 
MsgBox %URL% ;this message box shows the URL correctly so it seems to be working

if (type = "time"){ ;here is where something breaks but I am not sure what 
	replacedURL := StrReplace(%URL%, &order=Prem, &order=time, stringReplaceCount) ;this is the line the error points to
	
	MsgBox % stringReplaceCount ;testing here to see if it worked but we never get to this msgbox
	
	;MsgBox % replacedURL
	}
}


; getURL code is down here from the forum link above. Returns the URL when called. Seems to be working correctly. 



User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Error when pulling the URL and using strReplace on it  Topic is solved

01 Dec 2021, 02:39

You’re right that this line is a problem:

Code: Select all

replacedURL := StrReplace(%URL%, &order=Prem, &order=time, stringReplaceCount)
You wouldn’t put % around URL. For the next two parameters, literal strings need to be in quotes. So it would be:

Code: Select all

replacedURL := StrReplace(URL, "&order=Prem", "&order=time", stringReplaceCount)

Function parameters use expression syntax. See details here.
User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Re: Error when pulling the URL and using strReplace on it

01 Dec 2021, 03:29

boiler wrote:
01 Dec 2021, 02:39
You’re right that this line is a problem:

Code: Select all

replacedURL := StrReplace(%URL%, &order=Prem, &order=time, stringReplaceCount)
You wouldn’t put % around URL. For the next two parameters, literal strings need to be in quotes. So it would be:

Code: Select all

replacedURL := StrReplace(URL, "&order=Prem", "&order=time", stringReplaceCount)

Function parameters use expression syntax. See details here.
Beautiful, this worked. Thanks!
Fortnite Youtuber BrockPlaysFortnite :D | AHK completely redefined the way I do things. What used to take me hours to do over and over can now be done with the click of a button. Don't give up! It's worth learning it front to back :wave:
(Note: I'm still a noob so my code may suck sometimes and there is almost assuredly a better way to do it)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 294 guests