muncherw Posted December 28, 2007 Share Posted December 28, 2007 This is a simple search that points to a file out on one of my servers and let's me search through users on my network. It works fine but one irritation I have is that when I type a name (or any search criteria) into the search field hitting 'Enter' doesn't trigger the search, instead I have to click the button to search. (Actually the very first search I do when it's opened will allow me to hit the 'Enter' key but that's the only time it works). I'd be greatful for any help. I'm using the latest of both production and beta versions of AutoIt. CODE;------------------------------------------------------------------------------ ; NAME: INFOLOG.AU3 ; Author: TSHII ; DESCRIPTION: Searches a given logfile for a substring. It does so by ; checking each individual line and returning all lines that have the ; substring. ;------------------------------------------------------------------------------ ;---------------------------------------------------------------------- ; INCLUDES ;---------------------------------------------------------------------- #include <GUIConstants.au3> Opt("TrayAutoPause",0) ;0=no pause, 1=Pause TraySetIcon("Shell32.dll", 23) ;Magnifying Glass ;---------------------------------------------------------------------- ; VARIABLES ;---------------------------------------------------------------------- $SEARCHSTRING = "" $LOGFILEPATH = "\\mserver\users_share\super\log\" ;$LOGFILEPATH = "y:\super\log\" $LOGFILENAME = "Login.txt" $LOGFILESTR = $LOGFILEPATH & $LOGFILENAME $ss = "" $lf = "" $FILE = "" ;---------------------------------------------------------------------- ; CREATE GUI LOG WINDOW ;---------------------------------------------------------------------- Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Lookup User", 650, 430) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $labelSearchStr = GuiCtrlCreateLabel("Search String:", 10, 20, 80, 20) $getSearchStr = ("", 90, 20, 200, 20) GUICtrlSetData($getSearchStr, $SEARCHSTRING) $SearchButton = GUICtrlCreateButton("Search", 310, 17, 60) GUICtrlSetOnEvent($SearchButton, "SearchButton") GUICtrlSetState($SearchButton, $GUI_DEFBUTTON) $labelLogFile = GuiCtrlCreateLabel("Log File:", 10, 55, 80, 20) $getLogFile = GuiCtrlCreateInput("", 90, 55, 200, 20) GUICtrlSetData($getLogFile, $LOGFILESTR) $LogFileButton = GUICtrlCreateButton("Log File", 310, 52, 60) GUICtrlSetOnEvent($LogFileButton, "LogFileButton") $EditBox = GUICtrlCreateEdit( "", 10, 90, 630 , 300 , $WS_VSCROLL) GUICtrlSetFont($EditBox, 9, 400, 0, "Courier New") $labelStatus = GuiCtrlCreateLabel("No Searches Performed", 10, 400, 200, 20) ;GUICtrlSetData($labelStatus, $LOGFILEPATH & $LOGFILENAME, "x") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func SearchButton() ; Note: at this point @GUI_CTRLID would equal $okbutton GUICtrlSetData($EditBox, "") $ss = GUICtrlRead($getSearchStr) $lf = GUICtrlRead($getLogFile) ;MsgBox(0, "GUI Event", "You pressed Search! " & $ss & " " & $lf ) $FILE = FileOpen($lf, 0) ; Check if file opened for reading OK If $FILE = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $lc = 0 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($FILE) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $FILE) If ($ss == "*") Then $pos = 1 Else $pos = StringInStr($line, $ss) EndIf If ($pos > 0) Then GUICtrlSetData($EditBox, $lc & " ", "x") GUICtrlSetData($EditBox, $line & @CRLF, "x") $lc += 1 EndIf $pos = 0 Wend FileClose($FILE) GUICtrlSetData($labelStatus, $lc & " occurances of " & $ss & " found." ) EndFunc Func LogFileButton() ;MsgBox(0, "GUI Event", "You pressed Log File! Nothing to see here yet.") $ss = FileOpenDialog("Locate Log File", $LOGFILEPATH, "All (*.*)", 1+2) $LOGFILEPATH = StringLeft($ss, StringInStr($ss, "\", 0, -1)) $LOGFILENAME = StringRight($ss, StringLen($ss) - StringInStr($ss, "\", 0, -1)) $LOGFILESTRING = $ss ;MsgBox(0, "Log File", $ss & @CRLF & $LOGFILEPATH & @CRLF & $LOGFILENAME) GUICtrlSetData($getLogFile, $ss) EndFunc Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;@GUI_WINHANDLE will be either $mainwindow or $dummywindow If @GUI_WINHANDLE = $mainwindow Then ;MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...") Exit EndIf EndFunc Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic] Link to comment Share on other sites More sharing options...
martin Posted December 28, 2007 Share Posted December 28, 2007 (edited) Maybe this expandcollapse popup;------------------------------------------------------------------------------ ; NAME: INFOLOG.AU3 ; Author: TSHII ; DESCRIPTION: Searches a given logfile for a substring. It does so by ; checking each individual line and returning all lines that have the ; substring. ;------------------------------------------------------------------------------ ;---------------------------------------------------------------------- ; INCLUDES ;---------------------------------------------------------------------- #include <GUIConstants.au3> Opt("TrayAutoPause", 0);0=no pause, 1=Pause TraySetIcon("Shell32.dll", 23);Magnifying Glass ;---------------------------------------------------------------------- ; VARIABLES ;---------------------------------------------------------------------- $SEARCHSTRING = "" $LOGFILEPATH = "\\mserver\users_share\super\log\" ;$LOGFILEPATH = "y:\super\log\" $LOGFILENAME = "Login.txt" $LOGFILESTR = $LOGFILEPATH & $LOGFILENAME $ss = "" $lf = "" $FILE = "" ;---------------------------------------------------------------------- ; CREATE GUI LOG WINDOW ;---------------------------------------------------------------------- Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Lookup User", 650, 430) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $labelSearchStr = GUICtrlCreateLabel("Search String:", 10, 20, 80, 20) $getSearchStr = GUICtrlCreateEdit("", 90, 20, 200, 20) GUICtrlSetData($getSearchStr, $SEARCHSTRING) $SearchButton = GUICtrlCreateButton("Search", 310, 17, 60) GUICtrlSetOnEvent($SearchButton, "SearchButton") GUICtrlSetState($SearchButton, $GUI_DEFBUTTON) $labelLogFile = GUICtrlCreateLabel("Log File:", 10, 55, 80, 20) $getLogFile = GUICtrlCreateInput("", 90, 55, 200, 20) GUICtrlSetData($getLogFile, $LOGFILESTR) $LogFileButton = GUICtrlCreateButton("Log File", 310, 52, 60) GUICtrlSetOnEvent($LogFileButton, "LogFileButton") $EditBox = GUICtrlCreateEdit("", 10, 90, 630, 300, BitOR($WS_VSCROLL, $ES_WANTRETURN)) GUICtrlSetFont($EditBox, 9, 400, 0, "Courier New") $labelStatus = GUICtrlCreateLabel("No Searches Performed", 10, 400, 200, 20) ;GUICtrlSetData($labelStatus, $LOGFILEPATH & $LOGFILENAME, "x") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 Sleep(1000); Idle around WEnd Func SearchButton() HotKeySet("{ENTER}") ConsoleWrite("Hotkey no longer setfor ENTER" & @LF) GUICtrlSetState($SearchButton, $GUI_FOCUS) ; Note: at this point @GUI_CTRLID would equal $okbutton GUICtrlSetData($EditBox, "") $ss = GUICtrlRead($getSearchStr) $lf = GUICtrlRead($getLogFile) ;MsgBox(0, "GUI Event", "You pressed Search! " & $ss & " " & $lf ) $FILE = FileOpen($lf, 0) ; Check if file opened for reading OK If $FILE = -1 Then MsgBox(0, "Error", "Unable to open file.") ;Exit EndIf $lc = 0 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($FILE) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $FILE) If ($ss == "*") Then $pos = 1 Else $pos = StringInStr($line, $ss) EndIf If ($pos > 0) Then GUICtrlSetData($EditBox, $lc & " ", "x") GUICtrlSetData($EditBox, $line & @CRLF, "x") $lc += 1 EndIf $pos = 0 WEnd FileClose($FILE) GUICtrlSetData($labelStatus, $lc & " occurances of " & $ss & " found.") EndFunc ;==>SearchButton Func LogFileButton() HotKeySet("{ENTER}") ;MsgBox(0, "GUI Event", "You pressed Log File! Nothing to see here yet.") $ss = FileOpenDialog("Locate Log File", $LOGFILEPATH, "All (*.*)", 1 + 2) $LOGFILEPATH = StringLeft($ss, StringInStr($ss, "\", 0, -1)) $LOGFILENAME = StringRight($ss, StringLen($ss) - StringInStr($ss, "\", 0, -1)) $LOGFILESTRING = $ss ;MsgBox(0, "Log File", $ss & @CRLF & $LOGFILEPATH & @CRLF & $LOGFILENAME) GUICtrlSetData($getLogFile, $ss) EndFunc ;==>LogFileButton Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;@GUI_WINHANDLE will be either $mainwindow or $dummywindow If @GUI_WinHandle = $mainwindow Then ;MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...") Exit EndIf EndFunc ;==>CLOSEClicked Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) $hCtrl = $lParam If $nNotifyCode = $EN_CHANGE Then Switch $nID Case $getSearchStr HotKeySet("{ENTER}", "SearchButton") Case $getLogFile HotKeySet("{ENTER}", "LogFileButton") Case Else HotKeySet("{ENTER}") EndSwitch EndIf return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND EDIT: improved Edited December 28, 2007 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...
muncherw Posted December 28, 2007 Author Share Posted December 28, 2007 Thanks, Martin! It didn't occur to me to create a hotkey to put in the middle. I was thinking that I might be doing so mething wrong. I'm not a programmer at all, I just dabble here and there when I need something so my brain isn't very good at outside-the-box thinking when it comes to coding. I really appreciate your addition to this. Now to try and figure out exactly what it is you did. I didn't expect you to actually do it for me so that's a nice little treat. Thanks! Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic] 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