Variable not always working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HARQUR
Posts: 33
Joined: 11 Jan 2021, 08:07

Variable not always working

Post by HARQUR » 18 Oct 2021, 07:39

Code: Select all

Gui, 1: New
Gui, 1: Add, Edit, vLink
Gui, 1: Add, Button, gSearch, Search
Gui, 1: show

Search:
GuiControlGet, Link,,1
Run, Brave.exe "https://www.quran.com/%Link%?font=indopak"
Return
I used %Link%, this works when i input '1/1' or '114/2' but not for strings like '2/2' and '4/2'.

User avatar
HARQUR
Posts: 33
Joined: 11 Jan 2021, 08:07

Re: Variable not always working

Post by HARQUR » 18 Oct 2021, 08:00

may be due to length of string

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Variable not always working

Post by mikeyww » 18 Oct 2021, 09:06

Is the slash part of the search text, or are you typing directory names?

Here is a way to do the URL encoding (other methods are also available on the forum). It may need some adjustments.

Code: Select all

Gui, Font, s10
Gui,  Add, Text,, Enter a search term (press F3 to show this dialog again):
Gui, Add, Edit, w350 vlink gCheck
Gui, Add, Button, Default, Search
Gosub, F3
F3::
Gosub, Check
Gui, Show,, Search
Return

Check:
Gui, Submit, NoHide
GuiControl, % link > "" ? "Enable" : "Disable", Search
Return

ButtonSearch:
Gui, Submit
url := "https://www.quran.com/" fix(link) "?font=indopak"
MsgBox, 64, URL for %link%, %url%
Run, %url%
Return

GuiEscape:
Gui, Hide
Return

fix(url) {
 RegExMatch(url, "^(https?://)?(.+?)(/)?$", part)
 Loop, Parse, part2
  text .= A_LoopField ~= "[$&+,/:;=?@""<>#`%{}|\\^~[\] `]" ? Format("%{:X}", Asc(A_LoopField)) : A_LoopField
 Return part1 text part3
}

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Variable not always working

Post by RussF » 18 Oct 2021, 09:17

I was leaning more in the direction that there was no submit and therefore the variable "Link" was not set properly. You also need a "Return" after your gui definition, otherwise the code below it gets executed before you have a chance to input the search variable.

Code: Select all

Gui, 1: New
Gui, 1: Add, Edit, vLink
Gui, 1: Add, Button, gSearch, Search
Gui, 1: show
Return

Search:
;GuiControlGet, Link,,1
Gui, 1: Submit
Run, Brave.exe "https://www.quran.com/%Link%?font=indopak"
Return
worked for me when I replaced "Run, brave.exe" With "MsgBox,"

Russ

Post Reply

Return to “Ask for Help (v1)”