url link format with run command Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

url link format with run command

Post by hancre » 27 Feb 2024, 07:42

my code for google search works. but the code for youtube search shows this following error.
the difference of the two codes is only the link. (different site)
Error: Expected a String but got an Object.

081: If IB = ""
082: Return
▶ 083: Run('https://www.youtube.com/results?search_query=' IB)

Code: Select all

!j:: {  ; google search 
    Gui "+LastFound +OwnDialogs +AlwaysOnTop"
    IB := InputBox("", "google search") 
    if IB = ""
        Return 
    Run('http://www.google.com/search?q=' IB) 
}


!enter:: { ; youtube search 
    Gui("+LastFound +OwnDialogs +AlwaysOnTop")
    IB := InputBox("", "Youtube search") 
    if IB = ""
        Return 
    Run('https://www.youtube.com/results?search_query=' IB) 
} 

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

Re: url link format with run command

Post by mikeyww » 27 Feb 2024, 07:49

Hello,

As the error message notes, InputBox returns an object. You cannot display this object, but you can get or display its value. Example

hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: url link format with run command

Post by hancre » 27 Feb 2024, 20:33

@mikeyww
Sorry. I can't find the fault of my codes despite the examples.
wHEN i I added < msgbox(IB) > and < msgbox IB > to the codes, it shows the same error.

The two codes are very similar. the link is only different.
If it's not blank, it should work for run command. the first code works well. but the second doesn.t

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

Re: url link format with run command  Topic is solved

Post by mikeyww » 27 Feb 2024, 21:23

In the example that I cited, did you see how the object's value was indicated in the MsgBox statement? How was that value accessed? Compared to your script, did the statement access the object's value the same way, or differently? It is the last line of the second example. You might also sneak a peek at the "Return Value" section of that page. It reports that one of the object's properties is called Value. This is a value that you can display.
This function returns an object with the following properties: Value (String): The text entered by the user.
Value is actually the exact name of the object's property.

hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: url link format with run command

Post by hancre » 28 Feb 2024, 00:30

mikeyww wrote:
27 Feb 2024, 21:23


OH. i realized my misake.
When I add Value in this following line. it worked. ^^

Code: Select all

Run('http://www.google.com/search?q=' IB.Value)  
Thanks a lot for your help. ^^

Post Reply

Return to “Ask for Help (v2)”