gr8BigGeek Posted November 27, 2010 Share Posted November 27, 2010 Hello great minds! I've been reading these posts and you guys are all so smart! I'm new to programming and so please don't make too much fun of me. I'm really struggling with this application I'm trying to write and I'm sure it will seem very easy to you guys. So, here it goes...I am having a problem with regular expressions (maybe this is even the incorrect way of going about it??). Either way, I Ctrl+A, then Ctrl+C so the clipboard is housing the information I need. It is taken from a mask I have to fill out; when I copy and paste the info (see attached) the format is always the same. This is because the mask only allows so many characters per textbox (like the VIN can only be 17 characters and the State can only be 2 characters, etc). What I'm trying to do is take what is already being stored in the clipboard and instead of just pasting all of the information into another txt document I need to extract certain bits of the data and send it in a different order. This is because all of these pieces of information need to populate another mask (that is virtually the same in every respect, only the fields are arranged differently so it can't be copied field for field in the same order). So my problem is how do I set up an array so I can send the text from the clipboard to populate this other mask? It would be like send ("{TAB}") insert/paste the lic, then send ("{TAB}") x2 and paste the VIN, then send ("{TAB}") and so on. Then I can simply stay on the window (to maintain focus) and let the autoit program run and auto-fill the whole mask (to save on time).I was trying to array the information and the parse it or use deliniators but then I was way in over my head. Plus I cannot get autoit to focus on the screen of the program that has the mask. This is because the information is on a tab contained within the main GUI not as easy as: WinWaitActive("Untitled - Notepad")The attached document simply has the following info (which I totally made up so sorry if this is someone's real car): LIC: 113ABJ ST: WA VIN: 1GHP3448PHFFB2378 COL: YEL YR: 98 Mak: Toyt Mod: Cor VS: 4DReport: 01-448993MISC: VEH WAS TOWED FROM HOSP PRKING LOT FOR BEING LEFT OVER-HRSThe mask to fill out is like this: COL:_______ YR:__ Mak:____ Mod:___ VS:__ VIN:__________________ ST:__ LIC:_______ Report:________________MISC:_______________________________________Any and/or all assistance you can provide in aiding me to complete this project would be awesome! Thank you so much in advance.Gr8_big_geek Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2010 Moderators Share Posted November 27, 2010 gr8BigGeek,No need for SREs - probably just as well as I am not a "great mind"! Just split the data and then rearrange it after some judicious trimming. You need the bit between the ############## lines - the rest of the code is for demonstration purposes only: expandcollapse popup#include <GUIConstantsEx.au3> ; Create a GUI to show it working Global $aInputs[10] $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("COL", 10, 10, 30, 20) GUICtrlCreateLabel("YR ", 120, 10, 30, 20) GUICtrlCreateLabel("Mak", 180, 10, 30, 20) GUICtrlCreateLabel("Mod", 250, 10, 30, 20) GUICtrlCreateLabel("VS", 320, 10, 30, 20) GUICtrlCreateLabel("VIN", 10, 40, 30, 20) GUICtrlCreateLabel("ST", 210, 40, 30, 20) GUICtrlCreateLabel("LIC", 270, 40, 30, 20) GUICtrlCreateLabel("Report", 10, 70, 50, 20) GUICtrlCreateLabel("MISC", 10, 100, 50, 20) $aInputs[0] = GUICtrlCreateInput("", 40, 10, 80, 20) $aInputs[1] = GUICtrlCreateInput("", 150, 10, 30, 20) $aInputs[2] = GUICtrlCreateInput("", 210, 10, 30, 20) $aInputs[3] = GUICtrlCreateInput("", 280, 10, 40, 20) $aInputs[4] = GUICtrlCreateInput("", 340, 10, 80, 20) $aInputs[5] = GUICtrlCreateInput("", 40, 40, 170, 20) $aInputs[6] = GUICtrlCreateInput("", 230, 40, 40, 20) $aInputs[7] = GUICtrlCreateInput("", 300, 40, 80, 20) $aInputs[8] = GUICtrlCreateInput("", 60, 70, 280, 20) $aInputs[9] = GUICtrlCreateInput("", 60, 100, 280, 20) GUISetState() ; ############################################################## ; Simulate getting the data - you would use ClipGet $sText = "LIC: 113ABJ ST: WA VIN: 1GHP3448PHFFB2378" & @CRLF & _ "COL: YEL YR: 98 Mak: Toyt Mod: Cor VS: 4D" & @CRLF & _ "Report: 01-448993" & @CRLF & _ "MISC: VEH WAS TOWED FROM HOSP PRKING LOT FOR BEING LEFT OVER-HRS" ; Remove any line returns $sText = StringReplace($sText, @CRLF, "") ; Split the data into sections $aData = StringSplit($sText, ":", 2) ; Create new array to hold data in correct order Global $aNewData[10] ; And fill it with the adjusted data taken from the original array $aNewData[0] = StringTrimLeft(StringTrimRight($aData[4], 3), 1) $aNewData[1] = StringTrimLeft(StringTrimRight($aData[5], 4), 1) $aNewData[2] = StringTrimLeft(StringTrimRight($aData[6], 4), 1) $aNewData[3] = StringTrimLeft(StringTrimRight($aData[7], 3), 1) $aNewData[4] = StringTrimLeft(StringTrimRight($aData[8], 6), 1) $aNewData[5] = StringTrimLeft(StringTrimRight($aData[3], 3), 1) $aNewData[6] = StringTrimLeft(StringTrimRight($aData[2], 4), 1) $aNewData[7] = StringTrimLeft(StringTrimRight($aData[1], 3), 1) $aNewData[8] = StringTrimLeft(StringTrimRight($aData[9], 4), 1) $aNewData[9] = StringTrimLeft($aData[10], 1) ; Now send the data to your new form - you will have to ensure that you have the first input focused For $i = 0 To 9 Send($aNewData[$i]) Sleep(250) ; This is for demo purposes - you could probably shorten or remove this delay Send("{TAB}") Sleep(250) ; This is for demo purposes - you could probably shorten or remove this delay Next ; ############################################################## While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndI hope this works as you wish. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Malkey Posted November 27, 2010 Share Posted November 27, 2010 (edited) With regular expression.#include <Array.au3> ; ############################################################## ;$sText = ClipGet() $sText = "LIC: 113ABJ ST: WA VIN: 1GHP3448PHFFB2378 " & _ "COL: YEL YR: 98 Mak: Toyt Mod: Cor VS: 4D " & _ "Report: 01-448993" & @CRLF & _ "MISC: VEH WAS TOWED FROM HOSP PRKING LOT FOR BEING LEFT OVER-HRS" $aNewData = StringRegExp(StringRegExpReplace($sText,"(\v)"," "), "(?:[^:]+: )([^:]* |$)", 3) _ArrayDisplay($aNewData) #cs For $i = 3 To 7 Send($aNewData[$i]) Send("{TAB}") Next For $i = 2 To 0 Step -1 Send($aNewData[$i]) Send("{TAB}") Next Send($aNewData[8]) Send("{TAB}") Send($aNewData[9]) #ce ; ############################################################## Edited November 27, 2010 by Malkey Link to comment Share on other sites More sharing options...
gr8BigGeek Posted November 27, 2010 Author Share Posted November 27, 2010 Malkey, Okay that was awesome! I took your code and it worked really well. At first, I was like, "whoa, OMG it's pulling my data from the clipboad!!!". I realized that the data is hard-programmed into the code which leads me to a question: at work each vehicle we tow from the parking lot will change; is there a way for the information to be taken straight from what I have holding in the "clipboard"? This way, in case I'm towing a brown pickup or a black limo it won't matter; the program will just grab whatever I have on the clipboard and paste it all into the correct destination fields..? I actually don't even need a(n autoit, or .au3) GUI to be populated with the information as there is already a mask/GUI'd program that I use (and/or have to enter the information into). I was hoping that if I simply left "focus" on the window that houses the company's mask they want filled out (along with the information already being stored on the clip board) the program could take the bits that are being saved in the clipboard and turn them into an array and place each of the correct bits of data to their respective fields (vin to vin, plate to plate, and the report number to whatever the matching field is to be called, etc). If that's not possible what I could do is have a document (.txt file) saved at a fixed location ("C:\Whatever\Help.txt") then when the program is executed take what is on the clipboard and override that Help.txt file by planting the new information from the clipboard into it. Then it could use: Global Const $datafile = "C:\Whatever\Help.txt" This way, I can pull the data using something like: Func Lookup($filename) Local $hdl = FileOpen($filename, 0) If $hdl = -1 Then Return(SetError(2, 0, '')) ; no such file Local $pos = FileGetSize($hdl) - $MaxLines * $LineSize - 20 then through a loop: For $i = UBound($data) - 1 To 0 Step -1 I can separate the different bits into array numbers; then, when I {TAB} to another location array (x, y or z) can be inserted into that respective field. I'm thinking out loud here. Honestly, I don't even know if that would help (or work) but maybe then I could break up the information into array's (which I am not very good with...yet). The program would be taking array's and plopping them into this window that has focus set on it (simply using {TAB} and then pasting whichever array). What are your thoughts? I also wanted to say thank you to Melba23 for responding to my post as well that was very helpful of you. I tried to use your code only I struggled with how to apply it (again, I'm a total beginner). I'm reading this stuff on these forms and trying to see how I can arrange them. I look forward to hearing more from you all; thanks in advance! Your geek, Matt~ Link to comment Share on other sites More sharing options...
SadBunny Posted November 27, 2010 Share Posted November 27, 2010 Malkey,is there a way for the information to be taken straight from what I have holding in the "clipboard"?As Melba's comment (in the code) states: ClipGet I actually don't even need a(n autoit, or .au3) GUI to be populated with the information as there is already a mask/GUI'd program that I use (and/or have to enter the information into). I was hoping that if I simply left "focus" on the window that houses the company's mask they want filled out (along with the information already being stored on the clip board) the program could take the bits that are being saved in the clipboard and turn them into an array and place each of the correct bits of data to their respective fields (vin to vin, plate to plate, and the report number to whatever the matching field is to be called, etc). You could use StringRegExp or _StringBetween to search for those bits of text and do with the results whatever you want... Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
gr8BigGeek Posted November 27, 2010 Author Share Posted November 27, 2010 Sorry in my last post I think I reversed the names of the posters! Didn't mean to offend anyone there. Also I was looking at the regular expression post made by: quote name='Malkey' timestamp='1290853745' post='851118' I was trying to simulate the mask when I copy it but it actually doesn't have ":"'s to separate the fields. I'm sorry about that. It actually just has "LIC" and then the license or "VIN" and a space then the vehicle identification number and so on. So, I would almost need to find "LIC", less white space and take everything to the right of "LIC" until the next white space is found and stop copying (then set that as array[1]); then, find VIN do the same thing (less all white space and copy everything to the right of it until white space and then stop) and then set that as array[2]. If it kept doing that I could have "target" fields to grab and then run the loop until every array is populated with the data (to the right of the target field names). Once all of these arrays have been filled and the focus was set on the target window I could press something like Ctrl+I and the program would start filling the GUI form out with the stored array amounts. Your regular expressions were very clever though. It took me a long time of looking at your code to figure it out; great job! With regular expression. #include <Array.au3> ; ############################################################## ;$sText = ClipGet() $sText = "LIC: 113ABJ ST: WA VIN: 1GHP3448PHFFB2378 " & _ "COL: YEL YR: 98 Mak: Toyt Mod: Cor VS: 4D " & _ "Report: 01-448993" & @CRLF & _ "MISC: VEH WAS TOWED FROM HOSP PRKING LOT FOR BEING LEFT OVER-HRS" $aNewData = StringRegExp(StringRegExpReplace($sText,"(\v)"," "), "(?:[^:]+: )([^:]* |$)", 3) _ArrayDisplay($aNewData) #cs For $i = 3 To 7 Send($aNewData[$i]) Send("{TAB}") Next For $i = 2 To 0 Step -1 Send($aNewData[$i]) Send("{TAB}") Next Send($aNewData[8]) Send("{TAB}") Send($aNewData[9]) #ce ; ############################################################## Link to comment Share on other sites More sharing options...
SadBunny Posted November 27, 2010 Share Posted November 27, 2010 (edited) How exactly is that line of input formatted? Is it actually one big line per car or are the newlines part of the string you pull from the clipboard? /edit: please past 1 unauthored copypaste of car information directly here (maybe change real info for fake info though ) Edited November 27, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
gr8BigGeek Posted November 27, 2010 Author Share Posted November 27, 2010 (edited) Hey Sad Bunny, Sweet avitar there; totally love it! the attached screen shot is an image of the actual mask we fill in the tow entry into. Then the additional entry I need to, or would like to auto-fill the info to is as follows: ORI OCA DOI TOT LOC LIC LIS LIY LIT VCO VYR VMA VMO VST VIN OFN MIS PND INV PHO Here's the rotten news; if I try to copy all (the attached) it does not work. It gives an error message. So, actually what I would need to do is set my cursor on the "LIC:" field (or that blue textbox) and then run the Autoit! program. The program would actually need to copy from that field, {TAB} then copy the "LST:", {TAB}, then copy the "LYR:", etc. Once everything has been tabbed and copied then stored it would be ready to auto fill the fields of the above mask. I don't mean to be, but I think I'm changing my game-plan mid-way here. I'm thinking of having it auto-tab and copy each field and populate an Autoit! GUI. Once that was done it could then be "standing by" for me to set the new focus onto the window that contains the above mask. Once I hit a key combination (Ctrl+T or what have you) then the program will auto populate the information from the Auto-it! GUI. Now....I have no idea how to do this. It's like the saying, "After all is said and done there's a lot more said than done." I feel like I'm dreaming all this up and I don't even know if it's possible but I'm certainly going to punch away at it until I can get it to work. Thanks again in advance, Matt post script - sorry, the mask format didn't stay very well here in this post, but the fields are the same and in the same order Edited November 27, 2010 by gr8BigGeek Link to comment Share on other sites More sharing options...
gr8BigGeek Posted November 28, 2010 Author Share Posted November 28, 2010 (edited) I'm not sure how popular this makes me (responding to my own last post) but I wanted to add the attached. It's a simple GUI that does nothing but set there. If you wanted to open it up; that is real close to what I need to populate. I was hoping to find a way to: - Select all where the cursor is currently setting. - Capture the data from that textbox and send it it array1 - Tab to next textbox - loop that about 24 times; capturing each textbox of information and sending it to separate arrays Next (see attached), open the attached "Tow Entry From.exe"; I was hoping to set my cursor in the first textbox then trigger the program to begin taking the stored arrays (x 24) that we looped from the other mask and delivering them to the newly focused window. So long as focus is set on the window the program continues to paste. example: Paste array18 in the textbox {TAB} Paste array1 in the textbox {TAB} Paste array16 in the textbox and so on until the second mask has been filled with all of the relevant information it was storing from the other mask. I've been googling and searching this form (along with the help files) but haven't been able to find a solid way to select all, copy to array then tab and continue doing that while not changing focus from the window that needs copying. Then I have the reverse problem spitting back out the arrays into a new mask (that I have to maintain focus on while it populates it). I'll keep working on it but any help would be just wonderful. Thank you so much everyone for everything you do and all the hard work you do in your coding and programming. Coming to this website is always so humbling for me. Thanks~Tow Entry Form.exe Edited November 28, 2010 by gr8BigGeek Link to comment Share on other sites More sharing options...
SadBunny Posted November 28, 2010 Share Posted November 28, 2010 (edited) Here's the rotten news; if I try to copy all (the attached) it does not work. It gives an error message. So, actually what I would need to do is set my cursor on the "LIC:" field (or that blue textbox) and then run the Autoit! program. The program would actually need to copy from that field, {TAB} then copy the "LST:", {TAB}, then copy the "LYR:", etc. It's not clear how you should do this... This might be the hardest part of tackling the situation. Can you copy the data in the fields manually in any way? If so than it's probably "automatable" (English?) in different ways, but if not then we would need more info on how that interface actually works. Judging from the screenshot it might be anything from a telnet session to a unix server to an embedded MSDOS run... The way that you would need to read that information depends heavily on what kind of system that is. I do wonder about your options to copy and/or read the data from the console-dos-telnet-whatever kind of screen. Are you sure there aren't log files or comman(dline tool)s or databases or whatever to read the data directly and that you NEED to go through that text-only-ish gui? Once everything has been tabbed and copied then stored it would be ready to auto fill the fields of the above mask. I don't mean to be, but I think I'm changing my game-plan mid-way here. I'm thinking of having it auto-tab and copy each field and populate an Autoit! GUI. Once that was done it could then be "standing by" for me to set the new focus onto the window that contains the above mask. Once I hit a key combination (Ctrl+T or what have you) then the program will auto populate the information from the Auto-it! GUI. (...) I'm not sure how popular this makes me (responding to my own last post) but I wanted to add the attached. It's a simple GUI that does nothing but set there. If you wanted to open it up; that is real close to what I need to populate. I was hoping to find a way to: - Select all where the cursor is currently setting. - Capture the data from that textbox and send it it array1 - Tab to next textbox - loop that about 24 times; capturing each textbox of information and sending it to separate arrays Next (see attached), open the attached "Tow Entry From.exe"; I was hoping to set my cursor in the first textbox then trigger the program to begin taking the stored arrays (x 24) that we looped from the other mask and delivering them to the newly focused window. So long as focus is set on the window the program continues to paste. Bumping your thread within 24 hours is considered pushy (bad thing ). But this is not bumping (bumping = saying "hey, no answer, doesn't anyone have any idea" so that post goes to top of newly changed list again), this is adding useful information, and that is a very good thing! Anyway, once you have that data read, the rest of what you want to do (send keypresses and/or strings to the windowsy Tow Entry Screen (your exe) is relatively elementary I guess. I wouldn't go activating the window and tabbing through it, that is slow, error-prone and it requires that the window is active and such. Instead, you can push to the controls in your Windowsy GUI directly. For instance run your exe again and try this script. Note that this also works if the Windowsy GUI is minimized and inactive! ; I found the names of the controls by using the AU3Info tool, it shows me the name of the actual gui control in your windowsy data entry screen ; ; "TextBox5" -> LOC ; "TextBox21" -> Upper misc ; "TextBox22" -> Lower misc ; ; i use three random input lines on your gui, but the other controls can be added by the same logic #include <Array.au3> ; We will pretend the data array only contains the location and the upper&lower misc line data. ; In your final situation the array would be bigger ofcourse, one array element for all pieces of data. Dim $arrayData[3] $arrayData[0] = "This is a location" $arrayData[1] = "This is the upper misc line" $arrayData[2] = "This is the lower misc line" Const $LOCATION_INDEX = 0 Const $MISC_UPPER_INDEX = 1 Const $MISC_LOWER_INDEX = 2 ; It would aid the readability of this script if you changed the name of the controls to something else than ; "TextBox5", "TextBox22" etc... Like MiscUpperEdit, LocEdit, etc. then the following lines could be more self-obvious: ControlSetText("Tow Entry Screen", "", "[NAME:TextBox5]", $arrayData[$LOCATION_INDEX]) ControlSetText("Tow Entry Screen", "", "[NAME:TextBox21]", $arrayData[$MISC_UPPER_INDEX]) ControlSetText("Tow Entry Screen", "", "[NAME:TextBox22]", $arrayData[$MISC_LOWER_INDEX]) /edit: removed the ConsoleWrite around the ControlSetText's from example code, that was only for testing my example. I hope this helps! Anyway, it's nice to have something to do since not long after my last post from yesterday, believe it or not, my girlfriend-for-8-years decided to break up with me. Not completely unexpected but still I'm not having the Weekend Of My Life Luckily I'm not the 'run to the bottle' kind... Never mind that though, shit happens, especially shit that needed to happen anyway. Edited November 28, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. 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