boiler wrote: ↑23 Jul 2021, 04:36
Well @Jakson, please don't tell people I taught you to do that, because I didn't.
You took something I suggested and misapplied it (it happens to work in this case but you would get in real trouble if you did this in general going forward). If you were going to just separate your
if statements so that they are now checking single items at a time instead of lists, then you just should have used
if (NCMVar = "NMC") (quotes needed because it's a literal string in expression format) and
if (NCMVar = 1) (no quotes because 1 is a numerical value, although it would work with them which would treat it as the string "1").
The reason I suggested using
if Var in s that it allows
lists like you were trying to use with
=. And
if Var contains is also meant for lists, not single values. I showed you how
if (NCMVar = 1,NCM) was incorrect but you could use
if NCMVar in 1,NCM. So it seems you are using
contains now only because you saw it on that page and it sounds more appropriate from an English perspective, but using it with a single value like
if NCMVar contains 1 isn’t how it was meant to be used. In fact it is the wrong use of it. That statement would be true if the variable contained a 1
anywhere in it, such as 10, "Text1", or 2010:
Code: Select all
NCMVar := 10
if NCMVar contains 1
MsgBox, Yes ; produces Yes, which is surely not desired
else
MsgBox, No
If you were going to do that, at least it would make more sense to use
if NCMVar in 1, since that at least produces the desired result. But please don't use that either as
in is meant to be used with lists. It makes more sense from an English perspective when you say it with a list: "Is the value of NCMVar
in the list of values 1,NCM?"
It appears I'm being a little overzealous!
It would also appear this solution I came up with, the one you mention above, is also not the right way forward!
I've slightly modified what my
iniwrite lines do. Instead of assigning each variable a 1, or their literal string name ("NCM", "ISW"...), I'm only assigning their literal string name. From the outset, it appears to have made things simpler.
Code: Select all
NCMVar := NCM
IniWrite,%NCMVar%,settings.ini,ncmtype,ncmvar
I'm still using
contains inappropriately, however.
Instead of checking if my variable is one of two values I'm instead checking if it is a literal string using
contains.
boiler wrote: ↑23 Jul 2021, 04:36
If you were going to just separate your
if statements so that they are now checking single items at a time instead of lists, then you just should have used
if (NCMVar = "NMC") (quotes needed because it's a literal string in expression format) and
if (NCMVar = 1) (no quotes because 1 is a numerical value, although it would work with them which would treat it as the string "1").
If I'm following along with what your saying, my original iteration was wrong because I was using the wrong function, and the wrong syntax, to check the contents of a variable against a list. Now that I'm not checking a variable's contents against a list of strings or numbers, (only one string to compare per each
if) am I correct in re-formatting my
if statements to be as you stated above,
If (NCMVar = "NMC")?
Example code below
Code: Select all
IniRead,NCMvar,settings.ini,ncmtype,ncmvar
If (NCMvar := "NCM") ; if True, do the thing
{
clipboard = %servicedate%
Sleep 10
DllCall("SetCursorPos", int, 2258, int, 640)
Send {LButton}
Send {End}
Sleep 10
Send ^v{.}NCM {Space}
goto, finish
}
Else ; if False, do the other thing
gISW:
IniRead,ISWvar,settings.ini,iswtype,iswvar
If (ISWVar := "ISW")
{
clipboard = %servicedate%
Sleep 10
DllCall("SetCursorPos", int, 2258, int, 640)
Send {LButton}
Send {End}
Sleep 10
Send ^v{.}ISWCM {Space}
goto, finish
}
Else
....
Also, thank you again for your grace, Boiler! You're really helpful, man! Some of these concepts I'm finding are very difficult to digest at first - but when you tell me about them a little, like in this current topic and the last topic you helped me with, you made it a lot easier to understand what I wasn't getting.
Thank you!