Kimpak Posted July 10, 2019 Share Posted July 10, 2019 Now that my mac address function is solved, this one still has me puzzled. This function is supposed to copy a block of text from a tab in sublime text. Example Customer Name* : NAME Customer Account Number* : 12345678910 Customer Phone Number* : 555-867-5309 Address* : 123 Fake Street City* : Townsville State* : NY Zip Code* : 12345 Then it will parse the relevant information and paste it into another program. I've isolated the function in its own program for testing. I feel like if I can get at least one variable to spit out the right text I can get the rest to work. Here is what I have for the code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Misc.au3> ; necessary for the SendEx function to avoid key sticking #include <String.au3> ; for string encryption #include <FileConstants.au3> ; for file handling #include <MsgBoxConstants.au3> #include <Constants.au3> HotKeySet("{`}", "RunAwayRunAway") ; abort HotKeySet("^8", "Entity") ; fill out with info from Service Request While 1 Sleep (10) WEnd Func RunAwayRunAway() ; Exit function MsgBox(262145, "ABORT", "Run away! Run away! Please restart") Sleep (200) Exit EndFunc Func Entity() ; copy Incident number and Service Request to file named untitled and have IP Control open before launching MsgBox(262145, "ACHTUNG!", "Have Service Request info in Untitled in Sublime Text 2 and IP Control in Chrome open before continuing") SplashTextOn("", " Press ` to ABORT", 400, 75, 250, 550, 48, "") WinActivate ("untitled") WinWaitActive ("untitled") _SendEx("^a") Sleep (100) _SendEx("^c") _SendEx("{end}") Sleep (100) $copied = ClipGet() $name = StringRegExp($copied, 'Customer Name\*\s*\:(.+?)$', 1) ; strip off the Customer Name : WinActivate("[CLASS:Notepad]") WinWaitActive("[CLASS:Notepad]") Sleep (200) Send($name) ; Customer name EndFunc Func _SendEx($ss, $warn = "") Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys are still down. Requires misc.au3 to be included in the script for the _IsPressed function. Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") If $warn <> "" And TimerDiff($iT) > 1000 Then ; MsgBox(262144, "Warning", $warn) EndIf Sleep(50) WEnd Send($ss) EndFunc;==>_SendEx Most of this was written by an excoworker and I'm trying to update it to do more functions. For context, I know very little about programming so any help would be appreciated. If this is just pure garbage, I apologize in advance. But if I can get this thing to work, it'll make my job a lot easier. Link to comment Share on other sites More sharing options...
Kimpak Posted July 10, 2019 Author Share Posted July 10, 2019 I should add, that the function will successfully open the sublime text window, copy the information, open the notepad, then it just outputs a 0 instead of the expected customer name. Link to comment Share on other sites More sharing options...
Danp2 Posted July 10, 2019 Share Posted July 10, 2019 A few items I can see -- StringRegExp will return an array when using 1 for the flag parameter You should look into using ControlSend instead of Send for better reliability Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 10, 2019 Share Posted July 10, 2019 @Kimpak As @Danp2 noticed, you are using the $STR_REGEXPARRAYMATCH parameter, which will exit at the first match the pattern does, so, you should use $STR_REGEXPARRAYGLOBALMATCH in order to extract all the information from the text in the Clipboard. Then, with a text like that, you should use a pattern like the following one: '(?s)Customer Name\*\h*:\h*(\N+).*?Customer Account Number\*\h*:\h*(\d+).*?Customer Phone Number\*\h*:\h*(\d{3}\-\d{3}\-\d{4}).*?Address\*\h*:\h*(\N+).*?City\*\h*:\h*(\N+).*?State\*\h*:\h*([A-Z]{2}).*?Zip Code\*\h*:\h*(\d+)' Sorry if I didn't split it to make it more readable, but it's just to let you see it. For the rest, take a look at Control* functions to see if you can use them instead of Send() Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Kimpak Posted July 10, 2019 Author Share Posted July 10, 2019 That didn't seem to work. It now returns a 1 though instead of the name. Link to comment Share on other sites More sharing options...
Danp2 Posted July 10, 2019 Share Posted July 10, 2019 @Kimpak Please be more specific. Where are you seeing a value of 1? Also, it seems that you are missing the concept of StringRegExp returning an array instead of a single found item. Suggest that you review the help file entry for this command, particularly the examples. Open then in Scite. Study them and run them. 😉 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 11, 2019 Share Posted July 11, 2019 @Kimpak This sample should clarify your doubts: #include <Array.au3> #include <StringConstants.au3> Global $strString = "Customer Name* : NAME" & @CRLF & _ "Customer Account Number* : 12345678910" & @CRLF & _ "Customer Phone Number* : 555-867-5309" & @CRLF & _ "Address* : 123 Fake Street" & @CRLF & _ "City* : Townsville" & @CRLF & _ "State* : NY" & @CRLF & _ "Zip Code* : 12345", _ $arrResult $arrResult = StringRegExp($strString, '(?s)Customer Name\*\h*:\h*(\N+).*?' & @CRLF & _ 'Customer Account Number\*\h*:\h*(\d+).*?' & @CRLF & _ 'Customer Phone Number\*\h*:\h*(\d{3}\-\d{3}\-\d{4}).*?' & @CRLF & _ 'Address\*\h*:\h*(\N+).*?' & @CRLF & _ 'City\*\h*:\h*(\N+).*?' & @CRLF & _ 'State\*\h*:\h*([A-Z]{2}).*?' & @CRLF & _ 'Zip Code\*\h*:\h*(\d+)', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then _ArrayDisplay($arrResult) Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted July 11, 2019 Share Posted July 11, 2019 #include <Array.au3> Global $arrResult[0][2], $strString = "Customer Name* : NAME" & @CRLF & _ "Customer Account Number* : 12345678910" & @CRLF & _ "Customer Phone Number* : 555-867-5309" & @CRLF & _ "Address* : 123 Fake Street" & @CRLF & _ "City* : Townsville" & @CRLF & _ "State* : NY" & @CRLF & _ "Zip Code* : 12345" _ArrayAdd($arrResult, $strString, 0, ":") _ArrayDisplay($arrResult) mLipok, Jfish and Danp2 2 1 Link to comment Share on other sites More sharing options...
mLipok Posted July 11, 2019 Share Posted July 11, 2019 1 hour ago, mikell said: _ArrayAdd($arrResult, $strString, 0, ":") Every day a man learns something new. Thanks Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Kimpak Posted July 11, 2019 Author Share Posted July 11, 2019 Thank you everyone for trying to help. I think I'm just going to have to give up on this particular piece of my program as I think this is involving programming concepts that are just way over my head. I'll stick to my networking world 14 hours ago, Danp2 said: @Kimpak Please be more specific. Where are you seeing a value of 1? Also, it seems that you are missing the concept of StringRegExp returning an array instead of a single found item. Suggest that you review the help file entry for this command, particularly the examples. Open then in Scite. Study them and run them. 😉 @Danp2 You are correct, I don't really know what that means exactly. To be specific, I have a particular work task that involves copying a block of data similar to my example, then I manualy put that information into a webform to create a customer entity in an IP management tool. Its tedious. Ultimately, I was going to try and use autoit to take the raw information in my sublimetext pad, parse the information then paste the relevant bit into the webform so I don't have to manually do it. So it'd find the Customer's name, paste into the form, tab to the address line, paste the address, tab to the city, paste etc.... I've read the help for StringRegExp and to me it kind of looks like a bunch of archaic runes. So I'll have to keep working on some more basic programming concepts and work my way up. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 11, 2019 Share Posted July 11, 2019 @Kimpak You have more than one sample that does exactly what you were looking for: extract values from that string to paste them somewhere else. You need to do just the part where you want to paste them, and you have the job done. Isn't it worth it? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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