Zohar Posted August 7, 2012 Share Posted August 7, 2012 (edited) HiI need to do 2 operations in a While's Condition.The 2 operations are:1) Setting a Variable2) Conditioning, according to the Content of the Variable that was just assignedI need something like this:While ( $Data=SomeFunctionForGettingTheData() ) = "" Operations WendIn many programming Languages,the While condition that I just wrote, will do 2 operations:1) It will do the assinment $Data=SomeFunctionForGettingTheData()2) It will check the properly check if the value assigned, equals "", And the reason it will do it, because an assignment's return value, is the value that was assigned. (so like, the value of a codepiece like that $V=5, will be 5)How can I make the same in AutoIt?Thank you Edited August 10, 2012 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 7, 2012 Moderators Share Posted August 7, 2012 Zohar,I would use a Do...Until loop like this: Global $sData Do $sData = InputBox("Data Input", "Input here") Until $sData <> "" MsgBox(0, "Data Assigned", $sData)That way you both assign and check the value in the loop. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zohar Posted August 7, 2012 Author Share Posted August 7, 2012 (edited) Hi Melba23 Thank you,The only problem is that we have the Operations part.I need both the Assignment and the Condition to be checked before the Operations block is performed.What can we do in this case?I am ooking for a way to write the While's Condition, like in C++,Where you can write an Assignment to a variable,and that assignment's value, will also be the value of the whole clause..Is it somehow possible? Edited August 7, 2012 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 7, 2012 Moderators Share Posted August 7, 2012 Zohar, This perhaps: Global $sData HotKeySet("{ESC}", "On_Exit") While 1 ; Assign and check Do $sData = InputBox("Data Input", "Input here") Until $sData <> "" ; Operations MsgBox(0, "Data Assigned", $sData) WEnd Func On_Exit() Exit EndFunc But it is difficult to be helpful when I have so little idea of what exactly you are trying to do. There might well be another method more suited but without a better explanation it is impossible to say. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zohar Posted August 7, 2012 Author Share Posted August 7, 2012 (edited) Right now, my workaround is this: Local $Data While True $Data =SomeFunctionForGettingTheData() If $Data<>"" Then ExitLoop ;Operations Sleep(1000) WEnd However, If I could have the Assignment and the Condition in the While's Condition clause, the block could be like this: While ($Data =SomeFunctionForGettingTheData()) = "" Beep(1000,10) Sleep(1000) WEnd If only an Assignment in AutoIt, returned the Value that was assigned, the whole problem would've been solved.. Regarding your question, since this problem occured to me in many places, then there's not just 1 scenario - it's a basic coding problem, it has nothing to do with what you try to achieve in your program.. Edited August 7, 2012 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 7, 2012 Moderators Share Posted August 7, 2012 Zohar,If I could have the Assignment and the Condition in the While's Condition clauseBut I do not believe you can. And all you would achieve is more complicated, but slightly shorter, code - why not KISS? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zohar Posted August 7, 2012 Author Share Posted August 7, 2012 OK then. Thank you Melba.. Link to comment Share on other sites More sharing options...
MvGulik Posted August 7, 2012 Share Posted August 7, 2012 I personally would go with: ... $Data = SomeFunctionForGettingTheData() ;; first/initiation. While $Data = "" ;Operations Sleep(1000) $Data = SomeFunctionForGettingTheData() ;; next/continuation WEnd ... Although, I figure this is also possible. ... Dim $Data While IsEmptyString($Data, SomeFunctionForGettingTheData()) ;Operations Sleep(1000) WEnd ... Func IsEmptyString(ByRef $Data_out, $Data_in) $Data_out = $Data_in Return ($Data_out = "") EndFunc "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Zohar Posted August 8, 2012 Author Share Posted August 8, 2012 I personally would go with: ... $Data = SomeFunctionForGettingTheData() ;; first/initiation. While $Data = "" ;Operations Sleep(1000) $Data = SomeFunctionForGettingTheData() ;; next/continuation WEnd ... The only problem with it, is that you repeat the $Data = SomeFunctionForGettingTheData() line. Although, I figure this is also possible. ... Dim $Data While IsEmptyString($Data, SomeFunctionForGettingTheData()) ;Operations Sleep(1000) WEnd ... Func IsEmptyString(ByRef $Data_out, $Data_in) $Data_out = $Data_in Return ($Data_out = "") EndFunc This one is interesting Thanks Link to comment Share on other sites More sharing options...
ajag Posted August 8, 2012 Share Posted August 8, 2012 (edited) Zohar, The only problem with it, is that you repeat the $Data = SomeFunctionForGettingTheData() line. See your "I need something like this:" example of your first post: While ( $Data=SomeFunctionForGettingTheData() ) = "" Operations Wend Since the condition has to be checked every loop count the "$Data=SomeFunctionForGettingTheData()" part in the while condition will be repeated every loop count also. So it doesn't matter if it is done in the while-condition or within the loop. Or did I missunderstand you? A-Jay Edited August 8, 2012 by ajag Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
Zohar Posted August 10, 2012 Author Share Posted August 10, 2012 The problem is not that the "$Data=SomeFunctionForGettingTheData()" will run every iteration - it needs to run every iteration.The problem is in the fact that the discussed idea, contains code duplication, which should be avoided, for many reasons. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 10, 2012 Share Posted August 10, 2012 The problem is in the fact that the discussed idea, contains code duplication, which should be avoided, for many reasons.No it shouldn't, if you need to check it before the While loop, check it before the While loop. There's nothing wrong with that scenario. It would be the same if you were using a timer in a While loop, you would set the TimerInit() before the While loop, and then reset it with the same line inside the loop. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zohar Posted August 10, 2012 Author Share Posted August 10, 2012 (edited) BrewManNH, I completely disagere with you on this one. But you can code however way you prefer. I code the way I prefer. If AutoIt made Assignment Statements return the value of what was just assigned (like it happens in all other programming langauges), then the problem would have not existed. But from the comments here, it seems that there's no way to solve it. So I used the workaround I mentioned. Edited August 10, 2012 by Zohar Link to comment Share on other sites More sharing options...
BrewManNH Posted August 10, 2012 Share Posted August 10, 2012 If AutoIt made Assignment Statements return the value of what was just assigned (like it happens in all other programming langauges),then the problem would have not existed.Not ALL other programming languages, Python for instance doesn't return a value on an assignment. But that's neither here nor there, AutoIt doesn't, and workarounds can be done as you say. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zohar Posted August 10, 2012 Author Share Posted August 10, 2012 OK 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