Leaderboard
Popular Content
Showing content with the highest reputation on 07/10/2018 in all areas
-
How can I parse JSON data into an Object ?
iiSkLz_ and one other reacted to JLogan3o13 for a topic
A search of the forum yields 700+ results, and a search of Google many more. You went through all of those and found nothing at all?2 points -
endfunc
FrancescoDiMuro and one other reacted to Earthshine for a topic
you can also type it in with your fingers2 points -
[BUGFIX VERSION] - 25 Jun 13 Fixed: A bug in AutoIt v3.3.6.1 could crash the UDF under certain circumstances - other releases do not show the same error. Small code change to prevent error in any release. Thanks to DatMCEyeBall for finding it. New UDF below and in zip. Previous versions: A recent topic dealt with the problem of the dotted focus lines which appear around controls - the most obvious ones are around sliders - and how to get rid of them. A bit of experimentation showed that these focus lines do not always appear. If there is a button in the GUI, they do not seem to appear until the TAB key has been used to change focus in the GUI - if you only use the mouse, they usually remain hidden. However, if there is no button, they appear immediately. I posted some code in the topic to show this. The only solution to permanently remove these lines appeared to be subclassing the controls to bypass the WM_SETFOCUS message, but the necessary code seemed a little daunting to coders less well-versed in the dark side of Autoit (in which category I firmly place myself! ). So once I had understood what was going on in the subclassing process, I thought I might try and make a UDF which would simplify the whole thing for us average Autoit users. A number of other forum members have offered suggestions and code snippets - and here you have the resulting UDF, which prevents focus lines from ruining the visual appearance of buttons, radios, checkboxes and sliders: [NEW] The NoFocusLines.au3 include file: #include-once ; #INDEX# ============================================================================================================ ; Title .........: NoFocusLines ; AutoIt Version : 3.3.4.0 + ; Language ......: English ; Description ...: Prevents dotted focus lines on GUI controls of button and slider classes ; Remarks .......: Once the _Set function has been used to prevent focus lines, the specified controls should be reset ; with the _Clear function before deletion. Note all such controls can be reset in ; one call to the _Clear function without having to specify each individual control. ; The _Global_Set function prevents focus lines on ANY subsequently created button or slider class ; control. However, CAUTION is advised when using the _Global_Set function as even though the use of ; the _Global_Exit function on exit deletes all such controls and frees the memory used by the UDF, ; full clean up relies on internal AutoIt procedures. ; Note ..........: Button class controls include buttons, radios and checkboxes ; Author(s) .....: Melba23, based on code from Siao, aec, martin, Yashied and rover ; ==================================================================================================================== ; #INCLUDES# ========================================================================================================= #include <WinAPI.au3> OnAutoItExitRegister("_NoFocusLines_AutoExit") ; #GLOBAL VARIABLES# ================================================================================================= Global $hNoFocusLines_Proc = 0, $pOrg_SliderProc = 0, $pOrg_ButtonProc = 0, $aHandle_Proc[1][2] = [[0, ""]] ; #CURRENT# ========================================================================================================== ; _NoFocusLines_Set: Prevents dotted focus lines on specified button and slider class controls ; _NoFocusLines_Clear: Resets normal focus lines on specified controls. ; _NoFocusLines_Exit: Used on script exit to reset all subclassed controls and free UDF WndProc memory ; _NoFocusLines_Global_Set: Prevents dotted focus lines on all subsequently created button and slider class controls ; _NoFocusLines_Global_Exit: Used on script exit to delete all subclassed controls and free UDF WndProc memory ; ==================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; _NoFocusLines_SubClass: Sets WndProc for specified control ; _NoFocusLines_Proc: New WndProc to prevent focus lines on specified button and slider class controls ; _NoFocusLines_Global_Proc: New WndProc to prevent focus lines on all subsequently created button and slider controls ; _NoFocusLines_AutoExit: Automatically deletes all controls and frees the memory used on exit ; ==================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _NoFocusLines_Set ; Description ...: Prevents the dotted focus lines on specified button and slider class controls ; Syntax.........: _NoFocusLines_Set($vCID) ; Parameters ....: $vCID - ControlIDs of controls - multiple ControlIDs must be passed as a 0-based array ; Requirement(s).: v3.3 + ; Return values .: Success: Returns number of controls currently subclassed ; Failure: Sets @error as follows: ; 1 = Global function already run ; 2 = Invalid controlID ; Author ........: Melba23, based on code from Siao, aec, martin and Yashied ; Remarks .......: Any controls on which focus lines have been prevented by using the _SET function should be reset via ; the _CLEAR function if deleted prior to exit ; Example........: Yes ;===================================================================================================================== Func _NoFocusLines_Set($vCID) Local $aCID[1] ; Check if Global function already used If $aHandle_Proc[0][1] = "Global" Then Return SetError(1, 0, 0) ; Check parameters are button or slider class controls If Not IsArray($vCID) Then Switch _WinAPI_GetClassName(GUICtrlGetHandle($vCID)) Case "Button", "msctls_trackbar32" $aCID[0] = $vCID Case Else Return SetError(2, 0, 0) EndSwitch Else For $i = 0 To UBound($vCID) - 1 Switch _WinAPI_GetClassName(GUICtrlGetHandle($vCID[$i])) Case "Button", "msctls_trackbar32" ; ContinueLoop Case Else Return SetError(2, 0, 0) EndSwitch Next $aCID = $vCID EndIf ; Check if _NoFocusLines_Proc has been registered If $hNoFocusLines_Proc = 0 Then ; Register callback function and obtain handle to _NoFocusLines_Proc $hNoFocusLines_Proc = DllCallbackRegister("_NoFocusLines_Proc", "int", "hwnd;uint;wparam;lparam") EndIf ; Get pointer to _NoFocusLines_Proc Local $pNoFocusLines_Proc = DllCallbackGetPtr($hNoFocusLines_Proc) ; Work through CIDs For $i = 0 To UBound($aCID) - 1 ; Get handle for control Local $hHandle = GUICtrlGetHandle($aCID[$i]) ; Check if control is already subclassed For $j = 1 To $aHandle_Proc[0][0] ; Skip if so If $hHandle = $aHandle_Proc[$j][0] Then ContinueLoop 2 EndIf Next ; Increase control count $aHandle_Proc[0][0] += 1 ; Double array size if too small (fewer ReDim needed) If UBound($aHandle_Proc) <= $aHandle_Proc[0][0] Then ReDim $aHandle_Proc[UBound($aHandle_Proc) * 2][2] ; Store control handle $aHandle_Proc[$aHandle_Proc[0][0]][0] = $hHandle ; Subclass control and store pointer to original WindowProc $aHandle_Proc[$aHandle_Proc[0][0]][1] = _NoFocusLines_SubClass($hHandle, $pNoFocusLines_Proc) ; If error in subclassing then remove this control from the array If $aHandle_Proc[$aHandle_Proc[0][0]][1] = 0 Then $aHandle_Proc[0][0] -= 1 Next ; Remove any empty elements after a ReDim ReDim $aHandle_Proc[$aHandle_Proc[0][0] + 1][2] ; Check if subclassing was successful If $aHandle_Proc[0][0] > 0 Then $aHandle_Proc[0][1] = "Local" Else ; Free WndProc memory DllCallbackFree($hNoFocusLines_Proc) $hNoFocusLines_Proc = 0 EndIf Return $aHandle_Proc[0][0] EndFunc ;==>_NoFocusLines_Set ; #FUNCTION# ========================================================================================================= ; Name...........: _NoFocusLines_Clear ; Description ...: Repermits the dotted focus lines on controls if previously prevented by _NoFocusLines_Set ; Syntax.........: _NoFocusLines_Clear($vCID) ; Parameters ....: $vCID - ControlIDs of control(s) - multiple ControlIDs must be passed as a 0-based array ; If no parameter passed, all previously set controls are reset ; Requirement(s).: v3.3 + ; Return values .: Success: Returns number of controls currently subclassed ; Failure: Sets @error as follows: ; 1 = Global function already run ; 2 = Invalid controlID ; Author ........: Melba23, based on code from Siao, aec, martin and Yashied ; Remarks .......: If controls which have had focus lines removed by the _SET function are deleted before the script ; exits, it is advisable to use this function on them BEFORE deletion. ; Example........: Yes ;===================================================================================================================== Func _NoFocusLines_Clear($vCID = "") Local $aCID[1] ; Check if Global function already used If $aHandle_Proc[0][1] = "Global" Then Return SetError(1, 0, 0) If $vCID = "" Then ; Reset all controls to original WndProc For $i = 1 To $aHandle_Proc[0][0] _NoFocusLines_SubClass($aHandle_Proc[$i][0], $aHandle_Proc[$i][1]) Next ; Reset array Dim $aHandle_Proc[1][2] = [[0, "Local"]] Else ; Check parameters are valid If Not IsArray($vCID) Then If Not IsHWnd(GUICtrlGetHandle($vCID)) Then Return SetError(2, 0, 0) $aCID[0] = $vCID Else For $i = 0 To UBound($vCID) - 1 If Not IsHWnd(GUICtrlGetHandle($vCID[$i])) Then Return SetError(2, 0, 0) Next $aCID = $vCID EndIf ; For each specified control For $j = 0 To UBound($aCID) - 1 ; Run through array to see if control has been subclassed For $i = 1 To $aHandle_Proc[0][0] ; Control found If $aHandle_Proc[$i][0] = GUICtrlGetHandle($aCID[$j]) Then ; Unsubclass the control _NoFocusLines_SubClass($aHandle_Proc[$i][0], $aHandle_Proc[$i][1]) ; Remove control handle and orginal WindowProc from array $aHandle_Proc[$i][0] = 0 $aHandle_Proc[$i][1] = 0 EndIf Next Next ; Remove zeroed elements of array For $i = $aHandle_Proc[0][0] To 1 Step -1 If $aHandle_Proc[$i][0] = 0 Then ; Reduce control count $aHandle_Proc[0][0] -= 1 ; Move up all following elements For $j = $i To $aHandle_Proc[0][0] $aHandle_Proc[$j][0] = $aHandle_Proc[$j + 1][0] $aHandle_Proc[$j][1] = $aHandle_Proc[$j + 1][1] Next EndIf Next ReDim $aHandle_Proc[$aHandle_Proc[0][0] + 1][2] EndIf Return $aHandle_Proc[0][0] EndFunc ;==>_NoFocusLines_Clear ; #FUNCTION# ==================================================================================================================== ; Name...........: _NoFocusLines_Exit ; Description ...: Resets any remaining subclassed controls and frees the memory used by the UDF created WndProc ; Syntax.........: _NoFocusLines_Exit() ; Requirement(s).: v3.3 + ; Return values .: None ; Author ........: Melba23 ; Remarks .......: This function should be called on exit to avoid reliance on internal AutoIt procedures for memory clean up ; Example........: Yes ;================================================================================================================================ Func _NoFocusLines_Exit() ; Check if _Set function used If $aHandle_Proc[0][1] <> "Local" Then Return SetError(1, 0, 0) ; First unsubclass any remaining subclassed controls _NoFocusLines_Clear() ; Now free UDF created WndProc DllCallbackFree($hNoFocusLines_Proc) Return 1 EndFunc ;==>_NoFocusLines_Exit ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _NoFocusLines_Proc ; Description ...: Replacement WindowProc to prevent focus lines appearing on button and slider class controls ; Author ........: Melba23, based on code from Siao, aec, martin and Yashied ; Modified.......: ; Remarks .......: This function is used internally by _NoFocus_Set ; =============================================================================================================================== Func _NoFocusLines_Proc($hWnd, $iMsg, $wParam, $lParam) ; Ignore SETFOCUS message from all subclassed controls If $iMsg = 0x0007 Then Return 0 ; $WM_SETFOCUS ; Locate control handle in array For $i = 1 To $aHandle_Proc[0][0] ; And pass other messages to original WindowProc If $hWnd = $aHandle_Proc[$i][0] Then Return _WinAPI_CallWindowProc($aHandle_Proc[$i][1], $hWnd, $iMsg, $wParam, $lParam) Next EndFunc ;==>_NoFocusLines_Proc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _NoFocusLines_SubClass ; Description ...: Sets new WindowProc for controls ; Syntax ........: _NoFocusLines_SubClass($hWnd, $pNew_WindowProc) ; Parameters ....: $hWnd - Handle of control to subclass ; $pNew_WindowProc - Pointer to new WindowProc ; Author ........: Melba23, based on code from Siao, aec and martin ; Modified.......: ; Remarks .......: This function is used internally by _NoFocusLines_Set and _NoFocusLines_Clear ; =============================================================================================================================== Func _NoFocusLines_SubClass($hWnd, $pNew_WindowProc) Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc) If @error Then Return SetError(1, 0, 0) If $iRes = 0 Then Return SetError(1, 0, 0) Return $iRes EndFunc ;==>_NoFocusLines_SubClass ; #FUNCTION# ==================================================================================================================== ; Name...........: _NoFocusLines_Global_Set ; Description ...: Prevents the dotted focus lines on ALL subsequently created button and slider class controls ; Syntax.........: _NoFocusLines_Global_Set() ; Requirement(s).: v3.3 + ; Return values .: Success: 1 ; Failure: 0 and sets @error as follows: ; 1 = Specific function already run ; Author ........: rover ; Remarks .......: The _Global Exit function should be called on script exit ; Note ..........; CAUTION is advised when using the _Global_Set function as even though the use of the _Global_Exit function on ; exit deletes all such controls and frees the memory used by the UDF, full clean up relies on internal AutoIt ; procedures. ; Example........: Yes ;================================================================================================================================ Func _NoFocusLines_Global_Set() ; Run once check If $aHandle_Proc[0][1] <> "" Then Return SetError(1, 0, 0) ; Create callback $hNoFocusLines_Proc = DllCallbackRegister("_NoFocusLines_Global_Proc", "int", "hwnd;uint;wparam;lparam") Local $pCallbackPtr = DllCallbackGetPtr($hNoFocusLines_Proc) ; Create temp gui with button and slider Local $hGUITemp = GUICreate("", 1, 1, -10, -10) Local $hButtonTemp = GUICtrlGetHandle(GUICtrlCreateButton("", -10, -10, 1, 1)) Local $hSliderTemp = GUICtrlGetHandle(GUICtrlCreateSlider(-10, -10, 1, 1)) ; Globally subclass Button class (includes buttons, radios and checkboxes) $pOrg_ButtonProc = DllCall("User32.dll", "dword", "SetClassLongW", "hwnd", $hButtonTemp, "int", -24, "ptr", $pCallbackPtr) $pOrg_ButtonProc = $pOrg_ButtonProc[0] ; Globally subclass Slider(Trackbar) class $pOrg_SliderProc = DllCall("User32.dll", "dword", "SetClassLongW", "hwnd", $hSliderTemp, "int", -24, "ptr", $pCallbackPtr) $pOrg_SliderProc = $pOrg_SliderProc[0] GUIDelete($hGUITemp) $aHandle_Proc[0][1] = "Global" Return SetError(0, 0, 1) EndFunc ;==>_NoFocusLines_Global_Set ; #FUNCTION# ==================================================================================================================== ; Name...........: _NoFocusLines_Global_Exit ; Description ...: Deletes all controls and frees the memory used by the UDF created WndProc ; Syntax.........: _NoFocusLines_Global_Exit() ; Requirement(s).: v3.3 + ; Return values .: None ; Author ........: Melba23 ; Remarks .......: This function should be called on script exit if the _Global_Set function has been used ; Note ..........; CAUTION is advised as even though the use of the _Global_Exit function on exit deletes all controls and frees ; the memory used by the UDF, full clean up relies on internal AutoIt procedures. ; Example........: Yes ;================================================================================================================================ Func _NoFocusLines_Global_Exit() ; Check if _Set function used If $aHandle_Proc[0][1] <> "Global" Then Return SetError(1, 0, 0) ; First delete all controls - any subclassed controls are now deleted For $i = 3 To 65532 GUICtrlDelete($i) Next ; Now free UDF created WndProc DllCallbackFree($hNoFocusLines_Proc) Return 1 EndFunc ;==>_NoFocusLines_Global_Exit ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _NoFocusLines_AutoExit ; Description ...: Automatically deletes all controls and frees the memory used by the UDF created WndProc on exit ; Author ........: M23 ; Modified.......: ; Remarks .......: This function is used internally by NoFocusLines ; =============================================================================================================================== Func _NoFocusLines_AutoExit() Switch $aHandle_Proc[0][1] Case "Global" _NoFocusLines_Global_Exit() Case "Local" _NoFocusLines_Exit() EndSwitch EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _NoFocusLines_Global_Proc ; Description ...: Replacement WindowProc to prevent focus lines appearing on button and slider class controls ; Author ........: rover ; Modified.......: ; Remarks .......: This function is used internally by _NoFocusLines_Global_Set ; =============================================================================================================================== Func _NoFocusLines_Global_Proc($hWnd, $iMsg, $wParam, $lParam) If $iMsg = 0x0007 Then Return 0 ; $WM_SETFOCUS Switch _WinAPI_GetClassName($hWnd) Case "Button" ; pass the unhandled messages to default ButtonProc Return _WinAPI_CallWindowProc($pOrg_ButtonProc, $hWnd, $iMsg, $wParam, $lParam) Case "msctls_trackbar32" ; pass the unhandled messages to default SliderProc Return _WinAPI_CallWindowProc($pOrg_SliderProc, $hWnd, $iMsg, $wParam, $lParam) Case Else Return 0 EndSwitch EndFunc ;==>_NoFocusLines_Global_Proc [NEW] And an example script to show it working - and to show it does not affect other aspects of the control behaviour. It assumes the include is in the same folder. #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include "NoFocusLines.au3" Global $aCID[1] $iPos_1 = 0 $iPos_2 = 0 $fGlobal = False $hGUI = GUICreate("Choose Method", 200, 140) $sMsg = "Choose how you want the focus lines to be removed:" & @CRLF & @CRLF & _ "Global" & @TAB & "= All controls permanently" & @CRLF & _ "Specific" & @TAB & "= By choice" GUICtrlCreateLabel($sMsg, 10, 10, 180, 70) $hRadio_1 = GUICtrlCreateRadio("Global", 10, 90, 90, 20) $hRadio_2 = GUICtrlCreateRadio("Specific", 10, 110, 90, 20) GUICtrlSetState(-1, $GUI_CHECKED) $hButton_OK = GUICtrlCreateButton("OK", 110, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_OK ExitLoop EndSwitch WEnd ; If required remove focus lines from all controls If GUICtrlRead($hRadio_1) = $GUI_CHECKED Then If _NoFocusLines_Global_Set() = 1 Then $fGlobal = True ConsoleWrite("Global: " & @error & @CRLF) EndIf GUIDelete($hGUI) $hGUI = GUICreate("Subclassed Controls without Focus Lines", 500, 210) $hLabel_S1 = GUICtrlCreateLabel("Slider 1: " & $iPos_1, 20, 15, 100) $hLabel_S2 = GUICtrlCreateLabel("Slider 2: " & $iPos_2, 20, 115, 100) $hSlider_1 = GUICtrlCreateSlider(20, 50, 160, 30) $hSlider_2 = GUICtrlCreateSlider(20, 150, 160, 30) $hLabel_B1 = GUICtrlCreateLabel("", 200, 15, 80, 20) $hLabel_B2 = GUICtrlCreateLabel("", 200, 115, 80, 20) $hButton_1 = GUICtrlCreateButton("Button 1", 200, 50, 90, 30) $hButton_2 = GUICtrlCreateButton("Button 2", 200, 150, 90, 30) $hLabel_R1 = GUICtrlCreateLabel("", 300, 15, 80, 20) $hLabel_R2 = GUICtrlCreateLabel("", 300, 115, 80, 20) $hRadio_1 = GUICtrlCreateRadio("Radio 1", 300, 35, 90, 20) $hRadio_2 = GUICtrlCreateRadio("Radio 2", 300, 135, 90, 20) $hLabel_C1 = GUICtrlCreateLabel("", 300, 65, 80, 20) $hLabel_C2 = GUICtrlCreateLabel("", 300, 165, 80, 20) $hCheck_1 = GUICtrlCreateCheckbox("Check 1", 300, 85, 90, 20) $hCheck_2 = GUICtrlCreateCheckbox("Check 2", 300, 185, 90, 20) $hButton_Action = GUICtrlCreateButton("Hide upper control focus lines", 400, 45, 80, 50, $BS_MULTILINE) $hButton_Tab = GUICtrlCreateButton("Show all control focus lines", 400, 145, 80, 50, $BS_MULTILINE) $hLabel_Global = GUICtrlCreateLabel("Global = " & $fGlobal, 400, 15, 100) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE #cs If $fGlobal = true Then _NoFocusLines_Global_Exit() Else _NoFocusLines_Exit() EndIf #ce Exit Case $hButton_1 GUICtrlSetData($hLabel_B1, "Button pressed") Sleep(500) GUICtrlSetData($hLabel_B1, "") Case $hButton_2 GUICtrlSetData($hLabel_B2, "Button pressed") Sleep(500) GUICtrlSetData($hLabel_B2, "") Case $hRadio_1 If GUICtrlRead($hRadio_1) = $GUI_CHECKED Then GUICtrlSetData($hLabel_R1, "Selected") GUICtrlSetData($hLabel_R2, "") Else GUICtrlSetData($hLabel_R2, "Selected") GUICtrlSetData($hLabel_R1, "") EndIf Case $hRadio_2 If GUICtrlRead($hRadio_2) = $GUI_CHECKED Then GUICtrlSetData($hLabel_R2, "Selected") GUICtrlSetData($hLabel_R1, "") Else GUICtrlSetData($hLabel_R1, "Selected") GUICtrlSetData($hLabel_R2, "") EndIf Case $hCheck_1 If GUICtrlRead($hCheck_1) = $GUI_CHECKED Then GUICtrlSetData($hLabel_C1, "Selected") Else GUICtrlSetData($hLabel_C1, "") EndIf Case $hCheck_2 If GUICtrlRead($hCheck_2) = $GUI_CHECKED Then GUICtrlSetData($hLabel_C2, "Selected") Else GUICtrlSetData($hLabel_C2, "") EndIf Case $hButton_Action ; Remove focus lines from slider_1 _NoFocusLines_Set($hSlider_1) ConsoleWrite("Slider: " & @error & @CRLF) ; Remove focus lines from top button, radio and checkbox Dim $aCID[4] = [$hButton_1, $hRadio_1, $hCheck_1, $hButton_Action] ; Place multiple ControlIDs in an array _NoFocusLines_Set($aCID) ConsoleWrite("Button: " & @error & @CRLF) ; Shows it will not work if used with other control type _NoFocusLines_Set($hLabel_B1) ConsoleWrite("Label: " & @error & @CRLF) ; Show Global function will not work after Specific, or previous Global, call _NoFocusLines_Global_Set() ConsoleWrite("Global: " & @error & @CRLF) Case $hButton_Tab ; Force focus lines to appear Send("{TAB}") ; Allow lines to appear Dim $aCID[5] = [$hSlider_1, $hButton_1, $hRadio_1, $hCheck_1, $hButton_Action] _NoFocusLines_Clear($aCID) ConsoleWrite("Clear: " & @error & @CRLF) EndSwitch If GUICtrlRead($hSlider_1) <> $iPos_1 Then $iPos_1 = GUICtrlRead($hSlider_1) GUICtrlSetData($hLabel_S1, "Slider 1: " & $iPos_1) EndIf If GUICtrlRead($hSlider_2) <> $iPos_2 Then $iPos_2 = GUICtrlRead($hSlider_2) GUICtrlSetData($hLabel_S2, "Slider 2: " & $iPos_2) EndIf WEnd On running the example script you are asked to choose either "Global" or "Specific" mode: "Global" mode permanently prevents focus lines on all controls - there is no easy way to reallow the lines (or at least one I am prepared to develop!). "Specific" mode allows you to prevent/allow the focus lines on specified controls. At first, as long as you only use the mouse to change focus you should find no focus lines on the controls - because a button is present. Pressing the "Show all focus lines" button, or pressing TAB yourself to change focus, will allow the lines become visible when the control has focus - remember you still have to select the sliders with the mouse, they have no TABSTOP property. Pressing the "Hide upper" button will, not surprisingly, prevent the lines from appearing on the top set of controls (if one of these controls has focus at that time, the lines will remain until the focus is changed - obviously we cannot intercept a previous message!). Repressing the "Show all focus lines" button will reallow focus lines on the upper controls. You can toggle the lines on and off as often as you wish. The 2 modes are obviously mutually exclusive - but the UDF will automatically detect the first mode used and prevent the other from running. This can be seen as the example script runs and the various errorlevels from the UDF calls made are printed in the SciTE console. A few points: 1. As previously stated, the _NoFocusLines_Global function can only be called once - BEFORE any controls are created. The _NoFocusLines_Set and _NoFocusLines_Clear functions can be called as and when required - but only AFTER the specified controls have been created. 2. When you want to delete controls which have been subclassed by _NoFocusLines_Set before the script exits, you should use _NoFocusLines_Clear before deleting - just in case Windows reallocates the handle. [NEW] Calling _NoFocusLines_Clear with no parameter resets all currently subclassed controls without having to specify the ControlIDs. 3. [NEW] In either mode, on finally exiting the script, AutoIt will run the cleanup script to delete all subclassed controls and free the memory used by the UDF created WndProc. 4. The "Specific" mode functions require the ControlIDs in array format if there is more than one. I accept that this means having to declare an array just to use the function, but I could not think of any other way to get an undefined number of parameters into the function. 5. The code uses _WinAPI_SetWindowLong, which according to MSDN means that it will not work on x64 systems. If anyone wants to modify the code for x64, please do so. [NEW] Here are the 2 files in zip form: NoFocusLines.zip Just to reiterate my thanks to Siao, aec and martin, whose basic code I plundered without pity; Yashied, whose "hint" made the whole UDF much better; rover for the "Global" mode code; and Valik for advice on the exit strategy. "Standing on the shoulders of giants", as Newton once put it, always makes life easier! As always, happy to hear comments and suggestions. M231 point
-
Version 1.2
29,311 downloads
I wrote an introductory text for new programmers to learn how to code using AutoIt. It follows along with the help file for the most part – but provides additional context and attempts to connect all the information in a cohesive way for someone without any programming experience. I find the help file to be an AMAZING resource and the text I wrote in no way reflects any opinion to the contrary. Rather, it was created from the perspective of someone who struggled early on with the most basic concepts and thought that a hand-holding guide could be useful. I was also inspired by code.org who is trying to encourage people to learn to code. I thought – what better way than to use free tools that you can download at any time with access to an amazing community? If only there was a guide to walk people through it … Full discussion about the file can be found here: https://www.autoitscript.com/forum/topic/174205-introductory-learn-to-program-text-using-au3/1 point -
July 8, 2018: New SciTE4AutoIt3 available with the updated SciTE v4.1.0 release
ModemJunki reacted to Jos for a topic
Try: "\\Include\\NewIcon.ico" Jos1 point -
_Excel_BookAttach is too slow!
Ahmed101 reacted to FrancescoDiMuro for a topic
Hey @water I am writing from smartphone... I thought that the parameters to be filled were implied I know that you can't call that function without parameters.. Best Regards.1 point -
Ahmed101, which version of Excel do you run?1 point
-
$arrWorkbooks[$i] = _Excel_BookAttach() Doesn't work. _Excel_BookAttach needs at least one parameter.1 point
-
_Excel_BookAttach is too slow!
Ahmed101 reacted to FrancescoDiMuro for a topic
; Declare your Global array of Worbooks Global $arrWorkbooks[10] ; Here, it dipends on how your workbooks are named... ; You can think to define an array of workbooks names, or just a prefix ( if they have same name, but are numbered ) For $i = 0 To UBound($arrWorkbooks) - 1 $arrWorkbooks[$i] = _Excel_BookAttach() If @error Then ; Error Handling EndIf Next Something like this1 point -
_Excel_BookAttach is too slow!
Ahmed101 reacted to FrancescoDiMuro for a topic
@Ahmed101, you could use a For...Next loop to attach workbook in an array of Workbooks I think it could be a little faster, and surely more compact Best Regards.1 point -
Did you know that this forum has a SEARCH feature? Why don't you enter something like "JSON" in it and see what comes up?1 point
-
1 point
-
As usual it is hard to resist the temptation to beaver away at implementing things once I get started. I've added some Series related fields and done a good part of the code, so many elements of it are now working, despite the complexity ... what have I let myself in for. I may upload something today/tomorrow. I also changed some of the controls around in the lower half of the GUI, and tied control positions for the bottom half, to the height ($height) of the GUI, which means i can adjust the middle section of the GUI at need without having to alter height values for the lower controls. As I have placed the Series stuff in the middle of the GUI, requiring the Thumb images and adjacent controls to move downward, it is looking less likely I will add a third row of thumbnails now. Not a real great loss though, as most authors I have, only have one book anyway, and a good number that have more go beyond 15 anyway. Talking about Series. That is also another area that calibre doesn't quite do a good enough job in. I have many books that belong to more than one series, and calibre is not really setup to deal with more than one. I will certainly be looking at a way to support such .... my head just went into a spin contemplating the complexity ... LOL. While I hope to support whatever a current calibre user has setup, it will be true that I will be recommending a specific kind of way to use calibre, if you are also using CalibBrowser. That will mean, that both programs will work better, and less manual interaction to adapt things. One good recommendation, is that you only have one calibre library, and instead rely on CalibBrowser to give you others. With that one calibre library, also make sure you are happy with where it is located ... perhaps on a second drive or partition if they exist in your machine, that allows for growth. I certainly would not recommend wasting space on a SSD for such data, if you have your OS on one of those ... that applies to all other sorts of data files too. No doubt another reason for calibre to have its file & folder duplicating structure, is due to the very real possibility a user may want to relocate their library or libraries. My program CalibBrowser, will of course need to keep tabs on paths etc, and like calibre, also support rebuilding any library database file, that may become corrupt, etc. It will also support relocation.1 point
-
!!AUTOIT SCRIPT LOOP!!
FrancescoDiMuro reacted to Jos for a topic
@BogdanNicolescu, What exactly is the question here? Jos1 point -
Extract data from Website. - (Moved)
BogdanNicolescu reacted to wolflake for a topic
Look at the help file under _Excel_RangeRead to get the A column read into an Array. Read the example for reading "A1" then use a range instead of a single cell. "A1:A999" Use a (for next) loop to go through the array of cells you have read. Use send("^v") to paste. Use Au3Info.exe in the autoit directory to find the x,y mouse positions for your clicking. You can drag the finder tool and look at the ControlClick Coords in the tool. Try running little bits of code to get each part to work then put the parts together.1 point -
!!AUTOIT SCRIPT LOOP!!
FrancescoDiMuro reacted to Earthshine for a topic
edit: this looks like it may be gaming related.1 point -
ElseIf vs Else If
FrancescoDiMuro reacted to JLogan3o13 for a topic
You understand you could have tested this yourself and had an answer in less time than it took to type out your post, right?1 point -
endfunc
ibrahem reacted to Earthshine for a topic
That was sarcasm I hope you got that but yeah the tidy program that is included does this and also in the tools menu if you place the cursor on a function name it'll create a function header for you. I believe there's a create function header or UDF header or something like that1 point -
question about RequireAdmin
nacerbaaziz reacted to AdamUL for a topic
Another options is to use the "runas" verb with ShellExecute or ShellExecuteWait. MsgBox(0, "Test", "User is " & (IsAdmin() ? "" : "not ") & "Admin.") If Not IsAdmin() Then _RerunAsAdmin() Else MsgBox(0, "Is Admin?", "Yes, Admin.") ;Example. EndIf Func _RerunAsAdmin() Local $sParameters = "" If Not @Compiled Then $sParameters = '"' & @ScriptFullPath & '"' EndIf ShellExecute(@AutoItExe, $sParameters, "", "runas") If @error Then Return MsgBox(16 + 262144, "ERROR!", "Unable to elevate to Admin due to UAC.") EndFunc Adam1 point -
WebDriver UDF - Help & Support
PoojaKrishna reacted to Danyfirex for a topic
Hello. Here are two functions that we will allow us to highlight the element(s) we're using. ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_HighlightElement ; Description ...: ; Syntax ........: __WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $sElement - Element ID from _WDFindElement ; $iMethod - [optional] an integer value. Default is 1. ; 1=style -> Highlight border dotted red ; 2=style -> Highlight yellow rounded box ; 3=style -> Highlight yellow rounded box + border dotted red ; Return values .: Success - True ; Failure - False ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_HighlightElement($sSession, $sElement, $iMethod = 1) Local Const $aMethod[] = ["border: 2px dotted red", _ "background: #FFFF66; border-radius: 5px; padding-left: 3px;", _ "border:2px dotted red;background: #FFFF66; border-radius: 5px; padding-left: 3px;"] If $iMethod < 1 Or $iMethod > 3 Then $iMethod = 1 Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $sElement & '"}' Local $sResponse = _WD_ExecuteScript($sSession, "arguments[0].style='" & $aMethod[$iMethod - 1] & "'; return true;", $sJsonElement) Local $sJSON = Json_Decode($sResponse) Local $sResult = Json_Get($sJSON, "[value]") Return ($sResult = "true" ? SetError(0, 0, $sResult) : SetError(1, 0, False)) EndFunc ;==>__WD_HighlightElement ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_HighlightElements ; Description ...: ; Syntax ........: __WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $aElements - an array of Elements ID from _WDFindElement ; $iMethod - [optional] an integer value. Default is 1. ; 1=style -> Highlight border dotted red ; 2=style -> Highlight yellow rounded box ; 3=style -> Highlight yellow rounded box + border dotted red ; Return values .: Success - True ; Failure - False ; @Extended Number of Highlighted Elements ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_HighlightElements($sSession, $aElements, $iMethod = 1) Local $iHighlightedElements = 0 For $i = 0 To UBound($aElements) - 1 $iHighlightedElements += (__WD_HighlightElement($sSession, $aElements[$i], $iMethod) = True ? 1 : 0) Next Return ($iHighlightedElements > 0 ? SetError(0, $iHighlightedElements, True) : SetError(1, 0, False)) EndFunc ;==>__WD_HighlightElements How to use: _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://google.com") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hplogo']") __WD_HighlightElement($sSession, $sElement) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='btnK']") __WD_HighlightElement($sSession, $sElement,2) Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='gb_P']", "", True) __WD_HighlightElements($sSession, $aElements,3) Sleep(10000) _WD_DeleteSession($sSession) _WD_Shutdown() Preview: Saludos1 point -
Server to run a autoit script from another pc
PleaseHelpMEIWillLoveyou reacted to KickStarter15 for a topic
Maybe if you will use the send and received method that can solve your problem. Let's say something like sending a txt file on a shared folder as what Juvigy said. How? 1. PC1, create a script that will send a text file on that specific shared folder with 0mb. 2. PC2, create a script that will loop to that shared folder looking for the specific text file using FileFindFirstFile() and FileFindNextFile(). 3. Once the script in PC2 find the specific text file, then it will run and you should directly delete the text file before the whole script run (else it will loop back many times). Or, I suggest search for chat script in this forum and you will see what I mean. Chat script has the same scenario as I stated above. Here's a sample script where you can start with. PC1 script: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "Terminate") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("PC1", 150, 80, 300, 200) $Button1 = GUICtrlCreateButton("Send", 16, 20, 81, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $logPath = "\\10.0.0.0\Shared\Test\" $info = MsgBox(4, "Sending Command in PC2", "This is just a confirmation!") If $info = 6 Then $hFile = FileOpen($logPath & "Test.log", 1) FileWriteLine($hFile, "") FileClose($hFile) Exit Else Exit EndIf EndSwitch WEnd PC2 script: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUISetState(@SW_HIDE) ; this will hide the process... While 1 Sleep(1000) Example() WEnd Func _RemoveFileExt($string) Return StringLeft($string,StringInStr($string,".",Default,-1)-1) EndFunc Func Example() $LogPath = "\\10.0.0.0\Shared\Test\*" ; this is you shared folder Local $hSearch = FileFindFirstFile($LogPath) $sFileName = FileFindNextFile($hSearch) If FileExists($LogPath & ".log") Then FileDelete("\\10.0.0.0\Shared\Test\" & $sFileName) $Form2 = GUICreate("PC2", 160, 100, 200, 124) $Button1 = GUICtrlCreateButton("Click Me", 16, 20, 81, 33) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0,"",$sFileName) EndSwitch WEnd EndIf EndFunc If that's what you want.1 point -
Solar Position UDF
robertocm reacted to tim292stro for a topic
Hi, I've been building up an AutoIt home automation script over the past months and one script I just finished this weekend I thought I'd share. This function allows you to calculate your sun-rise, sun-set, and solar-noon times for a given latitude and longitude - plus it allows you to calculate the current relative position of the sun to your position. The original code was JavaScrip from a NOAA website, they have graciously allowed me to convert it to AutoIt Script, so long as I reference the website that I obtained the code from which is: http://www.esrl.noaa.gov/gmd/grad/solcalc/ I will make the same disclaimer that NOAA makes regarding accuracy: “this calculator function is for ‘entertainment only’ – the author’s cannot be held accountable for accuracy issues and bugs in critical systems” Here is the UDF (select all and save as "SunPosition.au3" in your include folder...): #include-once #include <array.au3> #include <Math.au3> #include <Date.au3> ; #INDEX# ======================================================================================================================= ; Title .........: SunPosition ; AutoIt Version : 3.3.6++ ; Language ......: English ; Description ...: Function that allows the sun's postion to be calculated relative to a geographical position (lat/long) ; ; Author(s) .....: Tim Strommen (tim292stro), original Javascript source from NOAA "http://www.esrl.noaa.gov/gmd/grad/solcalc/" ; Dll(s) ........: N/A ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $Pi = 4 * ATan(1) Global Const $MonthLength[12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] Global Const $MonthFullName[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] Global Const $MonthAbrev[12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_GetSolarAstronimicalData ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetSolarAstronimicalData ; Description ...: Calculate the position of the sun relative to a position on earth for a given time/date. ; Syntax.........: _GetSolarAstronimicalData ( $Latitude, $Longitude, $Month, $MDay, $Year, $TimeZone, $Hour, $Minute, $Second, $DST ) ; Parameters ....: $Latitude - The Latitude portion of the earth position to calculate the sun's position relative to (float) ; $Longitude - The Latitude portion of the earth position to calculate the sun's position relative to (float) ; $Month - The month of the year you are calculating for (numeric-string: "1-12") ; $MDay - The day of the month you are calculating for (numeric-string: "1-31") ; $Year - The year you are calculating for (numeric-string: "-2000 to 3000") ; $TimeZone - The time zone you are calculating for (numeric-string: "-11 to 12") ; $Hour - Optional! The hour you are calculating for in 24-hrs (numeric-string: "0-23") ; $Minute - Optional! The minute you are calculating for (numeric-string: "00-59") ; $Second - Optional! The second you are calculating for (numeric-string: "00-59") ; $DST - Optional! Is Daylight Saving's Time in effect? (boolean) ; Return values .: Success - Returns an array with the following values: ; 0 = Element count. If count = 3, then only items 1-3 available. If count = 6, then all elements available) ; 1 = Sunrise time "07:12" 24-hr time, or "07:12 Jul 17" if position is near international date line ; 2 = Solar Noon "13:16:46" 24-hr time with seconds. Higest point of sun in sky. ; 3 = Sunset time "19:22" 24-hr time, or "19:22 Jul 19" if position is near international date line ; 4 = Sun Azimuth in degrees relative to computed position (0deg = true north, 180deg = true south, 90deg = East, 270 = West) ; 5 = Sun Elevation is degrees relative to computed position at sea-level ; 6 = Ambient light disposition (possibilities: Day, Civil Twilight, Nautical Twilight, Astronomical Twilight, Night) ; Author ........: Tim Strommen (tim292stro) ; Modified.......: ; Remarks .......: Again, special thanks to NOAA for allowing re-use of their code!! See: "http://www.esrl.noaa.gov/" ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GetSolarAstronimicalData ( $AstroLat = "", $AstroLong = "", $AstroMonth = "", $AstroDay = "", $AstroYear = "", $AstroTimeZone = "", $AstroHour = "", $AstroMinute = "", $AstroSecond = "", $AstroDST = False ) Local $AstroBeginAT, $AstroBeginNT, $AstroBeginCT, $AstroSunrise, $AstroSolarNoon, $AstroSunset, $AstroEndCT, $AstroEndNT, $AstroEndAT, $AstroSolarElevation, $AstroSolarAzimuth If ( $AstroLat = "" ) OR ( $AstroLong = "" ) Then ; Return current Greenwich, UK basic times with current solar position $AstroLat = "51.48" $AstroLong = "0.000000001" $AstroTimeZone = "0" $AstroMonth = @MON $AstroDay = @MDAY $AstroYear = @YEAR $AstroHour = @HOUR $AstroMinute = @MIN $AstroSecond = @SEC $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, True ) Return $RetunedArray ElseIf $AstroHour = "" Then ; Just return the specified day's basic times, no current solar position $AstroHour = "12" $AstroMinute = "00" $AstroSecond = "00" $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, False ) Return $RetunedArray Else ; Return both the basic times, plus the current solar position $RetunedArray = _SolarCalculate ( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST, True ) Return $RetunedArray EndIf EndFunc ;==>_GetSolarAstronimicalData #cs ********** Developer Notice!!! ********** The following are the original NOAA Javascripts with minor modifications to support programmatic query instead of web-form query. The original Javascript text preceeds the AutoIt-v3 conversion and are provided with gracious permission from NOAA. The original webform and calculator is located at: "http://www.esrl.noaa.gov/gmd/grad/solcalc/" Thank you again NOAA!! -Tim S. <script type="text/javascript"> function calcTimeJulianCent(jd) { var T = (jd - 2451545.0)/36525.0 return T } #ce Func _CalcTimeJulianCent( $jd = 0 ) Local $Time = ( $jd - 2451545.0 ) / 36525.0 Return $Time EndFunc #cs function calcJDFromJulianCent(t) { var JD = t * 36525.0 + 2451545.0 return JD } #ce Func _CalcJDFromJulianCent ( $t = 0 ) Local $JD = $t * 36525.0 + 2451545.0 Return $JD EndFunc #cs function isLeapYear(yr) { return ((yr % 4 == 0 && yr % 100 != 0) || yr % 400 == 0); } #ce Func _isLeapYear ( $yr = 0 ) Return ( ( Mod ( $yr, 4 ) And Mod ($yr, 100 ) ) Or ( Mod ( $yr, 400 ) = 0 ) ) EndFunc #cs function calcDoyFromJD(jd) { var z = Math.floor(jd + 0.5); var f = (jd + 0.5) - z; if (z < 2299161) { var A = z; } else { alpha = Math.floor((z - 1867216.25)/36524.25); var A = z + 1 + alpha - Math.floor(alpha/4); } var B = A + 1524; var C = Math.floor((B - 122.1)/365.25); var D = Math.floor(365.25 * C); var E = Math.floor((B - D)/30.6001); var day = B - D - Math.floor(30.6001 * E) + f; var month = (E < 14) ? E - 1 : E - 13; var year = (month > 2) ? C - 4716 : C - 4715; var k = (isLeapYear(year) ? 1 : 2); var doy = Math.floor((275 * month)/9) - k * Math.floor((month + 9)/12) + day -30; return doy; } #ce Func _calcDoyFromJD ( $jd = 0 ) Local $z = Floor ( $jd + 0.5 ) Local $f = ( $jd + 0.5 ) - $z Local $A, $alpha, $B, $C, $D, $doy, $E, $day, $month, $year, $K If $z < 2299161 Then $A = $z Else $alpha = Floor ( ( $z - 1867216.25 ) / 36524.25 ) $A = $z + 1 + $alpha - Floor ( $alpha / 4 ) EndIf $B = $A + 1524 $C = Floor ( ( $B - 122.1 ) / 365.25 ) $D = Floor ( 365.25 * $C ) $E = Floor ( ( $B - $D ) / 30.6001 ) $day = $B - $D - Floor ( 30.6001 * $E ) + $f If $E < 14 Then $month = $E - 1 Else $month = $E - 13 EndIf If $month > 2 Then $year = $C - 4716 Else $year = $C - 4715 EndIf If _isLeapYear ( $year ) Then $K = 1 Else $K = 2 EndIf $doy = Floor ( ( 275 * $month ) / 9 ) - $K * Floor ( ( $month + 9 ) / 12 ) + $day - 30 Return $doy EndFunc #cs function radToDeg(angleRad) { return (180.0 * angleRad / Math.PI); } #ce Func _radToDeg ( $AngleRad = 0 ) Return 180.0 * $AngleRad / $Pi EndFunc #cs function degToRad(angleDeg) { return (Math.PI * angleDeg / 180.0); } #ce Func _degToRad ( $AngleDeg = 0 ) Return $Pi * $AngleDeg / 180.0 EndFunc #cs function calcGeomMeanLongSun(t) { var L0 = 280.46646 + t * (36000.76983 + t*(0.0003032)) while(L0 > 360.0) { L0 -= 360.0 } while(L0 < 0.0) { L0 += 360.0 } return L0 // in degrees } #ce Func _calcGeomMeanLongSun ( $t = 0 ) Local $L0 = 280.46646 + $t * ( 36000.76983 + $t * (0.0003032) ) While $L0 > 360.0 $L0 -= 360.0 WEnd While $L0 < 0.0 $L0 += 360.0 WEnd Return $L0 ; in degrees EndFunc #cs function calcGeomMeanAnomalySun(t) { var M = 357.52911 + t * (35999.05029 - 0.0001537 * t); return M; // in degrees } #ce Func _calcGeomMeanAnomalySun ( $t = 0 ) Local $M = 357.52911 + $t * (35999.05029 - 0.0001537 * $t ) Return $M ; in degrees EndFunc #cs function calcEccentricityEarthOrbit(t) { var e = 0.016708634 - t * (0.000042037 + 0.0000001267 * t); return e; // unitless } #ce Func _calcEccentricityEarthOrbit ( $t = 0 ) Local $e = 0.016708634 - $t * ( 0.000042037 + 0.0000001267 * $t ) Return $e ; unitless EndFunc #cs function calcSunEqOfCenter(t) { var m = calcGeomMeanAnomalySun(t); var mrad = degToRad(m); var sinm = Math.sin(mrad); var sin2m = Math.sin(mrad+mrad); var sin3m = Math.sin(mrad+mrad+mrad); var C = sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289; return C; // in degrees } #ce Func _calcSunEqOfCenter ( $t = 0 ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $mrad = _degToRad ( $m ) Local $sinm = Sin ( $mrad ) Local $sin2m = Sin ( $mrad + $mrad ) Local $sin3m = Sin ( $mrad + $mrad + $mrad ) Local $C = $sinm * ( 1.914602 - $t * ( 0.004817 + 0.000014 * $t ) ) + $sin2m * ( 0.019993 - 0.000101 * $t ) + $sin3m * 0.000289 Return $C EndFunc #cs function calcSunTrueLong(t) { var l0 = calcGeomMeanLongSun(t); var c = calcSunEqOfCenter(t); var O = l0 + c; return O; // in degrees } #ce Func _calcSunTrueLong ( $t = 0 ) Local $lo = _calcGeomMeanLongSun ( $t ) Local $c = _calcSunEqOfCenter ( $t ) Local $O = $lo + $c Return $O ; in degrees EndFunc #cs function calcSunTrueAnomaly(t) { var m = calcGeomMeanAnomalySun(t); var c = calcSunEqOfCenter(t); var v = m + c; return v; // in degrees } #ce Func _calcSunTrueAnomaly ( $t = 0 ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $c = _calcSunEqOfCenter ( $t ) Local $v = $m + $c Return $v EndFunc #cs function calcSunRadVector(t) { var v = calcSunTrueAnomaly(t); var e = calcEccentricityEarthOrbit(t); var R = (1.000001018 * (1 - e * e)) / (1 + e * Math.cos(degToRad(v))); return R; // in AUs } #ce Func _calcSunRadVector ( $t = 0 ) Local $v = _calcSunTrueAnomaly ( $t ) Local $e = _calcEccentricityEarthOrbit ( $t ) Local $R = ( 1.000001018 * ( 1 - $e * $e ) ) / ( 1 + $e * cos ( _degToRad ( $v ) ) ) Return $R ; in AUs EndFunc #cs function calcSunApparentLong(t) { var o = calcSunTrueLong(t); var omega = 125.04 - 1934.136 * t; var lambda = o - 0.00569 - 0.00478 * Math.sin(degToRad(omega)); return lambda; // in degrees } #ce Func _calcSunApparentLong ( $t = 0 ) Local $o = _calcSunTrueLong ( $t ) Local $omega = 125.04 - 1934.136 * $t Local $lambda = $o - 0.00569 - 0.00478 * Sin ( _degToRad ( $omega ) ) Return $lambda ; in degrees EndFunc #cs function calcMeanObliquityOfEcliptic(t) { var seconds = 21.448 - t*(46.8150 + t*(0.00059 - t*(0.001813))); var e0 = 23.0 + (26.0 + (seconds/60.0))/60.0; return e0; // in degrees } #ce Func _calcMeanObliquityOfEcliptic ( $t = 0 ) Local $seconds = 21.448 - $t * ( 46.8150 + $t * ( 0.00059 - $t * ( 0.001813 ) ) ) Local $e0 = 23.0 + ( 26.0 + ( $seconds / 60.0 ) ) / 60.0 Return $e0 ; in degrees EndFunc #cs function calcObliquityCorrection(t) { var e0 = calcMeanObliquityOfEcliptic(t); var omega = 125.04 - 1934.136 * t; var e = e0 + 0.00256 * Math.cos(degToRad(omega)); return e; // in degrees } #ce Func _calcObliquityCorrection ( $t = 0 ) Local $e0 = _calcMeanObliquityOfEcliptic ( $t ) Local $omega = 125.04 - 1934.136 * $t Local $e = $e0 + 0.00256 * Cos ( _degToRad ( $omega ) ) Return $e EndFunc #cs function calcSunRtAscension(t) { var e = calcObliquityCorrection(t); var lambda = calcSunApparentLong(t); var tananum = (Math.cos(degToRad(e)) * Math.sin(degToRad(lambda))); var tanadenom = (Math.cos(degToRad(lambda))); var alpha = radToDeg(Math.atan2(tananum, tanadenom)); return alpha; // in degrees } #ce Func _calcSunRtAscension ( $t = 0 ) Local $e = _calcObliquityCorrection ( $t ) Local $lambda = _calcSunApparentLong ( $t ) Local $tananum = ( Cos ( _degToRad ( $e ) ) * Sin ( _degToRad ( $lambda ) ) ) Local $tanadenom = ( Cos ( _degToRad ( $lambda ) ) ) Local $alpha = _radToDeg ( _atan2 ( $tananum, $tanadenom ) ) Return $alpha ; in degrees EndFunc #cs function calcSunDeclination(t) { var e = calcObliquityCorrection(t); var lambda = calcSunApparentLong(t); var sint = Math.sin(degToRad(e)) * Math.sin(degToRad(lambda)); var theta = radToDeg(Math.asin(sint)); return theta; // in degrees } #ce Func _calcSunDeclination ( $t = 0 ) Local $e = _calcObliquityCorrection ( $t ) Local $lambda = _calcSunApparentLong ( $t ) Local $sint = Sin ( _degToRad ( $e ) ) * Sin ( _degToRad ( $lambda ) ) Local $theta = _radToDeg ( ASin ( $sint ) ) return $theta ; in degrees EndFunc #cs function calcEquationOfTime(t) { var epsilon = calcObliquityCorrection(t); var l0 = calcGeomMeanLongSun(t); var e = calcEccentricityEarthOrbit(t); var m = calcGeomMeanAnomalySun(t); var y = Math.tan(degToRad(epsilon)/2.0); y *= y; var sin2l0 = Math.sin(2.0 * degToRad(l0)); var sinm = Math.sin(degToRad(m)); var cos2l0 = Math.cos(2.0 * degToRad(l0)); var sin4l0 = Math.sin(4.0 * degToRad(l0)); var sin2m = Math.sin(2.0 * degToRad(m)); var Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m; return radToDeg(Etime)*4.0; // in minutes of time } #ce Func _calcEquationOfTime ( $t = 0 ) Local $epsilon = _calcObliquityCorrection ( $t ) Local $l0 = _calcGeomMeanLongSun ( $t ) Local $e = _calcEccentricityEarthOrbit ( $t ) Local $m = _calcGeomMeanAnomalySun ( $t ) Local $y = Tan ( _degToRad ( $epsilon ) / 2.0 ) $y *= $y Local $sin2l0 = Sin ( 2.0 * _degToRad ( $l0 ) ) Local $sinm = Sin ( _degToRad ( $m ) ) Local $cos2l0 = Cos ( 2.0 * _degToRad ( $l0 ) ) Local $sin4l0 = Sin ( 4.0 * _degToRad ( $l0 ) ) Local $sin2m = Sin ( 2.0 * _degToRad ( $m ) ) Local $Etime = $y * $sin2l0 - 2.0 * $e * $sinm + 4.0 * $e * $y * $sinm * $cos2l0 - 0.5 * $y * $y * $sin4l0 - 1.25 * $e * $e * $sin2m Return _radToDeg ( $Etime ) * 4.0 ; in minutes of time EndFunc #cs function calcHourAngleSunrise(lat, solarDec) { var latRad = degToRad(lat); var sdRad = degToRad(solarDec); var HAarg = (Math.cos(degToRad(90.833))/(Math.cos(latRad)*Math.cos(sdRad))-Math.tan(latRad) * Math.tan(sdRad)); var HA = Math.acos(HAarg); return HA; // in radians (for sunset, use -HA) } #ce ;SunRise = Horizon+0.8333 Func _calcHourAngleSunrise( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 90.833 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;CivilTwilight = (Horizon+6) < SunCenter < (Horizon+0.8333) Func _calcHourAngleCivilTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 96.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;NauticalTwilight = (Horizon+12) < SunCenter < (Horizon+6) Func _calcHourAngleNauticalTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 102.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning (for evening, use -HA) EndFunc ;AstronimicalTwilight = (Horizon+18) < SunCenter < (Horizon+12) Func _calcHourAngleAstronimicalTwilight( $lat, $solarDec ) Local $latRad = _degToRad ( $lat ) Local $sdRad = _degToRad ( $solarDec ) Local $HAarg = ( Cos ( _degToRad ( 108.0 ) ) / ( Cos ( $latRad ) * Cos ( $sdRad ) ) - Tan ( $latRad ) * Tan ( $sdRad ) ) Local $HA = ACos ( $HAarg ) Return $HA ; in radians for morning ( for evening, use -HA ) EndFunc #cs function isNumber(inputVal) { var oneDecimal = false; var inputStr = "" + inputVal; for (var i = 0; i < inputStr.length; i++) { var oneChar = inputStr.charAt(i); if (i == 0 && (oneChar == "-" || oneChar == "+")) { continue; } if (oneChar == "." && !oneDecimal) { oneDecimal = true; continue; } if (oneChar < "0" || oneChar > "9") { return false; } } return true; } #ce Func _isNumber ( $inputval ) Return ( IsFloat ( $inputval ) Or IsNumber ( $inputval ) Or IsInt ( $inputval ) ) EndFunc #cs function zeroPad(n, digits) { n = n.toString(); while (n.length < digits) { n = '0' + n; } return n; } #ce Func _zeroPad ( $n, $digits ) $n = String ( $n ) While StringLen ( $n ) < $digits $n = "0" & $n WEnd Return $n EndFunc #cs function month(name, numdays, abbr) { this.name = name; this.numdays = numdays; this.abbr = abbr; } var monthList = new Array(); var i = 0; monthList[i++] = new month("January", 31, "Jan"); monthList[i++] = new month("February", 28, "Feb"); monthList[i++] = new month("March", 31, "Mar"); monthList[i++] = new month("April", 30, "Apr"); monthList[i++] = new month("May", 31, "May"); monthList[i++] = new month("June", 30, "Jun"); monthList[i++] = new month("July", 31, "Jul"); monthList[i++] = new month("August", 31, "Aug"); monthList[i++] = new month("September", 30, "Sep"); monthList[i++] = new month("October", 31, "Oct"); monthList[i++] = new month("November", 30, "Nov"); monthList[i++] = new month("December", 31, "Dec"); #ce ; Global variable defined at top of file... #cs function getJD() { var docmonth = document.getElementById("mosbox").selectedIndex + 1 var docday = document.getElementById("daybox").selectedIndex + 1 var docyear = readTextBox("yearbox", 5, 1, 0, -2000, 3000, 2009) if ( (isLeapYear(docyear)) && (docmonth == 2) ) { if (docday > 29) { docday = 29 document.getElementById("daybox").selectedIndex = docday - 1 } } else { if (docday > monthList[docmonth-1].numdays) { docday = monthList[docmonth-1].numdays document.getElementById("daybox").selectedIndex = docday - 1 } } if (docmonth <= 2) { docyear -= 1 docmonth += 12 } var A = Math.floor(docyear/100) var B = 2 - A + Math.floor(A/4) var JD = Math.floor(365.25*(docyear + 4716)) + Math.floor(30.6001*(docmonth+1)) + docday + B - 1524.5 return JD } #ce Func _getJD ( $CompJDMon = "", $CompJDDay = "", $CompJDYear = "" ) If ( ( _isLeapYear ( $CompJDYear ) ) And ( $CompJDMon = 2 ) ) Then If $CompJDDay > 29 Then $CompJDDay = 29 EndIf Else If $CompJDDay > $MonthLength[$CompJDMon] Then $CompJDDay = $MonthLength[$CompJDMon] EndIf EndIf If $CompJDMon <= 2 Then $CompJDYear -= 1 $CompJDMon += 12 EndIf Local $A = Floor ( $CompJDYear / 100 ) Local $B = 2 - $A + Floor ( $A / 4 ) Local $JD = Floor ( 365.25 * ( $CompJDYear + 4716 ) ) + Floor ( 30.6001 * ( $CompJDMon + 1 ) ) + $CompJDDay + $B - 1524.5 Return $JD EndFunc #cs function getTimeLocal() { var dochr = readTextBox("hrbox", 2, 1, 1, 0, 23, 12) var docmn = readTextBox("mnbox", 2, 1, 1, 0, 59, 0) var docsc = readTextBox("scbox", 2, 1, 1, 0, 59, 0) var docpm = document.getElementById("pmbox").checked var docdst = document.getElementById("dstCheckbox").checked if ( (docpm) && (dochr < 12) ) { dochr += 12 } if (docdst) { dochr -= 1 } var mins = dochr * 60 + docmn + docsc/60.0 return mins } #ce Func _getTimeLocal ( $CompHour = "", $CompMin = "", $CompSec = "", $CompDST = False ) If ( $CompDST ) Then $CompHour -= 1 EndIf Local $mins = $CompHour * 60 + $CompMin + $CompSec / 60.0 Return $mins EndFunc #cs function calcAzEl(output, T, localtime, latitude, longitude, zone) { var eqTime = calcEquationOfTime(T) var theta = calcSunDeclination(T) if (output) { document.getElementById("eqtbox").value = Math.floor(eqTime*100 +0.5)/100.0 document.getElementById("sdbox").value = Math.floor(theta*100+0.5)/100.0 } var solarTimeFix = eqTime + 4.0 * longitude - 60.0 * zone var earthRadVec = calcSunRadVector(T) var trueSolarTime = localtime + solarTimeFix while (trueSolarTime > 1440) { trueSolarTime -= 1440 } var hourAngle = trueSolarTime / 4.0 - 180.0; if (hourAngle < -180) { hourAngle += 360.0 } var haRad = degToRad(hourAngle) var csz = Math.sin(degToRad(latitude)) * Math.sin(degToRad(theta)) + Math.cos(degToRad(latitude)) * Math.cos(degToRad(theta)) * Math.cos(haRad) if (csz > 1.0) { csz = 1.0 } else if (csz < -1.0) { csz = -1.0 } var zenith = radToDeg(Math.acos(csz)) var azDenom = ( Math.cos(degToRad(latitude)) * Math.sin(degToRad(zenith)) ) if (Math.abs(azDenom) > 0.001) { azRad = (( Math.sin(degToRad(latitude)) * Math.cos(degToRad(zenith)) ) - Math.sin(degToRad(theta))) / azDenom if (Math.abs(azRad) > 1.0) { if (azRad < 0) { azRad = -1.0 } else { azRad = 1.0 } } var azimuth = 180.0 - radToDeg(Math.acos(azRad)) if (hourAngle > 0.0) { azimuth = -azimuth } } else { if (latitude > 0.0) { azimuth = 180.0 } else { azimuth = 0.0 } } if (azimuth < 0.0) { azimuth += 360.0 } var exoatmElevation = 90.0 - zenith // Atmospheric Refraction correction if (exoatmElevation > 85.0) { var refractionCorrection = 0.0; } else { var te = Math.tan (degToRad(exoatmElevation)); if (exoatmElevation > 5.0) { var refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te); } else if (exoatmElevation > -0.575) { var refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) ); } else { var refractionCorrection = -20.774 / te; } refractionCorrection = refractionCorrection / 3600.0; } var solarZen = zenith - refractionCorrection; if ((output) && (solarZen > 108.0) ) { document.getElementById("azbox").value = "dark" document.getElementById("elbox").value = "dark" } else if (output) { document.getElementById("azbox").value = Math.floor(azimuth*100 +0.5)/100.0 document.getElementById("elbox").value = Math.floor((90.0-solarZen)*100+0.5)/100.0 if (document.getElementById("showae").checked) { showLineGeodesic("#ffff00", azimuth) } } return (azimuth) } #ce Func _calcAzEl ( $output, $T, $localtime, $latitude, $longitude, $zone ) Local $SolarReturnAzEl[1] = [0] Local $SolarLightStatus, $SolarEquationOfTime, $SolarDeclination Local $eqTime = _calcEquationOfTime ( $T ) Local $theta = _calcSunDeclination ( $T ) If $output Then $SolarEquationOfTime = Floor ( $eqTime * 100 + 0.5 ) / 100.0 $SolarDeclination = Floor ( $theta * 100 + 0.5 ) / 100.0 EndIf Local $solarTimeFix = $eqTime + 4.0 * $longitude - 60.0 * $zone Local $earthRadVec = _calcSunRadVector ( $T ) Local $trueSolarTime = $localtime + $solarTimeFix While $trueSolarTime > 1440 $trueSolarTime -= 1440 WEnd Local $hourAngle = $trueSolarTime / 4.0 - 180.0; If $hourAngle < -180 Then $hourAngle += 360.0 EndIf Local $haRad = _degToRad ( $hourAngle ) Local $csz = Sin ( _degToRad ( $latitude ) ) * Sin ( _degToRad ( $theta ) ) + Cos ( _degToRad ( $latitude ) ) * Cos ( _degToRad ( $theta ) ) * Cos ( $haRad ) If $csz > 1.0 Then $csz = 1.0 ElseIf $csz < -1.0 Then $csz = -1.0 EndIf Local $zenith = _radToDeg ( ACos ( $csz ) ) Local $azDenom = ( Cos ( _degToRad ( $latitude ) ) * Sin ( _degToRad ( $zenith ) ) ) If Abs ( $azDenom ) > 0.001 Then $azRad = ( ( Sin ( _degToRad ( $latitude ) ) * Cos ( _degToRad ( $zenith ) ) ) - Sin ( _degToRad ( $theta ) ) ) / $azDenom If Abs ( $azRad ) > 1.0 Then If $azRad < 0 Then $azRad = -1.0 Else $azRad = 1.0 EndIf EndIf Local $azimuth = 180.0 - _radToDeg ( ACos ( $azRad ) ) If $hourAngle > 0.0 Then $azimuth = -$azimuth EndIf Else If $latitude > 0.0 Then $azimuth = 180.0 Else $azimuth = 0.0 EndIf EndIf If $azimuth < 0.0 Then $azimuth += 360.0 EndIf Local $exoatmElevation = 90.0 - $zenith ; Atmospheric Refraction correction If $exoatmElevation > 85.0 Then Local $refractionCorrection = 0.0 Else Local $te = Tan ( _degToRad ( $exoatmElevation ) ) If $exoatmElevation > 5.0 Then Local $refractionCorrection = 58.1 / $te - 0.07 / ( $te * $te * $te ) + 0.000086 / ( $te * $te * $te * $te * $te ) ElseIf $exoatmElevation > -0.575 Then Local $refractionCorrection = 1735.0 + $exoatmElevation * ( -518.2 + $exoatmElevation * ( 103.4 + $exoatmElevation * ( -12.79 + $exoatmElevation * 0.711) ) ) Else Local $refractionCorrection = -20.774 / $te EndIf $refractionCorrection = $refractionCorrection / 3600.0 EndIf Local $solarZen = $zenith - $refractionCorrection If $solarZen > 108.0 Then $SolarLightStatus = "Night" ElseIf ( ( 108.0 > $solarZen ) And ( $solarZen >= 102.0 ) ) Then $SolarLightStatus = "Astronomical Twilight" ElseIf ( ( 102.0 > $solarZen ) And ( $solarZen >= 96.0 ) ) Then $SolarLightStatus = "Nautical Twilight" ElseIf ( ( 96.0 > $solarZen ) And ( $solarZen >= 90.8333 ) ) Then $SolarLightStatus = "Civil Twilight" Else $SolarLightStatus = "Day" EndIf _ArrayAdd ( $SolarReturnAzEl, Floor ( ( ( $azimuth * 100 ) + 0.5 ) / 100.0 ) ) _ArrayAdd ( $SolarReturnAzEl, Floor ( ( 90.0 - $solarZen ) * 100 + 0.5) / 100.0 ) _ArrayAdd ( $SolarReturnAzEl, $SolarLightStatus ) _ArrayDelete ( $SolarReturnAzEl, 0 ) Return ( $SolarReturnAzEl ) EndFunc #cs function calcSolNoon(jd, longitude, timezone, dst) { var tnoon = calcTimeJulianCent(jd - longitude/360.0) var eqTime = calcEquationOfTime(tnoon) var solNoonOffset = 720.0 - (longitude * 4) - eqTime // in minutes var newt = calcTimeJulianCent(jd + solNoonOffset/1440.0) eqTime = calcEquationOfTime(newt) solNoonLocal = 720 - (longitude * 4) - eqTime + (timezone*60.0)// in minutes if(dst) solNoonLocal += 60.0 document.getElementById("noonbox").value = timeString(solNoonLocal, 3) } #ce Func _calcSolNoon ( $jd, $longitude, $timezone, $dst ) Local $tnoon = _calcTimeJulianCent ( $jd - $longitude / 360.0 ) Local $eqTime = _calcEquationOfTime ( $tnoon ) Local $solNoonOffset = 720.0 - ( $longitude * 4 ) - $eqTime ; in minutes Local $newt = _calcTimeJulianCent ( $jd + $solNoonOffset / 1440.0 ) $eqTime = _calcEquationOfTime ( $newt ) $solNoonLocal = 720 - ( $longitude * 4 ) - $eqTime + ( $timezone * 60.0 ) ; in minutes If $dst Then $solNoonLocal += 60.0 Return _timeString ( $solNoonLocal, 3 ) EndFunc #cs function dayString(jd, next, flag) { // returns a string in the form DDMMMYYYY[ next] to display prev/next rise/set // flag=2 for DD MMM, 3 for DD MM YYYY, 4 for DDMMYYYY next/prev if ( (jd < 900000) || (jd > 2817000) ) { var output = "error" } else { var z = Math.floor(jd + 0.5); var f = (jd + 0.5) - z; if (z < 2299161) { var A = z; } else { alpha = Math.floor((z - 1867216.25)/36524.25); var A = z + 1 + alpha - Math.floor(alpha/4); } var B = A + 1524; var C = Math.floor((B - 122.1)/365.25); var D = Math.floor(365.25 * C); var E = Math.floor((B - D)/30.6001); var day = B - D - Math.floor(30.6001 * E) + f; var month = (E < 14) ? E - 1 : E - 13; var year = ((month > 2) ? C - 4716 : C - 4715); if (flag == 2) var output = zeroPad(day,2) + " " + monthList[month-1].abbr; if (flag == 3) var output = zeroPad(day,2) + monthList[month-1].abbr + year.toString(); if (flag == 4) var output = zeroPad(day,2) + monthList[month-1].abbr + year.toString() + ((next) ? " next" : " prev"); } return output; } #ce Func _dayString ( $jd, $next, $flag ) ; returns a string in the form DDMMMYYYY[ next] to display prev/next rise/set ; flag=2 for DD MMM, 3 for DD MM YYYY, 4 for DDMMYYYY next/prev If ( $jd < 900000 ) Or ( $jd > 2817000 ) Then Local $output = "error" Else Local $z = Floor ( $jd + 0.5 ) Local $f = ( $jd + 0.5 ) - $z If $z < 2299161 Then $A = $z Else Local $alpha = Floor ( ( $z - 1867216.25 ) / 36524.25 ) $A = $z + 1 + $alpha - Floor ( $alpha / 4 ) EndIf Local $B = $A + 1524 Local $C = Floor ( ( $B - 122.1 ) / 365.25 ) Local $D = Floor ( 365.25 * $C ) Local $E = Floor ( ( $B - $D ) / 30.6001 ) Local $day = $B - $D - Floor ( 30.6001 * $E ) + $f Local $month If $E < 14 Then $month = $E - 1 Else $month = $E - 13 EndIf Local $year If $month > 2 Then $year = $C - 4716 Else $year = $C - 4715 EndIf If $flag = 2 Then Local $output = _zeroPad ( $day, 2 ) & " " & $MonthAbrev[$month-1] ElseIf $flag = 3 Then Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) ElseIf $flag = 4 Then If $next Then Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) & " next" Else Local $output = _zeroPad ( $day, 2 ) & $MonthAbrev[$month-1] & String ( $year ) & " prev" EndIf EndIf EndIf Return $output EndFunc #cs function timeDateString(JD, minutes) { var output = timeString(minutes, 2) + " " + dayString(JD, 0, 2); return output; } #ce Func _TimeDateString ( $JD, $minutes ) Local $output = _timeString ( $minutes, 2 ) & " " & _dayString ( $JD, 0, 2 ) Return $output EndFunc #cs function timeString(minutes, flag) // timeString returns a zero-padded string (HH:MM:SS) given time in minutes // flag=2 for HH:MM, 3 for HH:MM:SS { if ( (minutes >= 0) && (minutes < 1440) ) { var floatHour = minutes / 60.0; var hour = Math.floor(floatHour); var floatMinute = 60.0 * (floatHour - Math.floor(floatHour)); var minute = Math.floor(floatMinute); var floatSec = 60.0 * (floatMinute - Math.floor(floatMinute)); var second = Math.floor(floatSec + 0.5); if (second > 59) { second = 0 minute += 1 } if ((flag == 2) && (second >= 30)) minute++; if (minute > 59) { minute = 0 hour += 1 } var output = zeroPad(hour,2) + ":" + zeroPad(minute,2); if (flag > 2) output = output + ":" + zeroPad(second,2); } else { var output = "error" } return output; } #ce Func _timeString ( $minutes, $flag ) ; timeString returns a zero-padded string (HH:MM:SS) given time in minutes ; flag=2 for HH:MM, 3 for HH:MM:SS If ( ( $minutes >= 0 ) And ( $minutes < 1440 ) ) Then Local $floatHour = $minutes / 60.0 Local $hour = Floor ( $floatHour ) Local $floatMinute = 60.0 * ( $floatHour - Floor ( $floatHour) ) Local $minute = Floor ( $floatMinute ) Local $floatSec = 60.0 * ( $floatMinute - Floor ( $floatMinute ) ) Local $second = Floor ( $floatSec + 0.5 ) If ( $second > 59) Then $second = 0 $minute += 1 EndIf If ( ( $flag = 2 ) And ( $second >= 30 ) ) Then $minute += 1 If ( $minute > 59 ) Then $minute = 0 $hour += 1 EndIf Local $output = _zeroPad ( $hour, 2 ) & ":" & _zeroPad ( $minute, 2 ) If $flag > 2 Then $output = $output & ":" & _zeroPad ( $second, 2 ) Else $output = "error" EndIf Return $output EndFunc #cs function calcSunriseSetUTC(rise, JD, latitude, longitude) { var t = calcTimeJulianCent(JD); var eqTime = calcEquationOfTime(t); var solarDec = calcSunDeclination(t); var hourAngle = calcHourAngleSunrise(latitude, solarDec); //alert("HA = " + radToDeg(hourAngle)); if (!rise) hourAngle = -hourAngle; var delta = longitude + radToDeg(hourAngle); var timeUTC = 720 - (4.0 * delta) - eqTime; // in minutes return timeUTC } #ce Func _calcSunriseSetUTC ( $rise, $JD, $latitude, $longitude ) Local $t = _calcTimeJulianCent ( $JD ) Local $eqTime = _calcEquationOfTime ( $t ) Local $solarDec = _calcSunDeclination ( $t ) Local $RiseSetAngle = _calcHourAngleSunrise ( $latitude, $solarDec ) If Not $rise Then $RiseSetAngle = -$RiseSetAngle Local $delta = $longitude + _radToDeg ( $RiseSetAngle ) Local $timeUTCRS = 720 - ( 4.0 * $delta ) - $eqTime Return $timeUTCRS ; in minutes EndFunc #cs function calcSunriseSet(rise, JD, latitude, longitude, timezone, dst) // rise = 1 for sunrise, 0 for sunset { var id = ((rise) ? "risebox" : "setbox") var timeUTC = calcSunriseSetUTC(rise, JD, latitude, longitude); var newTimeUTC = calcSunriseSetUTC(rise, JD + timeUTC/1440.0, latitude, longitude); if (isNumber(newTimeUTC)) { var timeLocal = newTimeUTC + (timezone * 60.0) if (document.getElementById(rise ? "showsr" : "showss").checked) { var riseT = calcTimeJulianCent(JD + newTimeUTC/1440.0) var riseAz = calcAzEl(0, riseT, timeLocal, latitude, longitude, timezone) showLineGeodesic(rise ? "#66ff00" : "#ff0000", riseAz) } timeLocal += ((dst) ? 60.0 : 0.0); if ( (timeLocal >= 0.0) && (timeLocal < 1440.0) ) { document.getElementById(id).value = timeString(timeLocal,2) } else { var jday = JD var increment = ((timeLocal < 0) ? 1 : -1) while ((timeLocal < 0.0)||(timeLocal >= 1440.0)) { timeLocal += increment * 1440.0 jday -= increment } document.getElementById(id).value = timeDateString(jday,timeLocal) } } else { // no sunrise/set found var doy = calcDoyFromJD(JD) if ( ((latitude > 66.4) && (doy > 79) && (doy < 267)) || ((latitude < -66.4) && ((doy < 83) || (doy > 263))) ) { //previous sunrise/next sunset if (rise) { // find previous sunrise jdy = calcJDofNextPrevRiseSet(0, rise, JD, latitude, longitude, timezone, dst) } else { // find next sunset jdy = calcJDofNextPrevRiseSet(1, rise, JD, latitude, longitude, timezone, dst) } document.getElementById(((rise)? "risebox":"setbox")).value = dayString(jdy,0,3) } else { //previous sunset/next sunrise if (rise == 1) { // find previous sunrise jdy = calcJDofNextPrevRiseSet(1, rise, JD, latitude, longitude, timezone, dst) } else { // find next sunset jdy = calcJDofNextPrevRiseSet(0, rise, JD, latitude, longitude, timezone, dst) } document.getElementById(((rise)? "risebox":"setbox")).value = dayString(jdy,0,3) } } } #ce Func _calcSunriseSet ( $rise, $JD, $latitude, $longitude, $timezone, $dst ) ; rise = 1 for sunrise, 0 for sunset Local $timeUTC = _calcSunriseSetUTC ( $rise, $JD, $latitude, $longitude ) Local $newTimeUTC = _calcSunriseSetUTC ( $rise, $JD + $timeUTC / 1440.0, $latitude, $longitude ) If isNumber ( $newTimeUTC ) Then Local $timeLocal = $newTimeUTC + ( $timezone * 60.0 ) If $rise Then Local $riseT = _calcTimeJulianCent ( $JD + $newTimeUTC / 1440.0 ) Local $riseAz = _calcAzEl ( 0, $riseT, $timeLocal, $latitude, $longitude, $timezone ) EndIf If $dst Then $timeLocal += 60.0 Else $timelocal += 0.0 EndIf If ( ( $timeLocal >= 0.0) And ( $timeLocal < 1440.0) ) Then Return _timeString ( $timeLocal, 2 ) Else Local $jday = $JD Local $increment If $timeLocal < 0 Then $increment = 1 Else $increment = -1 EndIf While ( ( $timeLocal < 0.0 ) Or ( $timeLocal >= 1440.0 ) ) $timeLocal += $increment * 1440.0 $jday -= $increment WEnd Return _timeDateString ( $jday, $timeLocal ) EndIf Else Local $doy = _calcDoyFromJD ( $JD ) If ( ( ( $latitude > 66.4 ) And ( $doy > 79 ) And ( $doy < 267 ) ) Or ( ( $latitude < -66.4 ) And ( ( $doy < 83 ) Or ( $doy > 263 ) ) ) ) Then If ( $rise ) Then $jdy = _calcJDofNextPrevRiseSet ( 0, $rise, $JD, $latitude, $longitude, $timezone, $dst ) Else $jdy = _calcJDofNextPrevRiseSet ( 1, $rise, $JD, $latitude, $longitude, $timezone, $dst ) EndIf ;Return _dayString ( $jdy, 0, 3 ) Else If ( $rise ) Then $jdy = _calcJDofNextPrevRiseSet ( 1, $rise, $JD, $latitude, $longitude, $timezone, $dst ) Else $jdy = _calcJDofNextPrevRiseSet ( 0, $rise, $JD, $latitude, $longitude, $timezone, $dst ) EndIf ;Return _dayString ( $jdy, 0, 3 ) EndIf EndIf EndFunc #cs function calcJDofNextPrevRiseSet(next, rise, JD, latitude, longitude, tz, dst) { var julianday = JD; var increment = ((next) ? 1.0 : -1.0); var time = calcSunriseSetUTC(rise, julianday, latitude, longitude); while(!isNumber(time)){ julianday += increment; time = calcSunriseSetUTC(rise, julianday, latitude, longitude); } var timeLocal = time + tz * 60.0 + ((dst) ? 60.0 : 0.0) while ((timeLocal < 0.0) || (timeLocal >= 1440.0)) { var incr = ((timeLocal < 0) ? 1 : -1) timeLocal += (incr * 1440.0) julianday -= incr } return julianday; } #ce Func _calcJDofNextPrevRiseSet ( $next, $rise, $JD, $latitude, $longitude, $tz, $dst ) Local $julianday = $JD Local $increment If $next Then $increment = 1.0 Else $increment = -1.0 EndIf Local $time = _calcSunriseSetUTC ( $rise, $julianday, $latitude, $longitude ) While Not isNumber ( $time ) $julianday += $increment $time = _calcSunriseSetUTC ( $rise, $julianday, $latitude, $longitude ) WEnd Local $timeLocal If $dst Then $timeLocal = $time + $tz * 60.0 + 60.0 Else $timeLocal = $time + $tz * 60.0 EndIf While ( ( $timeLocal < 0.0 ) Or ( $timeLocal >= 1440.0 ) ) Local $incr If $timeLocal < 0 Then $incr = 1 Else $incr = -1 EndIf $timeLocal += ( $incr * 1440.0 ) $julianday -= $incr WEnd Return $julianday EndFunc #cs function calculate() { //refreshMap() //clearOutputs() //map.clearOverlays() //showMarkers() var jday = getJD() var tl = getTimeLocal() var tz = readTextBox("zonebox", 5, 0, 0, -14, 13, 0) var dst = document.getElementById("dstCheckbox").checked var total = jday + tl/1440.0 - tz/24.0 var T = calcTimeJulianCent(total) var lat = parseFloat(document.getElementById("latbox").value.substring(0,9)) var lng = parseFloat(document.getElementById("lngbox").value.substring(0,10)) calcAzEl(1, T, tl, lat, lng, tz) calcSolNoon(jday, lng, tz, dst) var rise = calcSunriseSet(1, jday, lat, lng, tz, dst) var set = calcSunriseSet(0, jday, lat, lng, tz, dst) //alert("JD " + jday + " " + rise + " " + set + " ") } #ce ;( $AstroLat, $AstroLong, $AstroMonth, $AstroDay, $AstroYear, $AstroTimeZone, $AstroHour, $AstroMinute, $AstroSecond, $AstroDST ) Func _SolarCalculate ( $CalcLat, $CalcLong, $CalcMonth, $CalcDay, $CalcYear, $CalcTz, $CalcHour, $CalcMinute, $CalcSecond, $CalcDST, $CalcCurrent ) Local $SolarCalculateResult[1] = [0] Local $jday = _getJD ( $CalcMonth, $CalcDay, $CalcYear ) Local $tl = _getTimeLocal ( $CalcHour, $CalcMinute, $CalcSecond, $CalcDST ) Local $tz If $CalcTz = "" Then $tz = Int ( $CalcLong / 15 ) Else $tz = $CalcTz EndIf Local $total = $jday + $tl / 1440.0 - $tz / 24.0 Local $T = _calcTimeJulianCent ( $total ) Local $CalcSolNoon = _calcSolNoon ( $jday, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM:SS" ;MsgBox ( 0, "Solar Noon:", $CalcSolNoon ) Local $rise = _calcSunriseSet ( 1, $jday, $CalcLat, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM" or "HH:MM DD Mon" ;MsgBox ( 0, "Sun Rise:", $rise ) Local $set = _calcSunriseSet ( 0, $jday, $CalcLat, $CalcLong, $tz, $CalcDST ) ; Returns String: "HH:MM" or "HH:MM DD Mon" ;MsgBox ( 0, "Sun Set:", $set ) _ArrayAdd ( $SolarCalculateResult, $rise ) _ArrayAdd ( $SolarCalculateResult, $CalcSolNoon ) _ArrayAdd ( $SolarCalculateResult, $set ) $SolarCalculateResult[0] += 3 If $CalcCurrent Then Local $CalcAzEl = _calcAzEl ( 1, $T, $tl, $CalcLat, $CalcLong, $tz ) ; Returns Array: 0 - Azimuth, 1 - Elevation, 2 - Illumination-Disposition _ArrayConcatenate ( $SolarCalculateResult, $CalcAzEl ) $SolarCalculateResult[0] += 3 EndIf Return $SolarCalculateResult EndFunc #cs </SCRIPT> #ce Here is an example usage script: #include <SunPosition.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $MyLat = "37.818599" Global $MyLong = "-122.478418" $SunPosition_Window = GUICreate ( "Sun Position", 220, 180 ) GUICtrlCreateLabel ( "Sun Rise:", 10, 12 ) $Rise_Time = GUICtrlCreateInput("", 100, 10 ) GUICtrlCreateLabel ( "Solar Noon:", 10, 32 ) $Noon_Time = GUICtrlCreateInput("", 100, 30 ) GUICtrlCreateLabel ( "Sun Set:", 10, 52 ) $Set_Time = GUICtrlCreateInput("", 100, 50 ) GUICtrlCreateLabel ( "Azimuth:", 10, 72 ) $Sun_Azimuth = GUICtrlCreateInput("", 100, 70 ) GUICtrlCreateLabel ( "Elevation:", 10, 92 ) $Sun_Elevation = GUICtrlCreateInput("", 100, 90 ) GUICtrlCreateLabel ( "Illum Disp.:", 10, 112 ) $Light_Disposition = GUICtrlCreateInput("", 100, 110, 110 ) GUICtrlCreateLabel ( "Dimmer Lvl:", 10, 135 ) $Light_Level_Control = GUICtrlCreateLabel ( "", 70, 135, 23, 17 ) GUICtrlCreateLabel ( "Switched Lts:", 100, 135 ) $Light_Switch_Control = GUICtrlCreateLabel ( "", 170, 135, 23, 17 ) $Dummy = GUICtrlCreateInput("", 100, 210 ) GUICtrlCreateLabel ( "Light Blocking Curtians:", 10, 155 ) $Privacy_Curtain_Control = GUICtrlCreateLabel ( "", 125, 155, 23, 17 ) GUISetState(@SW_SHOW) Global $RefreshCounter = 0 Global $Light_Level_Register = 0 Global $Curtain_Opening_Register = 0 Global $CalcLightMagnatude = 0 While 1 Sleep ( 2 ) $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case "" $RefreshCounter += 1 If $RefreshCounter >=25 Then $TestVector = _GetSolarAstronimicalData ( $MyLat, $MyLong, @MON, @MDAY, @YEAR, Int ( $MyLong / 15 ), @HOUR, @MIN, @SEC, True ) GUICtrlSetData ( $Rise_Time, $TestVector[1] ) GUICtrlSetData ( $Noon_Time, $TestVector[2] ) GUICtrlSetData ( $Set_Time, $TestVector[3] ) GUICtrlSetData ( $Sun_Azimuth, $TestVector[4] ) GUICtrlSetData ( $Sun_Elevation, $TestVector[5] ) GUICtrlSetData ( $Light_Disposition, $TestVector[6] ) ; 0.8333 add to actual elevation for lights ; 1.722233333 subtract from actual elevation for lights ; 1.722233333 x 3 = 5.166699999 Max for Light control $Light_Level_Register = $TestVector[5] + 0.8333 $Light_Level_Register -= 3.444466666 $Light_Level_Register *= -1 If $Light_Level_Register < 0 Then $Light_Level_Register = 0 ElseIf $Light_Level_Register > 5.166699999 Then $Light_Level_Register = 255 Else $Light_Level_Register = $Light_Level_Register / 5.166699999 $Light_Level_Register = int ( 255 * $Light_Level_Register ) EndIf $CalcLightMagnatude = 0 $CalcLightMagnatude = ( $Light_Level_Register * 65536 ) + ( $Light_Level_Register * 256 ) + Round ( ( $Light_Level_Register * 0.75 ), 0 ) GUICtrlSetBkColor ( $Light_Level_Control, $CalcLightMagnatude ) GUICtrlSetData ( $Light_Level_Control, $Light_Level_Register ) If $Light_Level_Register < 191 Then GUICtrlSetColor ( $Light_Level_Control, 0xffffff ) Else GUICtrlSetColor ( $Light_Level_Control, 0x000000 ) EndIf GUICtrlSetState( $Dummy, $GUI_FOCUS) If $Light_Level_Register > 95 Then GUICtrlSetData ( $Light_Switch_Control, " On" ) GUICtrlSetBkColor ( $Light_Switch_Control, 0x00ff00 ) Else GUICtrlSetData ( $Light_Switch_Control, " Off" ) GUICtrlSetBkColor ( $Light_Switch_Control, 0xff0000 ) EndIf ; 0.8333 + 3.444466666 = 4.277766666 add to actual elevation for curtains ; 1.722233333 x 2 = 3.444466666 Max for Curtain control $Curtain_Opening_Register = $TestVector[5] + 4.277766666 $Curtain_Opening_Register *= -1 If $Curtain_Opening_Register < 0 Then $Curtain_Opening_Register = 0 ElseIf $Curtain_Opening_Register > 3.444466666 Then $Curtain_Opening_Register = 255 Else $Curtain_Opening_Register = $Curtain_Opening_Register / 3.444466666 $Curtain_Opening_Register = int ( 255 * $Curtain_Opening_Register ) EndIf $Curtain_Opening_Register = 255 - $Curtain_Opening_Register GUICtrlSetData ( $Privacy_Curtain_Control, $Curtain_Opening_Register ) $RefreshCounter = 0 EndIf EndSwitch WEnd GUIDelete() I personally believe this data can be used for pointing solar panels or, in home automation, opening and closing blinds/curtains to avoid over-exposure of a room. It could also be used for scheduling lights, etc… Have fun with it! -Tim1 point -
Need help to make my script repeat!
BogdanNicolescu reacted to Apfelkiller for a topic
Here this will do, just put the rest (or whatever you want) at the ;... position. The Hotkey to exit the script is set to {ESC} HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) ;... ;... ;... MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate() Exit 0 EndFunc1 point -
Need help to make my script repeat!
BogdanNicolescu reacted to Apfelkiller for a topic
Do you want to repeat the whole skript?? While 1 ;Your skript here WEnd This will repeat it forever1 point