Nahuel Posted August 10, 2007 Share Posted August 10, 2007 Ok, I'm making a timer that will do what you select (Shutdown, restart, logoff) at the time that you specify. The problem is that using the UpDown function to select time, the numbers are "1","2", ect instead of "01","02", ect. And when I compare the current time with the selected time using: If Guictrlread($selectedtime) = @HOUR Then... it won't work because @HOUR will be = "01","02", ect. and $selectedtime will be"1","2", ect It only works if I type the 0 in the UpDown... I hope that's clear enough... Here's my script in case you want to check it out (In spanish, sorry): expandcollapse popup#include <GuiConstants.au3> ;Algunas Variables $loop2=1 $AnchoVentana = 250 $AltoVentana = 200 $MargenIzquierdo=10 $MargenSuperior=10 $Separador=20 $AnchoEtiqueta=130 $AltoEtiqueta=22 ;Opciones especiales Opt("TrayAutoPause",0) Opt("TrayMenuMode",1) GuiCreate("Temporizador", $AnchoVentana, $AltoVentana) ;Hora actual: $Reloj=GUICtrlCreateLabel(@HOUR&":"&@MIN,$AnchoVentana/2-$Separador,$MargenSuperior+6,$AnchoEtiqueta) GUICtrlSetFont($Reloj, 10, 500, "", "Verdana") ;Hora $HoraApagado = GUICtrlCreateInput ("00",$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20) GUICtrlCreateUpdown($HoraApagado) GUICtrlSetLimit(-1, 23,00) GUICtrlCreateLabel("Horas",$MargenIzquierdo+5+65,$MargenSuperior+$Separador*2+12) ;Minutos $MinApagado = GUICtrlCreateInput ("00",$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20) GUICtrlCreateUpdown($MinApagado) GUICtrlSetLimit(-1, 59,00) GUICtrlCreateLabel("Minutos",$MargenIzquierdo+$Separador+100+65,$MargenSuperior+$Separador*2+12) ;Eventos $combo=GUICtrlCreateCombo("Apagar",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200) GUICtrlSetData($combo,"Reiniciar|Cerrar Sesión","Apagar") ;Grupos GUICtrlCreateGroup("Hora Actual:",$MargenIzquierdo-5,$MargenSuperior-5,$AnchoVentana-10,$AltoEtiqueta+10) GUICtrlCreateGroup("Hora De Evento:", $MargenIzquierdo-5, $MargenSuperior+$Separador+10,$AnchoVentana-10,$AltoEtiqueta+10+$Separador) GUICtrlCreateGroup("Evento:",$MargenIzquierdo-5,$MargenSuperior+$Separador*4+6,$AnchoVentana-10, $AltoEtiqueta+10+$Separador) ;Botones $Aplicar=GUICtrlCreateButton("&Aplicar",$MargenIzquierdo+10,$MargenSuperior+$Separador*7+15,100,-1,$BS_DEFPUSHBUTTON) $Cancelar=GUICtrlCreateButton("&Cancelar",$MargenIzquierdo+$Separador+105,$MargenSuperior+$Separador*7+15,100) ;Menú del ícono de bandeja: Opt("TrayOnEventMode",1) TrayCreateItem("") TrayCreateItem("Acerca de") TrayItemSetOnEvent(-1, "about") TrayCreateItem("") TrayCreateItem("Nueva hora") TrayItemSetOnEvent(-1, "nueva_hora") TrayCreateItem("") TrayCreateItem("Salir") TrayItemSetOnEvent(-1, "app_close") TraySetToolTip("Actualmente Inactivo") ;Ciclo principal GUISetState() $MediElTiempo=False $loop = 0 While $loop = 0 ;========================= ;Refresca el reloj de hora actual if Not $MediElTiempo Then $Empezar = TimerInit() $MediElTiempo = True EndIf $dif = TimerDiff($Empezar) if $dif>4000 Then refrescar_reloj() $MediElTiempo = False EndIf ;========================= $msg=GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $loop=1 Case $msg = $Aplicar MsgBox(0,Guictrlread($combo),"El evento seleccionado sucederá a las: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado)) GUISetState(@SW_HIDE) TraySetToolTip("Evento: "&GUICtrlRead($combo)&". Hora de evento: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado)) $loop2=0 $MediElTiempo1=False While $loop2=0 If @HOUR=GUICtrlRead($HoraApagado) And @MIN=GUICtrlRead($MinApagado) Then ;Cuando se cumple el tiempo, checkea que evento se ha seleccionado y confirma con el usuario. Select ;APAGAR Case GUICtrlRead($combo)="Apagar" Dim $iMsgBoxAnswer3 $iMsgBoxAnswer3 = MsgBox(49,"Apagar","Se apagará el ordenador en 5 segundos",5) Select Case $iMsgBoxAnswer3 = 1 ;Yes apagar() Case $iMsgBoxAnswer3 = 2 ;No Exit Case $iMsgBoxAnswer3 = -1;TimeOut apagar() Exit EndSelect ;REINICIAR Case GUICtrlRead($combo)="Reiniciar" Dim $iMsgBoxAnswer4 $iMsgBoxAnswer4 = MsgBox(49,"Reiniciar","Se reiniciará el ordenador en 5 segundos",5) Select Case $iMsgBoxAnswer4 = 1 ;Yes reiniciar() Case $iMsgBoxAnswer4 = 2 ;No Exit Case $iMsgBoxAnswer4 = -1;TimeOut reiniciar() EndSelect ;CERRAR SESION Case GUICtrlRead($combo)="Cerrar Sesión" Dim $iMsgBoxAnswer5 $iMsgBoxAnswer5 = MsgBox(49,"Cerrar Sesión","Se cerrará sesión en 5 segundos",5) Select Case $iMsgBoxAnswer5 = 1 ;Yes cerrar_sesion() Exit Case $iMsgBoxAnswer5 = 2 ;No Exit Case $iMsgBoxAnswer5 = -1;TimeOut cerrar_sesion() Exit EndSelect EndSelect EndIf WEnd Case $msg=$Cancelar $loop=1 EndSelect WEnd Func refrescar_reloj() GUICtrlSetData($Reloj,@HOUR&":"&@MIN) EndFunc Func about() MsgBox(0,"Acerca de","Apague, reinicie o cierre sesión en su ordenador"&@CRLF&"a la hora que usted seleccione."&@CRLF&@CRLF&@CRLF&"Creado por Nahuel José"&@CRLF&"nahueljose@gmail.com") EndFunc Func app_close() Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52,"Salir","¿Realmente deseas salir?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndFunc Func nueva_hora() If $loop2=0 Then Dim $iMsgBoxAnswer2 $iMsgBoxAnswer2 = MsgBox(36,"Nueva Hora","¿Desea reiniciar el temporizador y elegir nueva hora y evento?") Select Case $iMsgBoxAnswer2 = 6 ;Yes $loop2=1 GUISetState(@SW_SHOW) TraySetToolTip("Actualmente Inactivo") Case $iMsgBoxAnswer2 = 7 ;No EndSelect Else $loop2=1 GUISetState(@SW_SHOW) TraySetToolTip("Actualmente Inactivo") EndIf EndFunc Func apagar() ProcessClose("explorer.exe") Shutdown(9);Apaga! EndFunc Func reiniciar() ProcessClose("explorer.exe") Shutdown(2);Reinicia EndFunc Func cerrar_sesion() Shutdown(0) EndFunc Link to comment Share on other sites More sharing options...
bogQ Posted August 10, 2007 Share Posted August 10, 2007 (edited) Ok, I'm making a timer that will do what you select (Shutdown, restart, logoff) at the time that you specify. The problem is that using the UpDown function to select time, the numbers are "1","2", ect instead of "01","02", ect. And when I compare the current time with the selected time using: If Guictrlread($selectedtime) = @HOUR Then... it won't work because @HOUR will be = "01","02", ect. and $selectedtime will be"1","2", ect can you use maby select Case GUICtrlRead($MinApagado) <= 9 $Time_m = 0&GUICtrlRead($MinApagado) Case GUICtrlRead($MinApagado) >= 10 $Time_m = GUICtrlRead($MinApagado) EndSelect select Case GUICtrlRead($HoraApagado) <= 9 $Time_h = 0&GUICtrlRead($HoraApagado) Case GUICtrlRead($HoraApagado) >= 10 $Time_h = GUICtrlRead($HoraApagado) EndSelect time = GUICtrlRead($HoraApagado) If $Time_h=GUICtrlRead($HoraApagado) And $Time_m=GUICtrlRead($MinApagado) Then ;Cuando se cumple el tiempo, checkea que evento se ha seleccionado y confirma con el usuario. or something like that Edited August 10, 2007 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Nahuel Posted August 10, 2007 Author Share Posted August 10, 2007 Yeah, that might work... but it will also give me trouble if I type the 0 (it will make it 001,002,etc) I need to know if there's a way I can make the UpDown 'uneditable' (you can only change the numbers by clicking the up and down buttons) and set the numbers to 2 digits. Thanks! Link to comment Share on other sites More sharing options...
bogQ Posted August 10, 2007 Share Posted August 10, 2007 (edited) Yeah, that might work... but it will also give me trouble if I type the 0 (it will make it 001,002,etc)I need to know if there's a way I can make the UpDown 'uneditable' (you can only change the numbers by clicking the up and down buttons) and set the numbers to 2 digits.Thanks!then i think that you need to put StringLen ( "string" ) with simular formStringLen ( "string" ) > 2 error msg StringLen ( "string" ) = 2 $dataStringLen ( "string" ) = 1 "0"&$datafor way to make it 'uneditable' i dono sry maby someone else Edited August 10, 2007 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Nahuel Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks The StringLen function might be useful. Link to comment Share on other sites More sharing options...
Nahuel Posted August 10, 2007 Author Share Posted August 10, 2007 OK, I added the function and it works pretty nice. Is there any way I can limit the updown to two digits? Link to comment Share on other sites More sharing options...
bogQ Posted August 10, 2007 Share Posted August 10, 2007 (edited) OK, I added the function and it works pretty nice. Is there any way I can limit the updown to two digits?i dono if there is some function (command) to do that, but you can try something like this While $loop = 0 ;========================= ;Refresca el reloj de hora actual if Not $MediElTiempo Then $Empezar = TimerInit() $MediElTiempo = True EndIf $dif = TimerDiff($Empezar) if $dif>4000 Then refrescar_reloj() $MediElTiempo = False EndIf ;========================= $msg=GUIGetMsg() $xl = GUICtrlRead($HoraApagado, 1) $x2 = StringLen ( $xl) Select Case $x2 > 2 $var = StringRight($xl, 2) GUICtrlSetData($HoraApagado,$var) Case $msg = $GUI_EVENT_CLOSE i added it only 4 H if you need it 4 min. set other variables i hope that this is working in your case Edited August 10, 2007 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 10, 2007 Share Posted August 10, 2007 OK, I added the function and it works pretty nice. Is there any way I can limit the updown to two digits?Read the help file on GUICtrlSetLimit(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Nahuel Posted August 10, 2007 Author Share Posted August 10, 2007 Read the help file on GUICtrlSetLimit(). I did that, and if you check my script you'll see that I used it. But I can't set the limit for number of digits. It only lets me set the min and max values... Link to comment Share on other sites More sharing options...
Generator Posted August 10, 2007 Share Posted August 10, 2007 Directly from help file, modified to suit your case, the key is, set limit for the Input box, not the updown control #include <GUIConstants.au3> $title = "My GUI UpDown" GUICreate($title,-1,-1,-1,-1, $WS_SIZEBOX) $input = GUICtrlCreateInput ("2",10,10, 50, 20) $updown = GUICtrlCreateUpdown($input) ; Attempt to resize input control GUICtrlSetPos($input, 10,10, 100, 40 ) GUICtrlSetLimit($input,2) GUISetState () ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend msgbox(0,"Updown",GUICtrlRead($input)) Link to comment Share on other sites More sharing options...
Nahuel Posted August 10, 2007 Author Share Posted August 10, 2007 Of course!! hahaha Yeah, that did the trick. Thank you! Link to comment Share on other sites More sharing options...
bogQ Posted August 11, 2007 Share Posted August 11, 2007 I need to know if there's a way I can make the UpDown 'uneditable' (you can only change the numbers by clicking the up and down buttons) and set the numbers to 2 digits. Thanks!i runed your script from your post on Example Scripts and i like it ^^ i whas reading the help file... $ES_READONLY is the command $HoraApagado = GUICtrlCreateInput (@HOUR,$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) $MinApagado = GUICtrlCreateInput (@MIN,$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) and i think that your GUICtrlCreateCombo need this (only sugestion ) $combo=GUICtrlCreateCombo("Shutdown",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200,$WS_VSCROLL+$CBS_DROPDOWNLIST+$CBS_SORT+$CBS_AUTOHSCROLL) heare it is edited from your Example Scripts post expandcollapse popup#include <GuiConstants.au3> $loop2=1 $AnchoVentana = 250 $AltoVentana = 200 $MargenIzquierdo=10 $MargenSuperior=10 $Separador=20 $AnchoEtiqueta=130 $AltoEtiqueta=22 Opt("TrayAutoPause",0) Opt("TrayMenuMode",1) GuiCreate("Timer", $AnchoVentana, $AltoVentana) ;Current time: $Reloj=GUICtrlCreateLabel(@HOUR&":"&@MIN,$AnchoVentana/2-$Separador,$MargenSuperior+6,$AnchoEtiqueta) GUICtrlSetFont($Reloj, 10, 500, "", "Verdana") ;Hour $HoraApagado = GUICtrlCreateInput (@HOUR,$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($HoraApagado) GUICtrlSetLimit(-1, 23,00) GUICtrlSetLimit($HoraApagado, 2) GUICtrlCreateLabel("Hours",$MargenIzquierdo+5+65,$MargenSuperior+$Separador*2+12) ;Minutes $MinApagado = GUICtrlCreateInput (@MIN,$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($MinApagado) GUICtrlSetLimit(-1, 59,00) GUICtrlSetLimit($MinApagado, 2) GUICtrlCreateLabel("Minutes",$MargenIzquierdo+$Separador+100+65,$MargenSuperior+$Separador*2+12) ;Events $combo=GUICtrlCreateCombo("Shutdown",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200,$WS_VSCROLL+$CBS_DROPDOWNLIST+$CBS_SORT+$CBS_AUTOHSCROLL) TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Nahuel Posted August 11, 2007 Author Share Posted August 11, 2007 hahaha Yeah!!! That's exactly what I wanted. And you made the combo read-only too! You're da man I'll edit my post on the example forum 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