Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Issue with Msgbox output



  • Please log in to reply
6 replies to this topic
Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

The below code returns 0, but not the content of s

s:="1|2"
Msgbox % s "`n" s == A_Blank

Looks like a bug to me because this works just fine

s:="1|2"
b:=s==A_Blank
Msgbox % s "`n" b

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
It's not a bug, you're just not thinking through how the evaluation process works:
 
s:="1|2"
Msgbox %	s "`n" s==A_Blank
Msgbox %	s "`n" (s==A_Blank)
Think about why the latter in the above code works the way you think it should but the former doesn't and you'll see why this isn't a bug.

Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Hmm, ok. Yes, I definitely misunderstood the evaluation process. For this same reason, the difference is not immediately obvious to me. % forces an expression, but the parenthesis are distinguishing s==A_Blank from the rest of the expression?

 

Here's how I was parsing it in my mind:

  1. Create Msgbox with
  2. contents of s and
  3. a newline and
  4. result for s == A_Blank

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
✓  Best Answer

We have one expression with one operator (i.e. ==). On the left side of the operator we have s "`n" s which will be auto-concatenated to "1|2`n1|2" and compared with A_Blank on the right side.


Prefer ahkscript.org for the time being.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Understood. That just shattered my entire universe (not really). Thanks!


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
just me pretty much laid it out, but I'll explain it a different way.

You want a combination of text and the result of an evaluation to be the result in your MsgBox. In order to do that, you have to establish clear boundaries for what should be evaluated and what shouldn't. In the previous example s "`n" s==A_Blank, the expression has no way of knowing that you want to evaluate only s==A_Blank. It sees everything on the left side of the == as the term to be evaluated, so in essence, there is no text; the entire expression is the evaluation.

In the working example s "`n" (s==A_Blank), the expression knows what needs to be evaluated and keeps it independent of the rest of the expression until it has a result from the evaluation.

As in math, if you put 1 + 2 * 3 intending to add 1 + 2 first to end up with 9, your statement would fail because the order of operation doesn't allow that. But if you use (1 + 2) * 3, the order of operation works as intended and you get 9.

Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Thank you for taking the time to explain that in detail, Sinkfaze. That was an excellent explanation.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.