Search found 474 matches

by john_c
16 Oct 2020, 05:43
Forum: Ask For Help
Topic: The reason to use "Return (%Var%)" Topic is solved
Replies: 3
Views: 445

Re: The reason to use "Return (%Var%)" Topic is solved

To compare the example by Gregster with cases with no return:

Code: Select all

Var := "Foo"
Foo := "Bar"
msgbox % %Var%    ; => "Bar"
msgbox % (%Var%)  ; => "Bar"

Code: Select all

Var := "Foo"
Foo := "Bar"
; Abc := %Var%
; Abc := (%Var%)
msgbox % Abc  ; => "Bar"
by john_c
10 Oct 2020, 06:41
Forum: Ask For Help
Topic: Need a good example of a use of a guard statement Topic is solved
Replies: 4
Views: 188

Re: Need a good example of a use of a guard statement Topic is solved

Just in case and to mark this thread as solved, here is the function I searched for: Capital(Country, CompleteSentence) { Country := GetCountry(Country) If (Country == "") Return "Information about the country is missing" Capital := GetCapital(Country) If (Capital == "") Return "Information about th...
by john_c
08 Oct 2020, 18:13
Forum: Ask For Help
Topic: Two numbers are different but treated as equal. What the heck?
Replies: 9
Views: 137

Re: Two numbers are different but treated as equal. What the heck?

@boiler Yes, now both errors are obvious to me, thanks.

But it's not clear why - if I change the return statement to return Customer - the function sometimes returns the empty string. This is probably related to your last post, though I'm not sure.
by john_c
08 Oct 2020, 16:48
Forum: Ask For Help
Topic: Two numbers are different but treated as equal. What the heck?
Replies: 9
Views: 137

Re: Two numbers are different but treated as equal. What the heck?

@Xtra Could you show where exactly? I really don't see. I don't think you mean return.

Code: Select all

            return "Lucky:" A_Tab IsLucky(Customer) "`n"
                 . "Index:" A_Tab Index "`n"
                 .  Customer
@mikeyww Yes, exactly. A small typo.
by john_c
08 Oct 2020, 15:48
Forum: Ask For Help
Topic: Two numbers are different but treated as equal. What the heck?
Replies: 9
Views: 137

Two numbers are different but treated as equal. What the heck?

I generally avoid to create 2 thread per day, but it is too interesting why the following code doesn't work as I expect it. (And yes, we don't need two separate functions here, it could be done much simpler. It is just an example.) Customers := ["Bill", "Karl", "Tom"] FindLuckyCustomer(Customers) { ...
by john_c
08 Oct 2020, 15:42
Forum: Ask For Help
Topic: Update cloned array Topic is solved
Replies: 7
Views: 115

Re: Update cloned array Topic is solved

Thanks!
by john_c
08 Oct 2020, 13:57
Forum: Ask For Help
Topic: Update cloned array Topic is solved
Replies: 7
Views: 115

Re: Update cloned array Topic is solved

I suppose your function is trying to handle cases where the particular customer hasn’t been added,
Yes, this is correct.
but I’m not seeing why.
You mean, what is the reason? Just curiosity.
by john_c
08 Oct 2020, 13:39
Forum: Ask For Help
Topic: Update cloned array Topic is solved
Replies: 7
Views: 115

Update cloned array Topic is solved

Bill := {} Bill["Country"] := "Canada" Bill["City"] := "Toronto" Bill["Profession"] := "Designer" Karl := {} Karl["Country"] := "UK" Karl["City"] := "London" Karl["Profession"] := "Manager" Jane := {} Jane["Country"] := "UK" Jane["City"] := "London" Jane["Profession"] := "Artist" Customers := {} Cu...
by john_c
06 Oct 2020, 15:47
Forum: General Discussion
Topic: "Say thanks" feature or something similar
Replies: 3
Views: 253

"Say thanks" feature or something similar

I think that it would be useful to have an option to mark some answer as useful so that the poster (the who posted the answer) will receive a notification but the thread won't be "bumped" (= "upped"). The first reason is that messages like "Thanks!" or "Amazing!!!" don't add anything valuable to oth...
by john_c
04 Oct 2020, 16:12
Forum: Ask For Help
Topic: Throw an error about a wrong parameter of a function - with the name of this parameter Topic is solved
Replies: 4
Views: 125

Throw an error about a wrong parameter of a function - with the name of this parameter Topic is solved

If you run the following Hotstring() example, Hotstring(":*:btw", "by the way", "WrongArg") there will be thrown an error: Error: Parameter #3 invalid. Specifically: WrongArg How to achieve the same effect (that is, to report the name of the wrong argument) with a custom function? I know there is A_...
by john_c
04 Oct 2020, 08:14
Forum: Ask For Help
Topic: How does AHK handle wrong function arguments?
Replies: 9
Views: 329

Re: How does AHK handle wrong function arguments?

boiler wrote:
04 Oct 2020, 07:21
You are just pointing out that they are both working exactly as documented.
Yes, but why FileOpen() doesn't check whether its 2nd argument is a valid string (that is, either "r", "w", "a", "rw", "h", and some others) the same way as Hotstring() do?
by john_c
04 Oct 2020, 06:18
Forum: Ask For Help
Topic: How does AHK handle wrong function arguments?
Replies: 9
Views: 329

Re: How does AHK handle wrong function arguments?

lexikos , but what about the situations where a function expects a string? Here is a comparison of how FileOpen() and HotString() work. If we use "WrongArg" , the former function returns 0 instead of an object, but the latter throws an error. ; If the 2nd argument is wrong, the function returns 0 M...
by john_c
03 Oct 2020, 17:32
Forum: Ask For Help
Topic: How does AHK handle wrong function arguments?
Replies: 9
Views: 329

Re: How does AHK handle wrong function arguments?

Hmm, you are correct, thanks. It seems I need a break.
by john_c
03 Oct 2020, 16:37
Forum: Ask For Help
Topic: How does AHK handle wrong function arguments?
Replies: 9
Views: 329

How does AHK handle wrong function arguments?

Here are two tests. ; The default value of the 3rd argument is False ; As the 3rd argument, I use "WrongArg" ; It seems "WrongArg" is treated as False MsgBox % InStr("aaa_XY_bbb", "xy", "WrongArg") ; => 5 ; The default value of the 6th argument is 1 ; As the 6th argument, I use "WrongArg" ; It seems...
by john_c
02 Oct 2020, 07:43
Forum: Ask For Help
Topic: Are braces represent scopes (like in C++)? Topic is solved
Replies: 5
Views: 122

Re: Are braces represent scopes (like in C++)? Topic is solved

@mikeyww Thanks, I share the same opinion. Let's wait for someone else here :-)
by john_c
02 Oct 2020, 05:24
Forum: Ask For Help
Topic: Are braces represent scopes (like in C++)? Topic is solved
Replies: 5
Views: 122

Are braces represent scopes (like in C++)? Topic is solved

In C++, as far as I know, each pair of curly brackets represent different scope: (http://icarus.cs.weber.edu/~dab/cs1410/textbook/3.Control/blocks.html) if ( . . . ) { int counter; // definition 1 if ( . . . ) { int counter; // definition 2 . . . do something with counter // uses definition 2 counte...
by john_c
30 Sep 2020, 04:49
Forum: Ask For Help
Topic: Do we need returns in "switch"? Topic is solved
Replies: 2
Views: 68

Re: Do we need returns in "switch"? Topic is solved

just me, thanks. So, normally there should be neither return nor break.

Go to advanced search