lafafmentvotre Posted February 28, 2011 Share Posted February 28, 2011 (edited) HelloFirst, i need to read a file (cf printers.txt) and put informations in an 2D array like this :Second, find information in the first column and retrieve columns informations 2 and 3 to use in a GUI ($findrow_Col 1 and $findrow_Col 2)Is it possible ?Thanks for helpprinters.txt Edited February 28, 2011 by lafafmentvotre Link to comment Share on other sites More sharing options...
hannes08 Posted February 28, 2011 Share Posted February 28, 2011 Hi lafafmentvotre, first do a _FileReadToArray(), then loop through the array and do a stringsplit to have a row with columns. You can do a StringSearch even use a StringregExp to find information in the first column. From there it is only a little step to the informations in the following columns. Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
guinness Posted February 28, 2011 Share Posted February 28, 2011 (edited) OK, for question 1, use _FileReadToArray() to get the entire contents of the Printers.txt. Then loop through this and use StringSplit() on each entry and assign to a new 2D Array. (It's my understanding you have knowledge of Arrays )And then for question 2 have a look at _GUICtrlListView_AddArray()Edit: I see Hannes123 hand's were typing away too. Edited February 28, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
lafafmentvotre Posted February 28, 2011 Author Share Posted February 28, 2011 Hello Thanks for responses I made this script but i'm not a master in array : #region AUTOIT VARIABLES #include <Array.au3> #include <file.au3> #endregion #region SCRIPT VARIABLES Local $file="Sources\printers.txt" Local $fileopen=FileOpen($file, 0) Local $avArray _FileReadToArray($file, $avArray) #endregion $i=1 For $i=1 To _FileCountLines($file) $avArray=StringSplit(FileReadLine($file,$i),",") _ArrayDisplay($avArray) If @error = -1 Then ExitLoop $ip=_ArrayToString($avArray, @TAB, 1, 1) $name=_ArrayToString($avArray, @TAB, 2, 2) $location=_ArrayToString($avArray, @TAB, 3, 3) MsgBox(0,'',$ip&@crlf&$name&@CRLF&$location) Next FileClose($file) Link to comment Share on other sites More sharing options...
hannes08 Posted February 28, 2011 Share Posted February 28, 2011 Hi lafafmentvotre, If you use _FileReadToArray() You don't need the _fleCountLines and the FileOpen and the FileReadLine functions. Just loop through the array: _FileReadToArray($file, $avArray) For $i = 1 To $avArray[0] $aTemp = StringSplit($avArray, ";") ;$aTemp[1] : first clumn ;$aTemp[2] : second clumn ;$aTemp[3] : third clumn Next Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
lafafmentvotre Posted February 28, 2011 Author Share Posted February 28, 2011 I'm sorry but i dont understand. I made this : _FileReadToArray($file, $avArray) For $i = 1 To $avArray[0] $aTemp = StringSplit($avArray,",") _ArrayDisplay($aTemp) Next But results are not ok Link to comment Share on other sites More sharing options...
guinness Posted February 28, 2011 Share Posted February 28, 2011 (edited) I found this >> Global $File = "Test.txt" Global $Array = _FileArray_Split($File, ",") If Not @error Then _ArrayDisplay($Array) Edited February 28, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
saywell Posted February 28, 2011 Share Posted February 28, 2011 Could you clarify which data items you want to find, and in what format you want to present them. Thanks. William Link to comment Share on other sites More sharing options...
lafafmentvotre Posted February 28, 2011 Author Share Posted February 28, 2011 (edited) Hi GuinessIt works to findThanksHi saywellI need to read a file and use Col1 to set data in a GUICtrlCreateCombo.If i select a value in the combo, i need to retrieve informations.If my search value is 'printer03', i need to retrieve $ip='10.0.01.03' and $location='location03'$ip and $location will be integrated into a GUI inputFor now and thanks to Guiness, i made this script :expandcollapse popup#region AUTOIT VARIABLES #include <Array.au3> #include <file.au3> #endregion #region SCRIPT VARIABLES Global $File = "Sources\printers.txt" Global $avArray = _FileArray_Split($File, ",") #endregion #Region SCRIPT If Not @error Then _ArrayDisplay($avArray) $sSearch='printer03' $sColumn='1' $ip=_ArraySearch($avArray, $sSearch, 0, 0, 0, 1, 1, $sColumn) ;~ $name=?? ;~ $location=?? MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $ip & ' on column ' & $sColumn & '.') #endregion #region FUNCTIONS Func _FileArray_Split($sFile, $sDelimiter = "|") Local $sFileOpen = FileOpen($sFile, 0) ; Code based around the function _FileReadToArray included in File.au3 If $sFileOpen = -1 Then Return SetError(1, 1, 0) Local $sFileRead = FileRead($sFileOpen, FileGetSize($sFile)) If StringRight($sFileRead, 1) = @LF Or StringRight($sFileRead, 1) = @CR Then $sFileRead = StringTrimRight($sFileRead, 1) FileClose($sFileOpen) If StringInStr($sFileRead, @LF) Then Local $TEMPsArray = StringSplit(StringStripCR($sFileRead), @LF) ElseIf StringInStr($sFileRead, @CR) Then $TEMPsArray = StringSplit($sFileRead, @CR) Else If StringLen($sFileRead) Then Dim $TEMPsArray[2] = [1, $sFileRead] Else Return SetError(1, 2, 0) EndIf EndIf Local $sStringSplit = StringSplit($TEMPsArray[1], $sDelimiter) ; Split the first line to find the number of columns for defining final Array Local $sArray[$TEMPsArray[0] + 1][$sStringSplit[0]] = [[0, $sStringSplit[0]]] ; Define final Array with the results found from reading the file and splitting line 1 For $A = 1 To $TEMPsArray[0] $sStringSplit = StringSplit($TEMPsArray[$A], $sDelimiter) ; Split the nth line to create a Temp Array If Not IsArray($sStringSplit) Then ContinueLoop ; If not Array then skip For $B = 1 To $sStringSplit[0] $sArray[$sArray[0][0] + 1][$B - 1] = $sStringSplit[$B] ; Add split data (by looping) to the final Array Next If UBound($sArray, 1) <= $sArray[0][0] + 1 Then ReDim $sArray[UBound($sArray, 1) * 2][UBound($sArray, 2)] ; Resize the number of rows if required $sArray[0][0] += 1 ; Add count to final Array Next ReDim $sArray[$sArray[0][0] + 1][UBound($sArray, 2)] ; Remove empty rows located at the end of the final Array Return $sArray ; Return the final Array EndFunc ;==>_FileArray_Split #endregionI just need to find $ip and $location informations. Edited February 28, 2011 by lafafmentvotre Link to comment Share on other sites More sharing options...
saywell Posted February 28, 2011 Share Posted February 28, 2011 Here's a different approach to consider: expandcollapse popup#include <sqlite.au3> #include <sqlite.dll.au3> #include <file.au3> #include <Array.au3> Global $aResult, $iRows, $iColumns If Not FileExists (@ScriptDir & "\Printers.sqlite") Then database() _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") _SQLite_GetTable2d (-1,"SELECT * FROM printers;", $aResult, $iRows, $iColumns) _ArrayDisplay ($aResult, "$aResult") Func database() Dim $aRecords If Not _FileReadToArray(@ScriptDir & "\printers.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf ;_ArrayDisplay ($aRecords,"$aRecords") Local $hQuery,$aRow _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") ; Whithout $sCallback its an Resultless query _SQLite_Exec(-1,"Create table printers (IP CHAR NOT NULL,CompNo CHAR, Loc CHAR); " ) For $x = 1 to $aRecords[0] Local $sRecord = "'" & $aRecords[$x] & "'" $sRecord = StringReplace ($sRecord, " ", "'") $sRecord = StringReplace ($sRecord, ",", "','") ;Msgbox(0,'Record:' & $x, $sRecord) _SQLite_Exec(-1,"INSERT INTO printers (IP, CompNo, Loc) VALUES ("& $sRecord & ") ; " ) Next _SQLite_Close() _SQLite_Shutdown() EndFunc ; ==>database You might need to change the file locations. You can then get the required data from the array $aResult or by using SQlite commands for more complex queries. William Link to comment Share on other sites More sharing options...
lafafmentvotre Posted February 28, 2011 Author Share Posted February 28, 2011 (edited) Hello Wonderfull but my need is to to find $ip value and the value $location with printer value. Could you help me with this script ? expandcollapse popup#region AUTOIT VARIABLES #include <Array.au3> #include <file.au3> #endregion #region SCRIPT VARIABLES Global $File = "Sources\printers.txt" Global $avArray = _FileArray_Split($File, ",") #endregion #Region SCRIPT If Not @error Then _ArrayDisplay($avArray) $sSearch='printer03' $sColumn='1' $ip=_ArraySearch($avArray, $sSearch, 0, 0, 0, 1, 1, $sColumn) ;~ $name=?? ;~ $location=?? MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $ip & ' on column ' & $sColumn & '.') #endregion #region FUNCTIONS Func _FileArray_Split($sFile, $sDelimiter = "|") Local $sFileOpen = FileOpen($sFile, 0) ; Code based around the function _FileReadToArray included in File.au3 If $sFileOpen = -1 Then Return SetError(1, 1, 0) Local $sFileRead = FileRead($sFileOpen, FileGetSize($sFile)) If StringRight($sFileRead, 1) = @LF Or StringRight($sFileRead, 1) = @CR Then $sFileRead = StringTrimRight($sFileRead, 1) FileClose($sFileOpen) If StringInStr($sFileRead, @LF) Then Local $TEMPsArray = StringSplit(StringStripCR($sFileRead), @LF) ElseIf StringInStr($sFileRead, @CR) Then $TEMPsArray = StringSplit($sFileRead, @CR) Else If StringLen($sFileRead) Then Dim $TEMPsArray[2] = [1, $sFileRead] Else Return SetError(1, 2, 0) EndIf EndIf Local $sStringSplit = StringSplit($TEMPsArray[1], $sDelimiter) ; Split the first line to find the number of columns for defining final Array Local $sArray[$TEMPsArray[0] + 1][$sStringSplit[0]] = [[0, $sStringSplit[0]]] ; Define final Array with the results found from reading the file and splitting line 1 For $A = 1 To $TEMPsArray[0] $sStringSplit = StringSplit($TEMPsArray[$A], $sDelimiter) ; Split the nth line to create a Temp Array If Not IsArray($sStringSplit) Then ContinueLoop ; If not Array then skip For $B = 1 To $sStringSplit[0] $sArray[$sArray[0][0] + 1][$B - 1] = $sStringSplit[$B] ; Add split data (by looping) to the final Array Next If UBound($sArray, 1) <= $sArray[0][0] + 1 Then ReDim $sArray[UBound($sArray, 1) * 2][UBound($sArray, 2)] ; Resize the number of rows if required $sArray[0][0] += 1 ; Add count to final Array Next ReDim $sArray[$sArray[0][0] + 1][UBound($sArray, 2)] ; Remove empty rows located at the end of the final Array Return $sArray ; Return the final Array EndFunc ;==>_FileArray_Split #endregion Thanks Edited February 28, 2011 by lafafmentvotre Link to comment Share on other sites More sharing options...
saywell Posted February 28, 2011 Share Posted February 28, 2011 OK, I've changed your text file to match the image in the original post [ie with the middle cloumn printer01, printer02 etc (attached). You now get a message box to enter the printer (eg printer03) and it pops up a message box with the IP address and location. expandcollapse popup#include <sqlite.au3> #include <sqlite.dll.au3> #include <file.au3> #include <Array.au3> Global $aResult, $iRows, $iColumns, $aRow, $hQuery If Not FileExists (@ScriptDir & "\Printers.sqlite") Then database() _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") ; _SQLite_GetTable2d (-1,"SELECT * FROM printers;", $aResult, $iRows, $iColumns) ;_ArrayDisplay ($aResult, "$aResult") Global $sSearchTerm = "" $sSearchTerm = InputBox ("Printer", "Enter the printer for which to search") ;MsgBox (0, "Printer", $sSearchTerm) If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) ;_ArrayDisplay ($aRow, "IP and Location for " & $sSearchTerm) EndIf MsgBox (4096, "Result for " & $sSearchTerm, "The IP address is: " & $aRow[0] &@CR& "The Location is: "& $aRow[1]) _SQLite_Close () _SQLite_Shutdown () Exit Func database() Dim $aRecords If Not _FileReadToArray(@ScriptDir & "\printers.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf ;_ArrayDisplay ($aRecords,"$aRecords") Local $hQuery,$aRow _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") ; Whithout $sCallback its an Resultless query _SQLite_Exec(-1,"Create table printers (IP CHAR NOT NULL,CompNo CHAR, Loc CHAR); " ) For $x = 1 to $aRecords[0] Local $sRecord = "'" & $aRecords[$x] & "'" $sRecord = StringReplace ($sRecord, " ", "'") $sRecord = StringReplace ($sRecord, ",", "','") ;Msgbox(0,'Record:' & $x, $sRecord) _SQLite_Exec(-1,"INSERT INTO printers (IP, CompNo, Loc) VALUES ("& $sRecord & ") ; " ) Next _SQLite_Close() _SQLite_Shutdown() EndFunc ; ==>database Note that if you change the data in the printers.txt file, you need to delete the sqlite file so it's re-created with the new data from the txt file. otherwise you can leave it be. William Link to comment Share on other sites More sharing options...
lafafmentvotre Posted February 28, 2011 Author Share Posted February 28, 2011 Yeeeeessssss It works with an error message in /ErrorStdOut : ! SQLite.au3 Error --> Function: _SQLite_Close --> Error: unable to close due to unfinalised statements Do you know how can i retrieve the Col1's elements (printer name) to set data in a GUICtrlCreateCombo ? I will use your script after to find informations with the combo value. Thanks Link to comment Share on other sites More sharing options...
saywell Posted February 28, 2011 Share Posted February 28, 2011 This will load the printer names into 2 variables - one for the first entry in the combo box, the other for the drop-down list. For demo purposes, these show on a message box. You should be able to add them easily to you GUI - though you might want to split my code into a couple of functions. William expandcollapse popup#include <sqlite.au3> #include <sqlite.dll.au3> #include <file.au3> #include <Array.au3> #include <GUIConstantsEx.au3> Global $aResult, $iRows, $iColumns, $aRow, $hQuery, $msg If Not FileExists (@ScriptDir & "\Printers.sqlite") Then database() _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") _SQLite_GetTable2d (-1,"SELECT * FROM printers;", $aResult, $iRows, $iColumns) _ArrayDisplay ($aResult, "$aResult") Global $comboFirst = $aResult[1][1] Global $comboList= $aResult[2][1] For $i = 3 To UBound($aResult)-1 $comboList = $comboList & "|" & $aResult[$i][1] Next MsgBox (4096, "ComboBox Variables", "First line = "& $comboFirst & @CR&@CR& "Rest of list = "& $comboList) Global $sSearchTerm = $comboFirst ;$sSearchTerm = InputBox ("Printer", "Enter the printer for which to search") ;MsgBox (0, "Printer", $sSearchTerm) If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) ;_ArrayDisplay ($aRow, "IP and Location for " & $sSearchTerm) EndIf MsgBox (4096, "Result for " & $sSearchTerm, "The IP address is: " & $aRow[0] &@CR& "The Location is: "& $aRow[1]) _SQLite_Close () _SQLite_Shutdown () Exit Func database() Dim $aRecords If Not _FileReadToArray(@ScriptDir & "\printers.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf ;_ArrayDisplay ($aRecords,"$aRecords") Local $hQuery,$aRow _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") ; Whithout $sCallback its an Resultless query _SQLite_Exec(-1,"Create table printers (IP CHAR NOT NULL,CompNo CHAR, Loc CHAR); " ) For $x = 1 to $aRecords[0] Local $sRecord = "'" & $aRecords[$x] & "'" $sRecord = StringReplace ($sRecord, " ", "'") $sRecord = StringReplace ($sRecord, ",", "','") ;Msgbox(0,'Record:' & $x, $sRecord) _SQLite_Exec(-1,"INSERT INTO printers (IP, CompNo, Loc) VALUES ("& $sRecord & ") ; " ) Next _SQLite_Close() _SQLite_Shutdown() EndFunc ; ==>database Link to comment Share on other sites More sharing options...
lafafmentvotre Posted March 1, 2011 Author Share Posted March 1, 2011 Hi Saywell Many thanks for help. it works in part because I can not refresh my values ($ ip and $ location) when I change my combobox ($ printer). Can I send you my script in private? Link to comment Share on other sites More sharing options...
saywell Posted March 1, 2011 Share Posted March 1, 2011 OK - but if you post here [you can blank out sensitive stuff like corporate server details] you'll get a wider opinion and probably better advise! I'm a learner myself. Firstly, how are you reading the combo box? I usually do it with a button press, but cleverer people here can do it by watching for a change being made in the box. William Link to comment Share on other sites More sharing options...
lafafmentvotre Posted March 1, 2011 Author Share Posted March 1, 2011 Hi Here is my script : expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIT: 3.3.6.1 Author: Infrastructure@2011 Function: Install Printers #ce ---------------------------------------------------------------------------- Break(1) #region AUTOIT VARIABLES #include <GUIConstants.au3> #include <Array.au3> #include <Process.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ;~ #include "Language.au3" #include <EditConstants.au3> #include <sqlite.au3> #include <sqlite.dll.au3> #include <file.au3> #include <GUIConstantsEx.au3> #endregion #region DIRECTORY & DRIVERS ;~ FileInstall("logo.bmp", @TempDir&'logo.bmp') FileInstall('printers.txt',@TempDir&'printers.txt') #endregion #region SCRIPT VARIABLES Global $aResult, $iRows, $iColumns, $aRow, $hQuery, $msg,$comboList,$comboFirst,$printer Global $file=@TempDir&'printers.txt' ;~ Global $logo=@TempDir&'logo.bmp' Local $inf_PCL5='.\Drivers\PCL5\hpcu104t.inf' Local $inf_PCL6='.\Drivers\PCL6\hpcu094u.inf' Local $inf_PS='.\Drivers\PS\hpcu107v.inf' Local $Form, $printer_ip,$printer_name,$ip,$printer Local $sServiceName="Spooler" Local $regsuffix=RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Domain") $green="0x11EF56" $red="0xFF0101" $blue="0xD9E3E9" $SDIversion="V1" $blank='' #endregion #region Language Variables ;FR $m0_FR = "------ Installation Zebra ------" $m1_FR = "Récupération des informations en cours..." $m2_FR = "&Fichier" $m3_FR = "Installer" $m4_FR = "Quitter" $m5_FR = "Imprimante" $m6_FR = "Imprimante à installer" $m7_FR = "Pilote à utiliser" $m8_FR = "Effacer" $m9_FR = "Installation terminée" $m10_FR = "Merci de redémarrez l'ordinateur." $m11_FR = "Erreur" $m12_FR = "Aucun nom d'imprimante et/ou IP n'a été saisi." & @LF & "Saisissez un nom et/ou IP et cliquez sur ""Installer""" $m13_FR = "Nom :" $m14_FR = "Emplacement :" $m15_FR = "Ip :" ;EN $m0_US = "------ Zebra's Installation ------" $m1_US = "Update Informations in progress..." $m2_US = "&File" $m3_US = "Installing" $m4_US = "Exit" $m5_US = "Printer" $m6_US = "Printer to install" $m7_US = "Driver to use" $m8_US = "Reset" $m9_US = "Finished installation" $m10_US = "Thank you for restart the computer." $m11_US = "Error" $m12_US = "No name of printer and/or IP was seized." & @LF & "Seize a name and/or IP and click on ""Installing""" $m13_US = "Name :" $m14_US = "Location :" $m15_US = "Ip :" ;~ Select ;~ Case _Language() = "French" ;~ $m0 = $m0_FR ;~ $m1 = $m1_FR ;~ $m2 = $m2_FR ;~ $m3 = $m3_FR ;~ $m4 = $m4_FR ;~ $m5 = $m5_FR ;~ $m6 = $m6_FR ;~ $m7 = $m7_FR ;~ $m8 = $m8_FR ;~ $m9 = $m9_FR ;~ $m10 = $m10_FR ;~ $m11 = $m11_FR ;~ $m12 = $m12_FR ;~ $m13 = $m13_FR ;~ $m14 = $m14_FR ;~ $m15 = $m15_FR ;~ Case _Language() = "English" $m0 = $m0_US $m1 = $m1_US $m2 = $m2_US $m3 = $m3_US $m4 = $m4_US $m5 = $m5_US $m6 = $m6_US $m7 = $m7_US $m8 = $m8_US $m9 = $m9_US $m10 = $m10_US $m11 = $m11_US $m12 = $m12_US $m13 = $m13_US $m14 = $m14_US $m15 = $m15_US ;~ EndSelect #endregion #region FIRST GUI FileDelete(@ScriptDir&'\Printers.sqlite') $recup_info = GUICreate($m0, 286, 99, -1, -1, $WS_POPUPWINDOW) $label1_recup_info=GUICtrlCreateLabel($m0, 0, 16, 286, 17, $SS_CENTER) GUICtrlSetFont(-1, 9, 800) $label3_recup_info=GUICtrlCreateLabel($m1, 0, 56, 286, 17,$SS_CENTER) GUISetState(@SW_SHOW,$recup_info) sqlite_combo() Sleep(1000) #endregion #region GUI $Form = GUICreate($m0, 400, 250, -1, -1,$WS_POPUPWINDOW) GUISetBkColor($blue) ;~ GUICtrlCreatePic($logo, 125, 205, 0, 0) $filemenu=GUICtrlCreateMenu ($m2) $installitem=GUICtrlCreateMenuitem ($m3,$filemenu) $resetitem=GUICtrlCreateMenuItem($m8,$filemenu) $exititem=GUICtrlCreateMenuitem ($m4,$filemenu) ;Printer $Group1 = GUICtrlCreateGroup($m6, 8, 8, 385, 90) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $printer_label=GUICtrlCreateLabel($m13, 30, 32, 70, 20,$SS_RIGHT) ;~ $printer=GUICtrlCreateInput("", 105, 30, 200, 20) $printer=GUICtrlCreateCombo("", 105, 30, 200, 20) ;~ sqlite_combo() GUICtrlSetData(-1,$comboFirst&'|'&$comboList) ;~ MsgBox (4096, "ComboBox Variables",$comboFirst&'|'&$comboList) $ip_label=GUICtrlCreateLabel($m15, 30, 52, 70, 20,$SS_RIGHT) $ip=GUICtrlCreateInput("", 105, 50, 200, 20,$ES_READONLY) GUICtrlSetData($ip,$aRow[0]) $location_label=GUICtrlCreateLabel($m14, 30, 72, 70, 20,$SS_RIGHT) $location=GUICtrlCreateInput("", 105, 70, 200, 20,$ES_READONLY) GUICtrlSetData($location,$aRow[1]) ;~ $location=GUICtrlCreateCombo("", 105, 70, 200, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;Driver $Group1 = GUICtrlCreateGroup($m7, 8, 108, 385, 50) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $driver=GUICtrlCreateCombo('',105,125,200,15) GUICtrlSetData(-1,'PCL5|PCL6|PS') GUICtrlCreateGroup("", -99, -99, 1, 1) ;Button $installbutton = GUICtrlCreateButton($m3, 65, 175, 87, 20) $resetbutton = GUICtrlCreateButton($m8, 155, 175, 87, 20) $exitbutton=GUICtrlCreateButton($m4, 245, 175, 87, 20) GUIDelete($recup_info) GUISetState(@SW_SHOW,$Form) #endregion #region SCRIPT While 1 $listener=GUIGetMsg() Select ;INSTALLING Case $listener=$installitem Or $listener=$installbutton $printer_name=GUICtrlRead($printer) $printer_ip=GUICtrlRead($ip) ;~ TCPStartup() ;~ $printer_ip=TCPNameToIP($printer_name) ;~ TCPShutdown() $driver_name=GUICtrlRead($driver) $location_name=GUICtrlRead($location) Select Case $printer_name='' MsgBox(16, $m11, $m12, 5) Case $printer_ip='' MsgBox(16, $m11, $m12, 5) Case $driver_name='' MsgBox(16, $m11, $m12, 5) Case Else GUISetState(@SW_HIDE,$Form) $gui_install=GuiCreate("", 300, 100, -1, -1, $WS_POPUPWINDOW) $label1=GUICtrlCreateLabel("-- "&StringTrimRight(StringUpper(@ScriptName),4)&" --", 0, 10, 300, 20, $SS_CENTER) GUICtrlSetFont(-1, 9, 800) $label2=GUICtrlCreateLabel("Vérification en cours...", 0, 40, 300, 20,$SS_CENTER) $label3=GUICtrlCreateLabel("", 0, 60, 300, 20,$SS_CENTER) GUICtrlSetFont(-1, 9, 800) GUISetState(@SW_SHOW,$gui_install) ;Port ;~ GUICtrlSetData($label2,"Installation Ports en cours...") ;~ GUICtrlSetData($label3,$printer_name) ;~ RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports','StatusUpdateEnabled','REG_DWORD','00000001') ;~ RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports','StatusUpdateInterval','REG_DWORD','0000000a') ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Hostname","REG_SZ","") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"HWAddress","REG_SZ","") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"IPAddress","REG_SZ",$printer_ip) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"PortNumber","REG_DWORD","9100") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Protocol","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Community","REG_SZ","public") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Enabled","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Index","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Version","REG_DWORD","00000001") ;~ Sleep(2000) ;Printer GUICtrlSetData($label2,"Installation Imprimante en cours...") GUICtrlSetData($label3,$printer_name) ;~ _RunDOS('net stop "'&$sServiceName&'"') ;~ Sleep(4000) ;~ _RunDOS('net start "'&$sServiceName&'"') ;~ Select ;~ Case $driver_name='PCL5' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PCL5&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PCL 5""","",@SW_HIDE) ;~ Case $driver_name='PCL6' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PCL6&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PCL 6""","",@SW_HIDE) ;~ Case $driver_name='PS' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PS&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PS""","",@SW_HIDE) ;~ EndSelect ;~ If $location_name<>'' Then ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name, "Location", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "Location", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name, "Description", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "Description", "REG_SZ", $location_name) ;~ EndIf ;~ _RunDOS('net stop "'&$sServiceName&'"') ;~ Sleep(4000) ;~ _RunDOS('net start "'&$sServiceName&'"') ;~ ;Parameters ;~ GUICtrlSetData($label2,"Paramétrage Imprimante en cours...") ;~ GUICtrlSetData($label3,$printer_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "uNCName", "REG_SZ", "\\"&@ComputerName&"."&$regsuffix&"\"&$printer_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "serverName", "REG_SZ", @ComputerName&"."&$regsuffix) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "shortServerName", "REG_SZ", @ComputerName) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "url", "REG_SZ", "http://"&@ComputerName&"."&$regsuffix&"/") ;~ Sleep(5000) GUIDelete($gui_install) GUISetState(@SW_SHOW,$Form) ;~ endmsg() EndSelect ;RESET Case $listener=$resetitem Or $listener=$resetbutton GUICtrlSetData($printer,$blank) GUICtrlSetData($ip,$blank) GUICtrlSetData($driver,$blank) GUICtrlSetData($location,$blank) GUICtrlSetData($driver,'HP|Driver02|Driver03') sqlite_combo() GUICtrlSetData($printer,$comboList,$comboFirst) GUICtrlSetData($ip,$aRow[0]) GUICtrlSetData($location,$aRow[1]) ;EXIT Case $listener=$GUI_EVENT_CLOSE Or $listener=$exititem Or $listener=$exitbutton ;~ FileDelete($logo) FileDelete($file) ExitLoop EndSelect WEnd #endregion #region FUNCTIONS Func endmsg() MsgBox(0, "Results", $m9&@CRLF&$m10,600) Exit EndFunc Func sqlite_combo() If Not FileExists (@ScriptDir & "\Printers.sqlite") Then database() _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") _SQLite_GetTable2d (-1,"SELECT * FROM printers;", $aResult, $iRows, $iColumns) ;~ _ArrayDisplay ($aResult, "$aResult") Global $comboFirst = $aResult[1][1] Global $comboList= $aResult[2][1] For $i = 3 To UBound($aResult)-1 $comboList = $comboList & "|" & $aResult[$i][1] Next ;~ MsgBox (4096, "ComboBox Variables", "First line = "& $comboFirst & @CR&@CR& "Rest of list = "& $comboList) ;~ MsgBox (4096, "ComboBox Variables",$comboFirst&'|'&$comboList) Global $sSearchTerm = $comboFirst ;~ Global $sSearchTerm = GUICtrlRead($printer) If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) EndIf ;~ MsgBox (4096, "Result for " & $sSearchTerm, "The IP address is: " & $aRow[0] &@CR& "The Location is: "& $aRow[1]) EndFunc Func database() Dim $aRecords If Not _FileReadToArray($file,$aRecords) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf Local $hQuery,$aRow _SQLite_Startup() _SQLite_Open(@ScriptDir & "\Printers.sqlite") _SQLite_Exec(-1,"Create table printers (IP CHAR NOT NULL,CompNo CHAR, Loc CHAR); " ) For $x = 1 to $aRecords[0] Local $sRecord = "'" & $aRecords[$x] & "'" $sRecord = StringReplace ($sRecord, " ", "'") $sRecord = StringReplace ($sRecord, ",", "','") _SQLite_Exec(-1,"INSERT INTO printers (IP, CompNo, Loc) VALUES ("& $sRecord & ") ; " ) Next _SQLite_Close() _SQLite_Shutdown() EndFunc ; ==>database #endregion Link to comment Share on other sites More sharing options...
saywell Posted March 1, 2011 Share Posted March 1, 2011 You need to take this part: If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) EndIf out of the SQLiteCombo function, as that's the bit that finds the IP address and location. I suggest a separate function Lookup() but remember to add the bits to open and close the database before and after the look-up, respectively, within the function. Assuming CompNo is unique, the data you need is IP address = $aRow[0] Location = $aRow[1] use that to update the variables (If you un-comment the messagebox you'll see the result) William Link to comment Share on other sites More sharing options...
lafafmentvotre Posted March 1, 2011 Author Share Posted March 1, 2011 Hi Saywell It works now : expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIT: 3.3.6.1 Author: Infrastructure@2011 Function: Install Printers #ce ---------------------------------------------------------------------------- Break(1) #region AUTOIT VARIABLES #include <GUIConstants.au3> #include <Array.au3> #include <Process.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ;~ #include "Language.au3" #include <EditConstants.au3> #include <sqlite.au3> #include <sqlite.dll.au3> #include <file.au3> #include <GUIConstantsEx.au3> #endregion #region DIRECTORY & DRIVERS ;~ FileInstall("logo.bmp", @TempDir&'logo.bmp') #endregion #region SCRIPT VARIABLES Global $aResult, $iRows, $iColumns, $aRow, $hQuery, $msg,$comboList,$comboFirst,$printer Global $file=@ScriptDir&'\printers.txt' Global $file_sqlite=@ScriptDir&'\printers.sqlite' ;~ Global $logo=@TempDir&'logo.bmp' Local $inf_PCL5='.\Drivers\PCL5\hpcu104t.inf' Local $inf_PCL6='.\Drivers\PCL6\hpcu094u.inf' Local $inf_PS='.\Drivers\PS\hpcu107v.inf' Local $Form, $printer_ip,$printer_name,$ip,$printer Local $sServiceName="Spooler" Local $regsuffix=RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Domain") $green="0x11EF56" $red="0xFF0101" $blue="0xD9E3E9" $SDIversion="V1" $blank='' #endregion #region Language Variables ;FR $m0_FR = "------ Installation Zebra ------" $m1_FR = "Récupération des informations en cours..." $m2_FR = "&Fichier" $m3_FR = "Installer" $m4_FR = "Quitter" $m5_FR = "Imprimante" $m6_FR = "Imprimante à installer" $m7_FR = "Pilote à utiliser" $m8_FR = "Effacer" $m9_FR = "Installation terminée" $m10_FR = "Merci de redémarrez l'ordinateur." $m11_FR = "Erreur" $m12_FR = "Aucun nom d'imprimante et/ou IP n'a été saisi." & @LF & "Saisissez un nom et/ou IP et cliquez sur ""Installer""" $m13_FR = "Nom :" $m14_FR = "Emplacement :" $m15_FR = "Ip :" ;EN $m0_US = "------ Zebra's Installation ------" $m1_US = "Update Informations in progress..." $m2_US = "&File" $m3_US = "Installing" $m4_US = "Exit" $m5_US = "Printer" $m6_US = "Printer to install" $m7_US = "Driver to use" $m8_US = "Reset" $m9_US = "Finished installation" $m10_US = "Thank you for restart the computer." $m11_US = "Error" $m12_US = "No name of printer and/or IP was seized." & @LF & "Seize a name and/or IP and click on ""Installing""" $m13_US = "Name :" $m14_US = "Location :" $m15_US = "Ip :" ;~ Select ;~ Case _Language() = "French" ;~ $m0 = $m0_FR ;~ $m1 = $m1_FR ;~ $m2 = $m2_FR ;~ $m3 = $m3_FR ;~ $m4 = $m4_FR ;~ $m5 = $m5_FR ;~ $m6 = $m6_FR ;~ $m7 = $m7_FR ;~ $m8 = $m8_FR ;~ $m9 = $m9_FR ;~ $m10 = $m10_FR ;~ $m11 = $m11_FR ;~ $m12 = $m12_FR ;~ $m13 = $m13_FR ;~ $m14 = $m14_FR ;~ $m15 = $m15_FR ;~ Case _Language() = "English" $m0 = $m0_US $m1 = $m1_US $m2 = $m2_US $m3 = $m3_US $m4 = $m4_US $m5 = $m5_US $m6 = $m6_US $m7 = $m7_US $m8 = $m8_US $m9 = $m9_US $m10 = $m10_US $m11 = $m11_US $m12 = $m12_US $m13 = $m13_US $m14 = $m14_US $m15 = $m15_US ;~ EndSelect #endregion #region FIRST GUI FileDelete($file_sqlite) $recup_info = GUICreate($m0, 286, 99, -1, -1, $WS_POPUPWINDOW) $label1_recup_info=GUICtrlCreateLabel($m0, 0, 16, 286, 17, $SS_CENTER) GUICtrlSetFont(-1, 9, 800) $label3_recup_info=GUICtrlCreateLabel($m1, 0, 56, 286, 17,$SS_CENTER) GUISetState(@SW_SHOW,$recup_info) sqlite_combo() Sleep(1000) #endregion #region GUI $Form = GUICreate($m0, 400, 250, -1, -1,$WS_POPUPWINDOW) GUISetBkColor($blue) ;~ GUICtrlCreatePic($logo, 125, 205, 0, 0) $filemenu=GUICtrlCreateMenu ($m2) $installitem=GUICtrlCreateMenuitem ($m3,$filemenu) $resetitem=GUICtrlCreateMenuItem($m8,$filemenu) $exititem=GUICtrlCreateMenuitem ($m4,$filemenu) ;Printer $Group1 = GUICtrlCreateGroup($m6, 8, 8, 385, 90) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $printer_label=GUICtrlCreateLabel($m13, 30, 32, 70, 20,$SS_RIGHT) $printer=GUICtrlCreateCombo("", 105, 30, 200, 20) GUICtrlSetData(-1,$comboFirst&'|'&$comboList) $ip_label=GUICtrlCreateLabel($m15, 30, 52, 70, 20,$SS_RIGHT) $ip=GUICtrlCreateInput("", 105, 50, 200, 20,$ES_READONLY) $location_label=GUICtrlCreateLabel($m14, 30, 72, 70, 20,$SS_RIGHT) $location=GUICtrlCreateInput("", 105, 70, 200, 20,$ES_READONLY) GUICtrlCreateGroup("", -99, -99, 1, 1) ;Driver $Group1 = GUICtrlCreateGroup($m7, 8, 108, 385, 50) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $driver=GUICtrlCreateCombo('',105,125,200,15) GUICtrlSetData(-1,'PCL5|PCL6|PS') GUICtrlCreateGroup("", -99, -99, 1, 1) ;Button $installbutton = GUICtrlCreateButton($m3, 65, 175, 87, 20) $resetbutton = GUICtrlCreateButton($m8, 155, 175, 87, 20) $exitbutton=GUICtrlCreateButton($m4, 245, 175, 87, 20) GUIDelete($recup_info) GUISetState(@SW_SHOW,$Form) #endregion #region SCRIPT While 1 $listener=GUIGetMsg() Select ;INSTALLING Case $listener=$installitem Or $listener=$installbutton $printer_name=GUICtrlRead($printer) $printer_ip=GUICtrlRead($ip) $driver_name=GUICtrlRead($driver) $location_name=GUICtrlRead($location) Select Case $printer_name='' MsgBox(16, $m11, $m12, 5) Case $printer_ip='' MsgBox(16, $m11, $m12, 5) Case $driver_name='' MsgBox(16, $m11, $m12, 5) Case Else GUISetState(@SW_HIDE,$Form) $gui_install=GuiCreate("", 300, 100, -1, -1, $WS_POPUPWINDOW) $label1=GUICtrlCreateLabel("-- "&StringTrimRight(StringUpper(@ScriptName),4)&" --", 0, 10, 300, 20, $SS_CENTER) GUICtrlSetFont(-1, 9, 800) $label2=GUICtrlCreateLabel("Vérification en cours...", 0, 40, 300, 20,$SS_CENTER) $label3=GUICtrlCreateLabel("", 0, 60, 300, 20,$SS_CENTER) GUICtrlSetFont(-1, 9, 800) GUISetState(@SW_SHOW,$gui_install) ;Port ;~ GUICtrlSetData($label2,"Installation Ports en cours...") ;~ GUICtrlSetData($label3,$printer_name) ;~ RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports','StatusUpdateEnabled','REG_DWORD','00000001') ;~ RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports','StatusUpdateInterval','REG_DWORD','0000000a') ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Hostname","REG_SZ","") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"HWAddress","REG_SZ","") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"IPAddress","REG_SZ",$printer_ip) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"PortNumber","REG_DWORD","9100") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Protocol","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Community","REG_SZ","public") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Enabled","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"SNMP Index","REG_DWORD","00000001") ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_"&$printer_ip,"Version","REG_DWORD","00000001") ;~ Sleep(2000) ;Printer GUICtrlSetData($label2,"Installation Imprimante en cours...") GUICtrlSetData($label3,$printer_name) ;~ _RunDOS('net stop "'&$sServiceName&'"') ;~ Sleep(4000) ;~ _RunDOS('net start "'&$sServiceName&'"') ;~ Select ;~ Case $driver_name='PCL5' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PCL5&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PCL 5""","",@SW_HIDE) ;~ Case $driver_name='PCL6' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PCL6&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PCL 6""","",@SW_HIDE) ;~ Case $driver_name='PS' ;~ RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /if /f "&$inf_PS&" /u /b """&$printer_name&""" /r ""IP_"&$printer_ip&""" /m ""HP Universal Printing PS""","",@SW_HIDE) ;~ EndSelect ;~ If $location_name<>'' Then ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name, "Location", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "Location", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name, "Description", "REG_SZ", $location_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "Description", "REG_SZ", $location_name) ;~ EndIf ;~ _RunDOS('net stop "'&$sServiceName&'"') ;~ Sleep(4000) ;~ _RunDOS('net start "'&$sServiceName&'"') ;~ ;Parameters ;~ GUICtrlSetData($label2,"Paramétrage Imprimante en cours...") ;~ GUICtrlSetData($label3,$printer_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "uNCName", "REG_SZ", "\\"&@ComputerName&"."&$regsuffix&"\"&$printer_name) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "serverName", "REG_SZ", @ComputerName&"."&$regsuffix) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "shortServerName", "REG_SZ", @ComputerName) ;~ RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\"&$printer_name&"\DsSpooler", "url", "REG_SZ", "http://"&@ComputerName&"."&$regsuffix&"/") ;~ Sleep(5000) GUIDelete($gui_install) GUISetState(@SW_SHOW,$Form) EndSelect ;RESET Case $listener=$resetitem Or $listener=$resetbutton GUICtrlSetData($printer,$blank) GUICtrlSetData($ip,$blank) GUICtrlSetData($driver,$blank) GUICtrlSetData($location,$blank) GUICtrlSetData($driver,'HP|Driver02|Driver03') sqlite_combo() GUICtrlSetData($printer,$comboList,$comboFirst) GUICtrlSetData($ip,$aRow[0]) GUICtrlSetData($location,$aRow[1]) ;EXIT Case $listener=$GUI_EVENT_CLOSE Or $listener=$exititem Or $listener=$exitbutton ;~ FileDelete($logo) FileDelete($file_sqlite) ExitLoop Case $listener=$printer lookup() GUICtrlSetData($ip,$aRow[0]) GUICtrlSetData($location,$aRow[1]) EndSelect WEnd #endregion #region FUNCTIONS Func endmsg() MsgBox(0, "Results", $m9&@CRLF&$m10,600) Exit EndFunc Func sqlite_combo() If Not FileExists ($file_sqlite) Then database() _SQLite_Startup() _SQLite_Open($file_sqlite) _SQLite_GetTable2d (-1,"SELECT * FROM printers;", $aResult, $iRows, $iColumns) Global $comboFirst = $aResult[1][1] Global $comboList= $aResult[2][1] For $i = 3 To UBound($aResult)-1 $comboList = $comboList & "|" & $aResult[$i][1] Next ;~ Global $sSearchTerm = $comboFirst ;~ Global $sSearchTerm = GUICtrlRead($printer) ;~ If $sSearchTerm <> "" Then ;~ _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) ;~ _SQLite_FetchData ( $hQuery, $aRow) ;~ EndIf _SQLite_Close($file_sqlite) _SQLite_Shutdown() ;~ MsgBox (4096, "Result for " & $sSearchTerm, "The IP address is: " & $aRow[0] &@CR& "The Location is: "& $aRow[1]) EndFunc Func lookup() $sSearchTerm=GUICtrlRead($printer) If Not FileExists ($file_sqlite) Then database() _SQLite_Startup() _SQLite_Open($file_sqlite) If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) EndIf _SQLite_Close($file_sqlite) _SQLite_Shutdown() EndFunc Func database() Dim $aRecords If Not _FileReadToArray($file,$aRecords) Then MsgBox(4096,"Error", " Error reading file to Array error:" & @error) Exit EndIf Local $hQuery,$aRow _SQLite_Startup() _SQLite_Open($file_sqlite) _SQLite_Exec(-1,"Create table printers (IP CHAR NOT NULL,CompNo CHAR, Loc CHAR); " ) For $x = 1 to $aRecords[0] Local $sRecord = "'" & $aRecords[$x] & "'" $sRecord = StringReplace ($sRecord, " ", "'") $sRecord = StringReplace ($sRecord, ",", "','") _SQLite_Exec(-1,"INSERT INTO printers (IP, CompNo, Loc) VALUES ("& $sRecord & ") ; " ) Next _SQLite_Close($file_sqlite) _SQLite_Shutdown() EndFunc ; ==>database #endregion I added : Case $listener=$printer lookup() GUICtrlSetData($ip,$aRow[0]) GUICtrlSetData($location,$aRow[1]) and : Func lookup() $sSearchTerm=GUICtrlRead($printer) If Not FileExists ($file_sqlite) Then database() _SQLite_Startup() _SQLite_Open($file_sqlite) If $sSearchTerm <> "" Then _SQLite_Query (-1,"SELECT IP, Loc FROM printers WHERE CompNo = " & "'" & $sSearchTerm & "';", $hQuery) ;", $aResult, $iRows, $iColumns) _SQLite_FetchData ( $hQuery, $aRow) EndIf _SQLite_Close($file_sqlite) _SQLite_Shutdown() EndFunc Just a little detail, how i can delete $file_sqlite (printers.sqlite) when i exit the script. I used this function but it doesn't works : Case $listener=$GUI_EVENT_CLOSE Or $listener=$exititem Or $listener=$exitbutton FileDelete($file_sqlite) ExitLoop Thanks "Master" Link to comment Share on other sites More sharing options...
saywell Posted March 1, 2011 Share Posted March 1, 2011 The same way as you do at the beginning should work. Where do you define $file_sqlite? It would need to be global rather than local, but it's not in your original full listing. FileDelete(@ScriptDir&'\Printers.sqlite') If it doesn't work, check that you've closed sqlite after every invocation of it. William 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