ARPFre Posted February 4, 2022 Share Posted February 4, 2022 Hello everyone, Sorry for any mistakes in English, as I'm using google translator. Please I would like some help. The source code is in the attachment, because I don't know how to insert it here in the text. For correct operation, you must remove the comment from Requires Administrator I'm making a script that works like inventory, including getting CDP and LDP data. But when looking for a monitor's serial number in a TXT file (in the temp folder), I can get it normally. What I need is: How to fetch specific part of TXT? Example: I would like to throw in a variable only the result that I had written in the Monitor Name: and Serial Number: lines. I tried 3 ways and failed: Primary idea: If AutoIT is unable to read specific words within the TXT (which would be ideal). or The TXT will always save the Monitor Name on line 15 - for example, but I don't want the whole line, but starting from the character ":" or Or line 15 from column 28. Could you please help me? TotalInventory.au3 Link to comment Share on other sites More sharing options...
mikell Posted February 4, 2022 Share Posted February 4, 2022 14 minutes ago, ARPFre said: How to fetch specific part of TXT? Could you provide an example of this .txt file ? Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 Yes, sorry! Data_Monitor.txt Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 @mikell Yes, Sorry! Data_Monitor.txt Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 (edited) Here one way : Local $aList, $sText, $sMon, $sSerial $sText = FileRead("Data_Monitor.txt") $aList = StringRegExp($sText, "(?mi)^Monitor Name\h*:\h*(.*)$", 1) If IsArray($aList) Then $sMon = $aList[0] $aList = StringRegExp($sText, "(?mi)^Serial Number\h*:\h*(.*)$", 1) If IsArray($aList) Then $sSerial = $aList[0] ConsoleWrite("Monitor Name = " & $sMon & @CRLF & "Serial Number = " & $sSerial & @CRLF) ps. in your txt file, there is 2 monitors. Is this 2 different examples, or do you want to get both at the same time ? My example code only gets the first, but it can be easily adapted to get both (or multiple). Edited February 4, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 @Nine - I want to get 02. Like me, many people in my work have 02 monitors. And a maximum of 03 monitors per Desktop is allowed. Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 (edited) Here something that shows multiple monitors : #include <Array.au3> #include <Constants.au3> Local $sText, $aMon, $aSerial $sText = FileRead("Data_Monitor.txt") $aMon = StringRegExp($sText, "(?mi)^Monitor Name\h*:\h*(.*)$", 3) If IsArray($aMon) Then _ArrayDisplay($aMon) Local $aSerial = StringRegExp($sText, "(?mi)^Serial Number\h*:\h*(.*)$", 3) If IsArray($aSerial) Then _ArrayDisplay($aSerial) If Not IsArray($aMon) Or Not IsArray($aSerial) Or UBound($aMon) <> UBound($aSerial) Then _ Exit MsgBox($MB_SYSTEMMODAL, "Error", "Missing informations") ConsoleWrite("You have " & UBound($aMon) & " monitors :" & @CRLF) For $i = 0 To UBound($aMon) - 1 ConsoleWrite("Monitor " & $i+1 & @CRLF & "Monitor Name = " & $aMon[$i] & @CRLF & "Serial Number = " & $aSerial[$i] & @CRLF & @CRLF) Next Edited February 4, 2022 by Nine added support of no found information “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 (edited) @Nine Yes, it was very good, the result is exactly what I expected. I'll read it slowly to learn how you did the coding. I'm just having a problem. As I'm in learning, I'm trying to remove ArrayDisplay, to get the results and throw in a GuiCreateLabel and I couldn't. For each monitor and serial number a GuiCreateLabel. Example: Monitor 01: Dell Serial: CKMASD2234 Monitor 02: HP Serial: OHASDFSD@ The result of the serial being a GuiCreateLabel to later be saved. (In Red) Edited February 4, 2022 by ARPFre Add pic Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 I looked at your code. You seem to recreate label at the same spot multiple times. You should not do that. Instead just assign your GUIcreateLabel to a variable. And then after, just use GUICtrlSetData to modify (or clear) the value of the label. Concerning you request, what do you want to achieve exactly ? Do you want all name/SN be displayed in a single label, or do you want to have a label for each monitor ? Try to put a small snippet of the code that would replace the ArrayDisplay, so you can learn along with it... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 @Nine Thanks for the "GUIcreateLabel and GUICtrlSetData" tip, I don't know these handlers, I'll look at Help. I believe it's easy. I want a label for each monitor. That is my objective. Without showing the (Display Array). Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 Try to put a loop like I did, and use GUICtrlSetData to assign new values to the labels. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 @Nine Will you help me one more time? In your code I still couldn't remove the Array window that appears, every time I modify the error code and the application does not open. Link to comment Share on other sites More sharing options...
Solution Nine Posted February 4, 2022 Solution Share Posted February 4, 2022 Alright, I will show you how you should post code correctly, see link. When you are asked to provide a snippet you can do something like this : #include <Constants.au3> .... ; Label creation for up to 3 monitors - adapt screen localization and size Local $aMonLabel[3] For $i = 0 to UBound($aMonLabel) - 1 $aMonLabel[$i] = GUICtrlCreateLabel("", 500, 200 + $i * 30, 100, 25) Next .... ; Read the name and serial from the txt file Local $sText, $aMon, $aSerial $sText = FileRead("Data_Monitor.txt") $aMon = StringRegExp($sText, "(?mi)^Monitor Name\h*:\h*(.*)$", 3) Local $aSerial = StringRegExp($sText, "(?mi)^Serial Number\h*:\h*(.*)$", 3) If Not IsArray($aMon) Or Not IsArray($aSerial) Or UBound($aMon) <> UBound($aSerial) Then _ Exit MsgBox($MB_SYSTEMMODAL, "Error", "Missing informations") ; assign retrieved values to labels For $i = 0 To UBound($aMon) - 1 GUICtrlSetData($aMonLabel[$i], "Monitor " & $i+1 & " : " & $aMon[$i] & " - Serial : " & $aSerial[$i]) Next untested of course... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted February 4, 2022 Share Posted February 4, 2022 Another flavour... $sText = FileRead("Data_Monitor.txt") $aMon = StringRegExp($sText, "(?:(?:Monitor Name|Serial Number)\h*:\h*(.*))+", 3) If IsArray($aMon) Then For $i = 0 to UBound($aMon)-1 step 2 Msgbox(0,"", $aMon[$i] & @crlf & $aMon[$i+1]) Next EndIf ARPFre 1 Link to comment Share on other sites More sharing options...
ARPFre Posted February 4, 2022 Author Share Posted February 4, 2022 @Nine I can't even thank you for the teachings. I'm learning a lot from your code. It is solving my doubts and serving as a learning experience. Thank you so much! Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 Glad I could help. Good luck for the future. ARPFre 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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