I'm still new to fat arrow functions... I want the value of bbAuto to change the instant the checkbox is checked/unchecked. I've run into the error before, but I'm having a hard time understanding what causes it...
bb := ''
biggerMsgBox(thisMess, secondButt)
{ Global bb := Gui(,'Validity Report')
bb.SetFont('s11 ' FontColor)
bb.BackColor := GuiColor, GuiColor
global mbTitle := ""
(mbTitle := bb.Add('Text',, 'For proposed new item:')).Focus() ; Focusing this prevents the three "edit" boxes from being focus by default.
bb.SetFont(myBigFont )
proposedHS := ':' tMyDefaultOpts ':' tTriggerString '::' tReplaceString
bb.Add('Text', (strLen(proposedHS)>90? 'w600 ':'') 'xs yp+22', proposedHS)
bb.SetFont('s11 ')
secondButt=0? bb.Add('Text', ,"===Validation Check Results==="):''
bb.SetFont(myBigFont )
bbItem := StrSplit(thisMess, "*|*")
; Use "edit" rather than "text" because it allows us to select the text.
edtSharedSettings := ' -VScroll ReadOnly -E0x200 Background'
bb.Add('Edit', (inStr(bbItem[1],'-Okay.')? myGreen : myRed) edtSharedSettings GuiColor, bbItem[1])
trigEdtBox := bb.Add('Edit', (strLen(bbItem[2])>104? ' w600 ' : ' ') (inStr(bbItem[2],'-Okay.')? myGreen : myRed) edtSharedSettings GuiColor, bbItem[2])
bb.Add('Edit', (strLen(bbItem[3])>104? ' w600 ' : ' ') (inStr(bbItem[3],'-Okay.')? myGreen : myRed) edtSharedSettings GuiColor, bbItem[3])
If (useFindInScript = 1 )
trigEdtBox.OnEvent('Focus', findInScript)
bb.SetFont('s11 ' FontColor)
secondButt=1? bb.Add('Text',,"==============================`nAppend HotString Anyway?"):''
bbAppend := bb.Add('Button', , 'Append Anyway')
bbAppend.OnEvent 'Click', (*) => Appendit(tMyDefaultOpts, tTriggerString, tReplaceString)
bbAppend.OnEvent 'Click', (*) => bb.Destroy()
if secondButt != 1
bbAppend.Visible := False
bbClose := bb.Add('Button', 'x+5 Default', 'Close')
bbClose.OnEvent 'Click', (*) => bb.Destroy()
global bbAuto := 0
bb.Add('Checkbox', 'x+5 Checked' AutoLookupFromValidityCheck, 'Auto Lookup`nin editor').OnEvent, "click" (*) => bbAuto := 1
bb.Show('yCenter x' (A_ScreenWidth/2))
WinSetAlwaysontop(1, "A")
bb.OnEvent 'Escape', (*) => bb.Destroy()
}
; Find the text that is selected in the GUI.
findInScript(*)
{ If (bb.bbAuto = 0)
Return
SoundBeep
if (GetKeyState("LButton", "P"))
KeyWait "LButton", "U"
A_Clipboard := ""
SendInput "^c"
If !ClipWait( 1, 0)
Return
;msgbox A_Clipboard
if WinExist(NameOfThisFile)
WinActivate NameOfThisFile
else
{ Run MyAhkEditorPath " " NameOfThisFile
While !WinExist(NameOfThisFile)
Sleep 50
WinActivate NameOfThisFile
}
If RegExMatch(A_Clipboard, "^\d{2,}") ; two or more digits?
SendInput "^g" A_Clipboard
else
{ SendInput "^f"
sleep 200
SendInput "^v"
}
mbTitle.Focus() ; Focus title again so text doesn't stay selected.
}
EDIT: Once I posted it, I realized it will never "toggle" the value.... Only will set it to 1.
Still though... What causes the error?
Re: "Expected a string, but got a function..."
Posted: 09 Apr 2024, 16:20
by ntepa
Parentheses can be omitted only if the function is called by itself at the start of a line.
There's also a missing comma between "click" and the fat arrow function. The space between them causes "click" to auto-concatenate with the fat arrow function.
Strings cannot concatenate with functions, so it resulted in the error "Expected a string, but got a function".
Even in cases where it is valid to omit the parentheses, it is not valid to write a comma immediately after the function/method name. Comma is used only between parameters or to separate sub-expressions, as in x := 1, y := 2.
Global variables being directly assigned by a function must be declared inside the function. bbAuto := 1 assigns to a local variable whose value is never used.
If the code was inside a function, removing global would allow the outer function to create a local variable which would be implicitly captured by the inner function. Replacing global with static would have a similar effect, except that the static variable would be referenced directly and not "captured".
Assigning bb.Auto := 1 would make a property of bb, avoiding all issues of variable scope, but causing a circular reference to the Gui. (cb, *) => cb.Gui.Auto := 1 would make a property of bb without creating a circular reference.