Jump to content

StringRegExp and ClipGet() help needed


Recommended Posts

26 minutes ago, USSSR said:

I got this working with the help of you. At the end there had to be one Sleep() inserted after copying the 7 digits from the program for AutoIT/ClipGet(). Otherwise it didn't work reliably.

Did you post the code that was “copying the 7 digits from the program for AutoIT/ClipGet()” ?

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

1 hour ago, USSSR said:

At the end there had to be one Sleep() inserted after copying the 7 digits from the program for AutoIT/ClipGet(). Otherwise it didn't work reliably.

I may be wrong, but I don't think the "unreliable behavior" is the result of a missing Sleep instruction.

Here is a test loop that fetches a value from the clipboard a 100 times :

; There must be a value in the clipboard, e.g. :
; valid   = A7341S7
; invalid = 00001BE
Local $sClipGetData
For $i = 1 To 100
    $sClipGetData = ClipGet() ;
    If Not StringRegExp($sClipGetData,"(?i)^[[:alnum:]]{5}s[[:alnum:]]$") Then
        ConsoleWrite (Stringformat("%03i", $i) & "-> ClipGet = " & $sClipGetData & "(" & Binary($sClipGetData) & ") ==> 0 (no match) " & @CRLF)
    Else
        ConsoleWrite (Stringformat("%03i", $i) & "-> ClipGet = " & $sClipGetData & "(" & Binary($sClipGetData) & ") ==> 1 (match) " & @CRLF)
    EndIf
Next

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

35 minutes ago, Musashi said:

I may be wrong, but I don't think the "unreliable behavior" is the result of a missing Sleep instruction.

I assumed he meant a Sleep after the code that puts characters into the clipboard.  I may be wrong as well, but I don’t think we’ve been shown how they get in the clipboard, maybe there is a race condition.

Code hard, but don’t hard code...

Link to comment
Share on other sites

You guys may be right. At the end there was something strange with copying the characters in to the clipboard and using that information with AutoIT. I tried many things as the program where the characters are copied from is also a bit unreliable and uses internet connection to give information from main server. I'm not 100 % sure what fixed the copying realiabilty issue but anyways it definitely was a Sleep function in some part of the code. At least I got it working in some level so I can test and develop the code more.

Link to comment
Share on other sites

  • 2 weeks later...

I'm getting back to this topic.. StringRegExp is very hard for me to learn as there are so many variations in the help file.

I'm struggling to make a simple If command, could someone help?

How to make a rule that if GetClip() contais wheter ?????** or ?????m? or ?????p? then... something. Where ? can be letters A-Z, a-z or 0-9. GetClip will always be 7 characters.

Local $sData = ClipGet()

If  StringRegExp($sData,"(?i)^[[:alnum:]]{5}p[[:alnum:]]$") or StringRegExp($sData,"(?i)^[[:alnum:]]{5}m[[:alnum:]]$") or StringRegExp($sData,"(?i)^[[:alnum:]]{5}[\*\*]$") Then

.....

 

Link to comment
Share on other sites

Other if rule with StringRegExp which I have no idea how to make it that if GetClip contains free text. For example this kind of sequence:

(10) - line 0   0,5 1       93,4    1   46,7    0000000001  THIS IS EXAMPLE     0,5 1   93,4    1   46,7    0   0           PP11        
(10) - line 0   0,2 1       93,4    1   18,68   0099101101  THIS IS EXAMPLE     0,2 1   93,4    1   18,68   0   0           TB1     
(10) - line 0   0,1 1       93,4    1   9,34    0000065001  THIS IS ONE EXAMPLE AND THEY MAY BE MORE TEXT IN HERE       0,1 1   93,4    1   9,34    0   0           p44     
(10) - line 0   0,3 1   0   93,4    1   28,02   0007069901  EAXMPLE 1       0,3 1   93,4    1   28,02   0   0           V41

Then how to make a rule that if that GetClip contains for example "070699" or "0000000001" or "This is example" Then.....

Local $sData = ClipGet()

If  StringRegExp($sData,"070699") or StringRegExp($sData,"0000000001") or StringRegExp($sData,"This is example") Then

.....

 

 

 

Link to comment
Share on other sites

1 hour ago, USSSR said:

GetClip() contais wheter ?????** or ?????m? or ?????p?

Local $a = ["A7341M7","a7341pX","2D187m9", "00001BE", "32671**"]
;  ?????** or ?????m? or ?????p?
For $s in $a
  ConsoleWrite ("With " & $s & "(" & Binary($s) & ") SRE returns " & StringRegExp($s,"(?i)^[[:alnum:]]{5}([MP][[:alnum:]]|\*\*)$") & @CRLF)
Next

As per your other rule, not sure what is the exact target, could you provide a real example of the content.

Edited by Nine
Link to comment
Share on other sites

16 hours ago, Nine said:
Local $a = ["A7341M7","a7341pX","2D187m9", "00001BE", "32671**"]
;  ?????** or ?????m? or ?????p?
For $s in $a
  ConsoleWrite ("With " & $s & "(" & Binary($s) & ") SRE returns " & StringRegExp($s,"(?i)^[[:alnum:]]{5}([MP][[:alnum:]]|\*\*)$") & @CRLF)
Next

As per your other rule, not sure what is the exact target, could you provide a real example of the content.

Thank you. I think this is just what I asked for. I have to test if it works. Sorry if I was a bit unclear. StringRegExp is really hard to understand 😅

How about that other question/post which I had? How to find some pre defined characters such as "070699" from a slight "larger" clipboard content?

Link to comment
Share on other sites

7 hours ago, USSSR said:

How to find some pre defined characters such as "070699" from a slight "larger" clipboard content?

If you have a hard time understanding SRE, maybe you should consider using StringInStr for the time being.  The function is perfect for finding just a series of characters and it will let you code your own scripts.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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