bailey1274 Posted August 29, 2019 Share Posted August 29, 2019 Can someone please explain why this expression keeps throwing errors? I've tried so many different combinations of parentheses around each part/the entire expression. For $row = 0 to UBound($aTableData,1)-1 (Mod($row,7)=0) ? (Null) : (ContinueLoop) This gives "Error: Missing right bracket ')' in expression" Sometimes with other parentheses combinations I just get 'Error in expression' which I'm assuming is just a syntax error but at this point I'm not sure. The $aTableData is an array of 100+ rows and the oddest part is that when $row = 0, the expression evaluates as expected but when it moves on, I keep getting these errors. It works fine with a plain If-Then statement so I'm assuming this has to be syntax. Link to comment Share on other sites More sharing options...
Danp2 Posted August 29, 2019 Share Posted August 29, 2019 I'm not sure that you can use the ternary operator in this manner. AFAIK, it's designed to return a value, not execute a command. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 29, 2019 Share Posted August 29, 2019 (edited) Why not use this one liner... If Mod($row, 7) <> 0 Then ContinueLoop ... instead? Using ternary operators is strange when you don't want to return something from them. Edit: Was ninja-d. Edited August 29, 2019 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
bailey1274 Posted August 29, 2019 Author Share Posted August 29, 2019 Well yeah, this works like I mentioned in the post but I'm more just curious why its not working. Link to comment Share on other sites More sharing options...
bailey1274 Posted August 29, 2019 Author Share Posted August 29, 2019 So ternarys will only work in return statements and not just a simple command? Why does it work in a message box like in the example? And that adds to the confusion on why the first iteration works and the following ones do not. Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 29, 2019 Share Posted August 29, 2019 The issue is that the result isn't being used... you're returning Null or ContinueLoop... to nothing. The example shows the result being posted to the message box, where it's used in that code. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
bailey1274 Posted August 29, 2019 Author Share Posted August 29, 2019 Ah so on the first iteration, returning Null works as I would hope because that causes nothing to happen. However on $row=1, it returns a ContinueLoop but does not actually execute it and this somehow causes an error. I get it a little more now, but still a little hazy on why I get that specific error message. Although I guess either way, I'm using it in the wrong context. Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 29, 2019 Share Posted August 29, 2019 Are you using SciTE? I can't even get the code to execute once, AU3Check throws a bunch of syntax errors. I highly suggest installing it, it's great for finding errors before you start All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Jfish Posted August 29, 2019 Share Posted August 29, 2019 I think if you use a variable to store the result of the ternary operation it should work ... just preface your ternary with something to capture it and it should execute the function. Some examples below. $number = 5 $result=(Mod($number,2)<>0) ? (MsgBox(0,'',"odd")) : (MsgBox(0,'',"even")) $functionResult=(Mod($number,2)<>0) ? _helloTernary() : (MsgBox(0,'',"even")) func _helloTernary() for $a=0 to 9 ConsoleWrite("This function is working! You selected an odd number"&@CRLF) Next EndFunc Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
iamtheky Posted August 29, 2019 Share Posted August 29, 2019 (edited) Isnt part of the issue that ContinueLoop is not a thing that returns a thing? There are some old lengthy threads by @guinness where he gets religious about ternary not being a replacement for If/Then. I think this sort of example is part of that. Edited August 29, 2019 by iamtheky i am confusing af ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 29, 2019 Share Posted August 29, 2019 @Jfish Even that doesn't work with ContinueLoop, I tried just to be sure. You'll get an error about a missing/mismatched parenthesis --> ( All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
bailey1274 Posted August 29, 2019 Author Share Posted August 29, 2019 This does seem like a good example why its not just a replacement for any if-then. And imo creating a new variable sort of defeats the purpose of being a shorthand as you're doing something extra to make it work. I'm too lazy for all that. My takeaway, just use ternarys for returning values and not executing things. Link to comment Share on other sites More sharing options...
mikell Posted August 29, 2019 Share Posted August 29, 2019 Iamtheky is right : nothing returned => error The example from Jfish is not good because Msgbox always returns a value, and user funcs return 0 (if nothing else is specified) An easy test : remove the parenthesis and you'll get "Error in expression" For $i = 1 to 4 $i <> 2 ? Msgbox(0,"", $i) : ContinueLoop Next Link to comment Share on other sites More sharing options...
jchd Posted August 29, 2019 Share Posted August 29, 2019 The ternary operator is special. One might think it evaluates to a RHS, whatever dataype it is. But it's not that simple, maybe because it has been introduced lately in the parser. One would think the two snippets below are equivalent (and both incorrect), but only the second one correctly raises a runtime error: For $i = 0 To 3 $i = 2 ? 42 : 42 Next For $i = 0 To 3 42 Next Also ContinueLoop is a statement (like Exit, Wend, EndIf, Select, ...) so it's illegal as a RHS value. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
guinness Posted September 14, 2019 Share Posted September 14, 2019 On 8/29/2019 at 8:01 PM, iamtheky said: Isnt part of the issue that ContinueLoop is not a thing that returns a thing? There are some old lengthy threads by @guinness where he gets religious about ternary not being a replacement for If/Then. I think this sort of example is part of that. Yep, my opinion hasn't changed on that one! iamtheky 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Danyfirex Posted September 15, 2019 Share Posted September 15, 2019 (edited) Ternary operator is for evaluating expressions. ContinueLoop or ExitLoop are statements. It's like you try to pass ContinueLoop to a function as parameter ( Cos(ExitLoop)) or you try to operate with a statement like ( $var=1+ContinueLoop) Saludos Edited September 15, 2019 by Danyfirex trancexx and FrancescoDiMuro 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
rudi Posted September 23, 2019 Share Posted September 23, 2019 You can use ternary to execute two different "all-in-one-commands", depending on a true/false value. I use that for setting Opt() values depending on if the script is compiled or not. Just "trow away" the returned result value by assigning it to a not used variable: $trash=@Compiled?(opt("trayautopause",0)):(opt("Trayicondebug",1)) ; MsgBox(0,@Compiled,"check tray icon now") Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now