katoNkatoNK Posted May 29, 2011 Author Share Posted May 29, 2011 The conditions in the select statement, with 'Case $subnetmask' is really all i'm trying to do ~ when $subnetmask is focused. My problem here is that even when $subnetmask is not in focus the case statement gets fired. Link to comment Share on other sites More sharing options...
martin Posted May 29, 2011 Share Posted May 29, 2011 The conditions in the select statement, with 'Case $subnetmask' is really all i'm trying to do ~ when $subnetmask is focused. My problem here is that even when $subnetmask is not in focus the case statement gets fired.Well, I still don't understand what you want to do, but your code is faulty and the case will fire continually. If you use Select then you must have a condition which returns true or false for each Case. You have Case $SUBNETMASK which will always be true because it isn't 0 if the IP control was created successfully.Then the result of GuiGetMsg will never be $SubNetMask because that is a window handle. I think you need to study the example in the help for _GUICtrlIPAddress_Create. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 29, 2011 Author Share Posted May 29, 2011 I know it is not the right way to set it up as well as the commented 'Switch' statement in the example i posted..I just don't know of a method that works for this sort of thing this is why i posted for help Link to comment Share on other sites More sharing options...
martin Posted May 29, 2011 Share Posted May 29, 2011 I know it is not the right way to set it up as well as the commented 'Switch' statement in the example i posted..I just don't know of a method that works for this sort of thing this is why i posted for helpOk, but I need a clear and simple explanation of what you are trying to do. Explain it as you would to a passing old man with poor hearing who was curious because that's what I am. I can't see from your examples what you want but I don't think it should take many words.Without a clear understanding I can't start. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 29, 2011 Author Share Posted May 29, 2011 Ok, I hope commenting the sample might give you a better idea. The comments is the end result that i had in mind.. Select Case $subnetmask ;When the 'subnet mask' control sends the message that it is focused (clicked in either of fields, 1 - 4) If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then ;If the 'ip address' control field[1] ($aIP_GET[0]) contains a value that is equal to, or between either of these numbers (126 & 1) then _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0") ;Set the 'subnet masks' ip to "255.0.0.0" EndIf If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then ;..repeat with different value. _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0") EndIf If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then ;..repeat with different value. _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0") EndIf EndSelect Link to comment Share on other sites More sharing options...
martin Posted May 29, 2011 Share Posted May 29, 2011 Ok, I hope commenting the sample might give you a better idea. The comments is the end result that i had in mind.. Select Case $subnetmask ;When the 'subnet mask' control sends the message that it is focused (clicked in either of fields, 1 - 4) If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then ;If the 'ip address' control field[1] ($aIP_GET[0]) contains a value that is equal to, or between either of these numbers (126 & 1) then _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0") ;Set the 'subnet masks' ip to "255.0.0.0" EndIf If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then ;..repeat with different value. _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0") EndIf If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then ;..repeat with different value. _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0") EndIf EndSelect I am a lot more stupid than you think. No doubt you know what you want to do, though I can't be sure, but I still have no clue. What is $IP_GET[0] for example? Forget the sodding code. Tell me in plain language something like this. I have a gui with 2 input fields for IP addresses IPA and IPB. When someone types a value into IPA first octet I want an address top be put into IPB depending on the value. If the first octet in IPA is in the range x to y then the address for the whole IPB must be Z. If the value in the first octet of IPA is in the range C to D then the whole address in IPB must be set to Y. If anything is typed into the other octets in IPA then it should have no effect on IPB. I need stuff like that otherwise I might be wasting another 5 posts and I don't have infinite patience and I'm getting close to the end of my lifespan. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) Ok, your explanation is fairly close, - i have two IP address controls, IPA, IPB. Only when IPB is focused in either of the octets (1st to 4th) and contains no existing values in these octets, then depending only on what value IPA's first octet is, a value X/Y/Z is set for IPB. Edited May 29, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
martin Posted May 29, 2011 Share Posted May 29, 2011 (edited) Ok, your explanation is fairly close, - i have two IP address controls, IPA, IPB. Only when IPB is focused in either of the octets (1st to 4th) and contains no existing values in these octets, then depending only on what value IPA's first octet is, a value X/Y/Z is set for IPB. Ok, I'll be back or someone will get there first. Here (simplified ie needs more code to stop unnecessary changes) expandcollapse popup#include <GuiIPAddress.au3> #include <GUIConstantsEx.au3> Global $gui Global $ipaddress Global $subnetmask Global $IPChanged = False $gui = GUICreate("test", 300, 300, -1, -1) $ipaddress = _GUICtrlIpAddress_Create($gui, 25, 40, 200, 20) $subnetmask = _GUICtrlIpAddress_Create($gui, 25, 80, 200, 20) ConsoleWrite($subnetmask & @CRLF) Global $msg GUISetState() Global $nowfoc, $lastfoc Global $aIP_GET While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch $nowfoc = ControlGetFocus($gui); If StringInStr("Edit5-Edit6-Edit7-$Edit8", $nowfoc) Then if not $IPChanged Then $aIP_GET = _GUICtrlIpAddress_GetArray($ipaddress) If $aIP_GET[0] <= 126 And $aIP_GET[0] >= 1 Then _GUICtrlIpAddress_Set($subnetmask, "255.0.0.0") EndIf If $aIP_GET[0] <= 191 And $aIP_GET[0] >= 128 Then _GUICtrlIpAddress_Set($subnetmask, "255.255.0.0") EndIf If $aIP_GET[0] <= 223 And $aIP_GET[0] >= 192 Then _GUICtrlIpAddress_Set($subnetmask, "255.255.255.0") EndIf $IPChanged = true EndIf Else $IPChanged = false EndIf WEnd EDIT: corrected so that the second IP address can be edited. Edited May 29, 2011 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted May 29, 2011 Share Posted May 29, 2011 I was back Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 29, 2011 Author Share Posted May 29, 2011 (edited) Thank you for the solution martin! Edited May 29, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
carloselectro Posted February 15, 2019 Share Posted February 15, 2019 On 2011-05-21 at 5:16 PM, martin said: Probably a few ways but I would use a message. If a script starts and finds that a previous script is running then it sends a message to that script and quits. The first instance can then do whatever you want when it gets the message. expandcollapse popup#include <misc.au3> #include <sendmessage.au3> #include <winapi.au3> $RecoverGui = _WinAPI_RegisterWindowMessage("MySpecialRecoverThing");get an unallocated message number, or get the number previously allocated to that string by a previous instance If _Singleton("hgtfredsws_underoveranything", 1) = 0 Then ;MsgBox(262144, "already", "one running") $hw = WinGetHandle("nothing much here") If @error = 0 Then _SendMessage($hw, $RecoverGui, 1);tell the first script to wake up EndIf Exit EndIf traysetstate(2) $g = GUICreate("nothing much here") GUISetState() GUIRegisterMsg($RecoverGui, "Mywakeup") While 1 $msg2 = GUIGetMsg() Switch $msg2 Case -3 Exit case -4 traysetstate() EndSwitch WEnd Func Mywakeup($hG, $iMsg, $wPar, $lPar) If $wPar = 1 Then; we have been told to restore GUISetState(@SW_RESTORE, $g);now you can use your GuiSetState traysetstate(2); and you can use your TraySetState EndIf EndFunc ;==>Mywakeup This is working great it helped me fix my problem too: https://www.autoitscript.com/forum/topic/197785-help-with-_singleton-function/?tab=comments#comment-1418688 Thanks a lot 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