niubbone Posted June 30, 2010 Share Posted June 30, 2010 Hi all. My problem is pretty simple. I have a starting date i decide. I have a function that everytime i press a button in a guy it adds up a day to the previous said date with _DateAdd. This should simulate a monthly work routine, so, every 30 days, salary adds up day by day and the full salary is paid every 30 days. Something like this 2010/06/30 Day 1; Starting date, Salary is 0$ Click on the button--> A day passes, salary +50$ 2010/07/01 Day 2; Salary is 5$ Click on the button--> A day passes, salary +50$ 2010/07/02 Day 3; Salary is 10$ Click on the button--> A day passes, salary +50$ 2010/07/01 Day 4; Salary is 10$ ...... Click on the button--> A day passes, salary +50$ 2010/07/30 Day 30; Salary is 1500$ My question is: How i manage a function like this? Global $StartingDate="2010/30/06" Global $SalaryDate="2010/30/06" Global $Daycount=1 Func DateAdd($Date) Local $NewDate = $Date $NewDate = _DateAdd('d', 1, $NewDate) $StartingDate=$NewDate $DayCount+=1 Salary($StartingDate) Endfunc I was thinking something like this Func Salary($Day) Local $StartCountDate=$Day If $StartCountDate=$x=_DateAdd('d',30,$StartCountDate) Then ;PAY SALARY (i won't write this code as it's not the problem) $SalaryDate=StartingDate Endfunc This is the raw code i had in mind. Could it work or there are more smart ways of doing it? Link to comment Share on other sites More sharing options...
James Posted June 30, 2010 Share Posted June 30, 2010 nuibbone,Variables declared as Dim/Global (although Global is deprecated) can be accessed (read/write) in any scope; i.e functions/while loop etc. This is a basic example of what I mean.HotKeySet("{F8}", "_AddToDay") Dim $intDate = 0 While 1 Sleep(500) ; GUI event handling here WEnd Func _AddToDay() $intDate += 1 ; This is where you'd basically use _DateAdd ConsoleWrite($intDate & @CRLF) EndFuncI access the $intDate variable in the _AddToDay() function scope, adding one to its previous value (+= does that).James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2010 Moderators Share Posted June 30, 2010 JamesBrooks,I feel it is Dim that is deprecated (or should be according to Valik!) - Global and Local are alive and kicking! 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...
James Posted June 30, 2010 Share Posted June 30, 2010 JamesBrooks,I feel it is Dim that is deprecated (or should be according to Valik!) - Global and Local are alive and kicking! M23I'm sure that I've seen the world deprecated next to Global in the help file. Last time I looked was a few months ago though.I use Dim over Global though - care to explain why I shouldn't?James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2010 Moderators Share Posted June 30, 2010 (edited) JamesBrooks,I clearly remember the conversation with Valik, but I cannot find the actual thread. His argument was that you should always declare the scope of variables explicitly - Dim relies on AutoIt applying the "inside/outside function" test, which might not be what you want in that particulr case.This was also true for redeclaring arrays - use Global/Local again and not Dim.His other argument is that you should always limit the number of Global variables to an absolute minimum - there was a thread about this not too long ago here where he offered some very sound advice.M23Edit: Wrong button too soon! Edited June 30, 2010 by Melba23 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...
James Posted June 30, 2010 Share Posted June 30, 2010 (edited) His other argument is that you should limit the number of Global variables to an absolute minimum - there was a thread about this not too long agoSo what should we use if he argues both ways? Here is his argument with an example.In short, Dim should only be allowed to turn an existing variable into an array. Edited June 30, 2010 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2010 Moderators Share Posted June 30, 2010 (edited) JamesBrooks,Sorry, our posts crossed as I pressed the wrong button too soon.Valik's view was that we should always use Global/Local, never Dim. But we should try and limit the Global variables to an absolute minimum. The thread I linked to has some good thoughts from Valik on how to do so.M23I have just seen your linked post that dates from 2006 - my conversation was much more recent and I seem to remember he was considering actually removing Dim from the lexicon. I will see if I can find it this evening.Edit: Found it here Edited June 30, 2010 by Melba23 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...
niubbone Posted June 30, 2010 Author Share Posted June 30, 2010 Thanks, I'm still waiting the day I could adventure myself into such technical questions. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2010 Moderators Share Posted June 30, 2010 niubbone, With plenty of study from you it will come sooner than you think! 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...
Valik Posted July 1, 2010 Share Posted July 1, 2010 So what should we use if he argues both ways? Here is his argument with an example. How am I arguing both ways? I've never liked Dim and I've always used explicit Global or Local statements to declare my variables. I use Dim only to re-declare a previously declared variable as an array. This is the only safe use the keyword has. Were it up to me I would either remove it entirely, or I would modify it so that it could ONLY be used to re-declare an existing variable as an array. This is not arguing both ways. 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