Jump to content

Recommended Posts

Posted

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:

#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.

Posted

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.

Posted

@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:

  Reveal hidden contents

 

Posted

@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:

  Reveal hidden contents

 

Posted
#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)

:)

Posted
  On 7/11/2019 at 7:13 AM, mikell said:

_ArrayAdd($arrResult, $strString, 0, ":")

Expand  

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

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 ;)

 

  On 7/10/2019 at 9:43 PM, 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. 😉

Expand  

@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.

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...