Jump to content

Logic help


Recommended Posts

Hello guys :) 

Actually doing a little tool for myself. 

Tool Goal :

-Read some text (_ClipGetClip)

-Check if some words are inside my text (_CheckTest,_CheckTest2)

-Do my stuff when my statement is verified. 

 

My script work fine. 

Just I cant figure out how to do exactly the same thing even if I add multiple words in my functions (_CheckTest,_CheckTest2)

 

Could you help me please ? :) 

HotKeySet ( "{F2}" , "_ReadString")
HotKeySet ( "{F3}" , "_Exit")

Global $Ticket , $MotClef1 , $MotClef2 , $MotClef3

While 1
   Sleep(100)
WEnd

Func _ReadString ()
   $Ticket = _ClipGetClip ()
   MsgBox(0,"ClipGetClip...",""&$Ticket);DEBUG
   $CheckTest = _CheckTest ()
   $CheckTest2 = _CheckTest2 ("Bouteille",)
   If $CheckTest = 1 Then Send ("OK")
   If $CheckTest2 = 1 Then Send ("OK2")
EndFunc

;J'aime les Bouteille

Func _CheckTest  ( $MotClef1="" , $MotClef2="" , $MotClef3="",$MotClef4="" , $MotClef5="" )
   $StringChecking = StringInStr ( $Ticket , $MotClef1 )
   If $StringChecking > 1 Then $MotClef1 = 1
   If $MotClef1 = 1 And $MotClef2 = "" Then
      Return 1
   Else
      Return 0
   EndIf
EndFunc

Func _CheckTest2 ( $MotClef1="" , $MotClef2="" , $MotClef3="", $MotClef4="" , $MotClef5="" )
   $StringChecking = StringInStr ( $Ticket , $MotClef1 )
   If $StringChecking > 1 Then $MotClef1 = 1
   If $MotClef1 = 1 And $MotClef2 = "" Then
      Return 1
   Else
      Return 0
   EndIf
EndFunc

Func _ClipGetClip ()
   $OldClip = ClipGet () ;On Prend ce qu'il y a dans le ClipBoard pour ne pas perdre le clip en cours.
   Sleep(10)
   Send("^c")
   $NewClip = ClipGet () ;On remplace le clip en cours par le contenu du ticket selectionné
   Return $NewClip ; On renvoi la valeur du ticket dans la function
   ClipPut ($OldClip) ;On remet le ClipBoard dans son etat initial.
EndFunc

Func _Exit ()
   MsgBox(0,"Arret...","Extinction")
   Exit
EndFunc

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I dont want to do array on this code. 

 

I know how to play with array but i want to dodge array in this code. Unless you say me i cannot do without an array 😛 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I did that actually but I would like to not pass the "_CheckTest2"

Becose i got 1/2 words. I have to change my If statement. How...? 

HotKeySet ( "{F2}" , "_ReadString")
HotKeySet ( "{F3}" , "_Exit")

Global $Ticket , $MotClef1 , $MotClef2 , $MotClef3

While 1
   Sleep(100)
WEnd

; Test Field:
; The word Bouteilles is here
; But the word Tourtle is not here.

Func _ReadString ()
   $Ticket = _ClipGetClip ()

   $CheckTest = _CheckTest ("Bouteilles")
      If $CheckTest = 1 Then ConsoleWrite ("Bouteilles is here"&@CRLF)

   $CheckTest2 = _CheckTest2 ("Frigot" , "But" )
      If $CheckTest2 = 1 Then ConsoleWrite ("Turtle & But are here"&@CRLF)
EndFunc ;===> _ReadString ()

Func _CheckTest  ( $MotClef1="" , $MotClef2="" , $MotClef3="" , $MotClef4="" , $MotClef5="" )
   $MotClef1 = _StringInString ( $Ticket , $MotClef1 )
   $MotClef2 = _StringInString ( $Ticket , $MotClef2 )
   $MotClef3 = _StringInString ( $Ticket , $MotClef3 )
   $MotClef4 = _StringInString ( $Ticket , $MotClef4 )
   $MotClef5 = _StringInString ( $Ticket , $MotClef5 )

   If $MotClef1 = "" _
    And $MotClef2 = "" _
    And $MotClef3 = "" _
    And $MotClef4 = "" _
    And $MotClef5 = "" Then
      Return 0
   Else
      Return 1
   EndIf
EndFunc ;===> _CheckTest  ()

Func _CheckTest2 ( $MotClef1="" , $MotClef2="" , $MotClef3="", $MotClef4="" , $MotClef5="" )
   $MotPresent1 = _StringInString ( $Ticket , $MotClef1 )
   $MotPresent2 = _StringInString ( $Ticket , $MotClef2 )
   $MotPresent3 = _StringInString ( $Ticket , $MotClef3 )
   $MotPresent4 = _StringInString ( $Ticket , $MotClef4 )
   $MotPresent5 = _StringInString ( $Ticket , $MotClef5 )

   If $MotPresent1 = "" _
    And $MotPresent2 = "" _
    And $MotPresent3 = "" _
    And $MotPresent4 = "" _
    And $MotPresent5 = "" Then
      Return 0
   Else
      Return 1
   EndIf
EndFunc ;===> _CheckTest2

Func _StringInString ($Ticket , $MotClef )
   $StringChecking = StringInStr ( $Ticket , $MotClef )
   If $StringChecking > 1 Then
      $MotClef = 1
   Else
      $MotClef = ""
   EndIf
   Return $MotClef
EndFunc ;===> _StringInString

Func _ClipGetClip ()
   $OldClip = ClipGet ()
   Sleep(10)
   Send("^c")
   $NewClip = ClipGet ()
   Return $NewClip
   ClipPut ($OldClip)
EndFunc ;===> _ClipGetClip ()

Func _Exit ()
   MsgBox(0,"Arret...","Extinction")
   Exit
EndFunc ;===> _Exit ()

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I am done with it so i share. :) 

Anyway if you got a more simple way to do the exact same thing I take ;) 

HotKeySet ( "{F2}" , "_ReadString")
HotKeySet ( "{F3}" , "_Exit")

Global $Ticket , $MotClef1 , $MotClef2 , $MotClef3 , $MotClef4 , $MotClef5 , $MotPresent1=0 , $MotPresent2=0 , $MotPresent3=0 , $MotPresent4=0 , $MotPresent5=0

While 1
   Sleep(100)
WEnd

; Test Field:
; The word Bouteilles is here
; But the word Tourtle is not here.

Func _ReadString ()
   $Ticket = _ClipGetClip ()

   $CheckTest = _CheckTest ("Bouteilles")
      If $CheckTest  = 1 Then ConsoleWrite ("Check 1 OK"&@CRLF)

   $CheckTest2 = _CheckTest2 ("Bouteilles" , "Boutt" )
      If $CheckTest2 = 1 Then ConsoleWrite ("Check 2 OK"&@CRLF)
EndFunc ;===> _ReadString ()

Func _CheckTest  ( $MotClef1="0" , $MotClef2="0" , $MotClef3="0" , $MotClef4="0" , $MotClef5="0" )
   If $MotClef1="0" Then
   Else
   $MotClef1 = _StringInString ( $Ticket , $MotClef1 )
   EndIf
   If $MotClef2="0" Then
   Else
   $MotClef2 = _StringInString ( $Ticket , $MotClef2 )
   EndIf
   If $MotClef3="0" Then
   Else
   $MotClef3 = _StringInString ( $Ticket , $MotClef3 )
   EndIf
   If $MotClef4="0" Then
   Else
   $MotClef4 = _StringInString ( $Ticket , $MotClef4 )
   EndIf
   If $MotClef5="0" Then
   Else
   $MotClef5 = _StringInString ( $Ticket , $MotClef5 )
   EndIf
   MsgBox(0,"_CheckTest2", $MotClef1 &" || "&$MotClef2&" || "&$MotClef3&" || "&$MotClef4&" || "&$MotClef5);DEBUG
   If $MotClef1 = "" Then
      Return 0
   ElseIf $MotClef2 = "" Then
      Return 0
   ElseIf $MotClef3 = "" Then
      Return 0
   ElseIf $MotClef4 = "" Then
      Return 0
   ElseIf $MotClef5 = "" Then
      Return 0
   Else
      Return 1
   EndIf
   $MotPresent1=0
   $MotPresent2=0
   $MotPresent3=0
   $MotPresent4=0
   $MotPresent5=0
   $MotClef1=0
   $MotClef2=0
   $MotClef3=0
   $MotClef4=0
   $MotClef5=0
EndFunc ;===> _CheckTest  ()

Func _CheckTest2 ( $MotClef1="0" , $MotClef2="0" , $MotClef3="0", $MotClef4="0" , $MotClef5="0" )
   If $MotClef1="0" Then
   Else
   $MotClef1 = _StringInString ( $Ticket , $MotClef1 )
   EndIf
   If $MotClef2="0" Then
   Else
   $MotClef2 = _StringInString ( $Ticket , $MotClef2 )
   EndIf
   If $MotClef3="0" Then
   Else
   $MotClef3 = _StringInString ( $Ticket , $MotClef3 )
   EndIf
   If $MotClef4="0" Then
   Else
   $MotClef4 = _StringInString ( $Ticket , $MotClef4 )
   EndIf
   If $MotClef5="0" Then
   Else
   $MotClef5 = _StringInString ( $Ticket , $MotClef5 )
   EndIf
   MsgBox(0,"_CheckTest2", $MotClef1 &" || "&$MotClef2&" || "&$MotClef3&" || "&$MotClef4&" || "&$MotClef5);DEBUG
   If $MotClef1 = "" Then
      Return 0
   ElseIf $MotClef2 = "" Then
      Return 0
   ElseIf $MotClef3 = "" Then
      Return 0
   ElseIf $MotClef4 = "" Then
      Return 0
   ElseIf $MotClef5 = "" Then
      Return 0
   Else
      Return 1
   EndIf
   $MotPresent1=0
   $MotPresent2=0
   $MotPresent3=0
   $MotPresent4=0
   $MotPresent5=0
   $MotClef1=0
   $MotClef2=0
   $MotClef3=0
   $MotClef4=0
   $MotClef5=0
EndFunc ;===> _CheckTest2

Func _StringInString ($Ticket , $MotClef )
   $StringChecking = StringInStr ( $Ticket , $MotClef )
   If $StringChecking > 1 Then
      $MotClef = 1
   Else
      $MotClef = ""
   EndIf
   Return $MotClef
EndFunc ;===> _StringInString

Func _ClipGetClip ()
   $OldClip = ClipGet ()
   Sleep(10)
   Send("^c")
   $NewClip = ClipGet ()
   Return $NewClip
   ClipPut ($OldClip)
EndFunc ;===> _ClipGetClip ()

Func _Exit ()
   MsgBox(0,"Arret...","Extinction")
   Exit
EndFunc ;===> _Exit ()

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

You can cut 90% of your code by just using an array and _ArraySearch, it is much easier and faster than what you have come up with.
Also you are not using any loops.  Most of what you are doing can be cut back to one function by using a FOR Loop and an array.

You may also want to look into using a text file or a .ini file and load that in as the program runs, this way you can change and add to the filter list without having to recompile the program.

The use of Global variables and then passing them into the functions the way you are is redundant. You do not need to do that with Global variables you can just use them directly.

There is a Dim function that brings in Global variables OR creates them in local scope if they do not exist, but I have found this can cause weird results where the variables are created locally anyway so it is best just to use Global variables directly within your functions without importing or passing them.

Edited by iAmNewbe
Link to comment
Share on other sites

1 minute ago, iAmNewbe said:

You may also want to look into using a text file or a .ini file and load that in as the program runs, this way you can change and add to the filter list without having to recompile the program.

This will be my last change inside the code. Thanks for all theses advise. 

2 minutes ago, iAmNewbe said:

You can cut 90% of your code by just using an array and _ArraySearch, it is much easier and faster than what you have come up with.
Also you are not using any loops.  Most of what you are doing can be cut back to one function by using a FOR Loop and an array.

I know but i want to dodge array on this code. For some reason. 

2 minutes ago, iAmNewbe said:

The use of Global variables and then passing them into the functions the way you are is redundant. You do not need to do that with Global variables you can just use them directly.

I need to read the theory on this subject it s now third time people said me i dont get this. 

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Take a day and read through the manual, everything you are doing is explained with many examples in the Manual as well as the Loops and how to use them.
It will save you a lot of time trying out the code in the manual and studying it line by line to understand what and why it does what it does.  Also Youtube has many videos on Logic Design and programming basics.  You just have to adapt what is used in the videos you end up watching to the actual AutoIT Language because a for loop is written a little different in AutoIT than in PHP, C++, JavaScript or whatever language.  Globals work the same,  don't use Dim unless you are sure you may want a local variable but in that case just create a local variable.

Link to comment
Share on other sites

11 minutes ago, iAmNewbe said:

The use of Global variables and then passing them into the functions the way you are is redundant. You do not need to do that with Global variables you can just use them directly.

He's not passing the global variables into the functions, he's creating new local variables inside the function, they just confusingly have the same name. Once that function ends, anything inside those variables will disappear, and any other function that tries to access them will get the contents of the global variables, unless he creates new local variables in other functions the same way.

This is a great example of how not to use Global variables, and the confusion that can arise when you reuse the Global variable's name in a Local variable inside a function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

11 minutes ago, iAmNewbe said:

Most of what you are doing can be cut back to one function by using a FOR Loop and an array.

Can you show me this magic function just for fun ? If it is a shord function as you said shouldn't be long to do ? 

3 minutes ago, iAmNewbe said:

Take a day and read through the manual, everything you are doing is explained with many examples in the Manual as well as the Loops and how to use them.
It will save you a lot of time trying out the code in the manual and studying it line by line to understand what and why it does what it does.  Also Youtube has many videos on Logic Design and programming basics.  You just have to adapt what is used in the videos you end up watching to the actual AutoIT Language because a for loop is written a little different in AutoIT than in PHP, C++, JavaScript or whatever language.  Globals work the same,  don't use Dim unless you are sure you may want a local variable but in that case just create a local variable.

Man i thought you understood before. 

I know how to use Array.au3

I know how to use For...Next loops./ 

 

I want to dodge these macro inside THIS ONE SCRIPT only in this one. 

You got it ? :) 

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

14 hours ago, caramen said:

Can you show me this magic function just for fun ? If it is a shord function as you said shouldn't be long to do ? 

 

Here is an Example

 

Func _CheckTest($stringToCheck, $exclusionList)
    If (IsArray($exclusionList) = False) Then Return False
    Local $aFound[0]
    For $item In $exclusionList
        $result = StringInStr($stringToCheck, $item, 0)
        If($result <> "") Then _ArrayAdd($aFound, $item)
    Next
    Return $aFound
EndFunc

 

Function used 

 

#include <String.au3>
#include <Array.au3>

Local $aMotClef[10] = ["Bouteilles","Boutt","Apple","Dino","Car","Spam","Girl","Scarf","Bicycle","Gaff"]
Local $string = "The girl rode her bicycle carrying bouteilles of fermented grape juice for her dinosaur"

$aResult = _CheckTest($string, $aMotClef)

If UBound($aResult) > 0 Then
    _ArrayDisplay($aResult) ; Array of found words
Else
    MsgBox(0,"","Nothing Found")
EndIf

Func _CheckTest($stringToCheck, $exclusionList)
    If (IsArray($exclusionList) = False) Then Return False
    Local $aFound[0]
    For $item In $exclusionList
        $result = StringInStr($stringToCheck, $item, 0)
        If($result <> "") Then _ArrayAdd($aFound, $item)
    Next
    Return $aFound
EndFunc

Func _Exit()
    Exit 0
EndFunc


Alternate Version
 

#include <String.au3>
#include <Array.au3>

Local $aMotClef[10] = ["Bouteilles","Boutt","Apple","Dino","Car","Spam","Girl","Scarf","Bicycle","Gaff"]
Local $string = "The girl rode her bicycle carrying bouteilles of fermented grape juice for her dinosaur"

If _CheckTest($string, $aMotClef) Then
    MsgBox(0,"","Word(s) Found")
Else
    MsgBox(0,"","Nothing Found")
EndIf

Func _CheckTest($stringToCheck, $exclusionList)
    If (IsArray($exclusionList) = False AND $exclusionList <> "") Then Return StringInStr($stringToCheck, $exclusionList, 0)
    Local $aFound[0]
    For $item In $exclusionList
        $result = StringInStr($stringToCheck, $item, 0)
        If($result <> "") Then _ArrayAdd($aFound, $item)
    Next
    If (UBound($aFound) > 0) Then Return True
    Return False
EndFunc


 

You can output whatever you want I just returned an array of words found from the List Array sent to the function.  Instead of displaying the returned array you can return False or whatever to designate the string has words you don't want or edit them out of the string or whatever you want to do.

Saves a lot of code to do all the check in one function like this.  You do not have to use an array, you can also pass the words to check against individually but it is a waste in my opinion to not just do it all at once. I returned the found words in case you wanted to do something with them otherwise just check that the returned array is greater than 0 and you have your answer if a word you don't want is in the string you are checking.

If you want to know the exact words in the string that is there also in the first example.

The Alternate Version allows for an individual word to be checked against the string in addition to a list of words in an array. Outputs True if there is a match and False if there is not.

 

 

Edited by iAmNewbe
Link to comment
Share on other sites

Here is an altered version that is more what you want without using arrays

 

Func _CheckTest($stringToCheck, $exclusionString)
        $result = StringInStr($stringToCheck, $exclusionString, 0)
        If($result <> "") Then
            return True  ; The $exclusionString is in $stringToCheck
        Else
        Return False ; A Okay, $exclusionString not in $stringtoCheck
        EndIf
EndFunc


Function used
 

#include <String.au3>

Local $string = "The girl rode her bicycle carrying bouteilles of fermented grape juice for her dinosaur"

If _CheckTest($string, "Bouteilles") Then MsgBox(0,"",'"Bouteilles" exists in string' & @CRLF)
If _CheckTest($string, "Boutt") Then MsgBox(0,"",'"Boutt" exists in string' & @CRLF)
If _CheckTest($string, "Apple") Then MsgBox(0,"",'"Apple" exists in string' & @CRLF)
If _CheckTest($string, "Dino") Then MsgBox(0,"",'"Dino" exists in string' & @CRLF)
If _CheckTest($string, "Girl") Then MsgBox(0,"",'"Girl" exists in string' & @CRLF)
If _CheckTest($string, "Bicycle") Then MsgBox(0,"",'"Bicycle" exists in string' & @CRLF)
If _CheckTest($string, "Gaff") Then MsgBox(0,"",'"Gaff" exists in string' & @CRLF)

Func _CheckTest($stringToCheck, $exclusionString)
        $result = StringInStr($stringToCheck, $exclusionString, 0)
        If($result <> "") Then
            return True  ; The $exclusionString is in $stringToCheck
        Else
        Return False ; A Okay, $exclusionString not in $stringtoCheck
        EndIf
EndFunc


 

Edited by iAmNewbe
Link to comment
Share on other sites

Ahhh ok. 

Look i am gonna explain you why you dont get it. 

 

The purpose is... 

 

I want to read some text and if there is 1 or 5 or more keywords inside it.  Open One doc or do an action (web vrowsing, docx openning, ...etc...)

 

So your code is good yeah but with multiple keyword we have to add more and more function ;) Becose you're only checking one keyword actually.

 

It's cool from you to tyake time, thanks bro :) 

You won one rep point 😜

Look this script it's close from final version i just have to add an ini to config keywords. Notice i have two action

-ToolTip with timer

-ConsoleWrite 

-1-2-3-4 or 5 Keywords max (i can add more later) (if needed)

Give a try to it you dont need an include.

HotKeySet ( "{F2}" , "_ReadString")
HotKeySet ( "{F3}" , "_Exit")

Global $Ticket , $MotClef1 , $MotClef2 , $MotClef3 , $MotClef4 , $MotClef5
Global $MotPresent1 = 0 , $MotPresent2 = 0 , $MotPresent3 = 0 , $MotPresent4 = 0 , $MotPresent5 = 0
Global $SuccessText = "" , $SuccessText2 = ""
Global $MyToolTip = 0 , $MyTimer = 0

While 1
   Sleep(100)
   If $MyToolTip = 0 Then
   Else
      $MyTimer += 100
      If $MyTimer > 5000 Then
         $MyTimer = 0
         Tooltip ("")
         $SuccessText2 = ""
      EndIf
   EndIf
WEnd

; Test Field:
; The word Bouteilles is here
; But the word Tourtle is not here.

Func _ReadString () ;Lit le texte compare les chaines de charactères puis agis
   $Ticket = _ClipGetClip ()

   $CheckTest = _CheckTest ("Bouteilles")
      If $CheckTest  = 1 Then
         $SuccessText = "Check 1 OK"&@CRLF&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      Else
         $SuccessText = "Check 1 NON OK"&@CRLF&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      EndIf

   $CheckTest2 = _CheckTest2 ("Bouteilles" , "Bertt" ,"word" , "test")
      If $CheckTest2 = 1 Then
         $SuccessText = "Check 2 OK"&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      Else
         $SuccessText = "Check 2 NON OK"&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      EndIf
EndFunc ;===> _ReadString ()

Func _CheckTest  ( $MotClef1="0" , $MotClef2="0" , $MotClef3="0" , $MotClef4="0" , $MotClef5="0" ) ;Test d'une fonction de comparaison de chaine de charactères avec un mot.
   If $MotClef1="0" Then
   Else
   $MotClef1 = _StringInString ( $Ticket , $MotClef1 )
   EndIf

   If $MotClef2="0" Then
   Else
   $MotClef2 = _StringInString ( $Ticket , $MotClef2 )
   EndIf

   If $MotClef3="0" Then
   Else
   $MotClef3 = _StringInString ( $Ticket , $MotClef3 )
   EndIf

   If $MotClef4="0" Then
   Else
   $MotClef4 = _StringInString ( $Ticket , $MotClef4 )
   EndIf

   If $MotClef5="0" Then
   Else
   $MotClef5 = _StringInString ( $Ticket , $MotClef5 )
   EndIf
   ;MsgBox(0,"_CheckTest2", $MotClef1 &" || "&$MotClef2&" || "&$MotClef3&" || "&$MotClef4&" || "&$MotClef5);DEBUG

   If $MotClef1 = "" Then
      Return 0
   ElseIf $MotClef2 = "" Then
      Return 0
   ElseIf $MotClef3 = "" Then
      Return 0
   ElseIf $MotClef4 = "" Then
      Return 0
   ElseIf $MotClef5 = "" Then
      Return 0
   Else
      Return 1
   EndIf

   $MotPresent1=0
   $MotPresent2=0
   $MotPresent3=0
   $MotPresent4=0
   $MotPresent5=0
   $MotClef1=0
   $MotClef2=0
   $MotClef3=0
   $MotClef4=0
   $MotClef5=0
EndFunc ;===> _CheckTest  ()

Func _CheckTest2 ( $MotClef1="0" , $MotClef2="0" , $MotClef3="0", $MotClef4="0" , $MotClef5="0" ) ;Test d'une fonction de comparaison de chaine de charactères avec plusieurs mots.
   If $MotClef1="0" Then
   Else
   $MotClef1 = _StringInString ( $Ticket , $MotClef1 )
   EndIf
   If $MotClef2="0" Then
   Else
   $MotClef2 = _StringInString ( $Ticket , $MotClef2 )
   EndIf
   If $MotClef3="0" Then
   Else
   $MotClef3 = _StringInString ( $Ticket , $MotClef3 )
   EndIf
   If $MotClef4="0" Then
   Else
   $MotClef4 = _StringInString ( $Ticket , $MotClef4 )
   EndIf
   If $MotClef5="0" Then
   Else
   $MotClef5 = _StringInString ( $Ticket , $MotClef5 )
   EndIf
   ;MsgBox(0,"_CheckTest2", $MotClef1 &" || "&$MotClef2&" || "&$MotClef3&" || "&$MotClef4&" || "&$MotClef5);DEBUG
   If $MotClef1 = "" Then
      Return 0
   ElseIf $MotClef2 = "" Then
      Return 0
   ElseIf $MotClef3 = "" Then
      Return 0
   ElseIf $MotClef4 = "" Then
      Return 0
   ElseIf $MotClef5 = "" Then
      Return 0
   Else
      Return 1
   EndIf
   $MotPresent1=0
   $MotPresent2=0
   $MotPresent3=0
   $MotPresent4=0
   $MotPresent5=0
   $MotClef1=0
   $MotClef2=0
   $MotClef3=0
   $MotClef4=0
   $MotClef5=0
EndFunc ;===> _CheckTest2

Func _StringInString ($Ticket , $MotClef ) ;Comparaison de la chaine au ticket
   $StringChecking = StringInStr ( $Ticket , $MotClef )
   $MotDeLaFin = $MotClef
   If $StringChecking > 1 Then
      $MotClef = 1;Est la
      $SuccessText2 = $SuccessText2&$MotDeLaFin&" est detecté!"&@CRLF
   Else
      $MotClef = "";N'est pas la
      $SuccessText2 = $SuccessText2&$MotDeLaFin&" n'est pas detecté!"&@CRLF
   EndIf

   Return $MotClef
EndFunc ;===> _StringInString

Func _Tooltip ($SuccessText)
   $MyToolTip = 1
   $SuccessText2 &= $SuccessText
   Global $MyToolTip = ToolTip ($SuccessText2,0,0 , "Checks results")
EndFunc

Func _ClipGetClip ();On integre la selection dans la mémoire
   $OldClip = ClipGet ();ClipGetp précédent
   Sleep(10)
   Send("^c")
   Sleep(10)
   $NewClip = ClipGet ();Integration selection
   Sleep(10)
   ClipPut ($OldClip);Restauration clip précédent
   Return $NewClip
EndFunc ;===> _ClipGetClip ()

Func _Exit ()
   MsgBox(0,"Arret...","Extinction...")
   Exit ;Quitter
EndFunc ;===> _Exit ()

 

I just have to figure out what you tryed t explain me about the global scope declaration but have no time anymore now.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

And with simplified function addition that give me this. 

 

It's pretty cool to get it working with 2 lines ;) 

$CheckTest2 = _CheckTest2 ("Bouteilles" , "Bertt" ,"word" , "test")
   _Simplificateur ($CheckTest2)
Func _ReadString () ;Lit le texte compare les chaines de charactères puis agis
   $Ticket = _ClipGetClip ()

   $CheckTest = _CheckTest ("Bouteilles")
   _Simplificateur ($CheckTest)
;~       If $CheckTest  = 1 Then
;~       $SuccessText = "Check 1 OK"&@CRLF&@CRLF
;~       _Tooltip ($SuccessText)
;~       ConsoleWrite ($SuccessText)
;~    Else
;~       $SuccessText = "Check 1 NON OK"&@CRLF&@CRLF
;~       _Tooltip ($SuccessText)
;~       ConsoleWrite ($SuccessText)
;~    EndIf

   $CheckTest2 = _CheckTest2 ("Bouteilles" , "Bertt" ,"word" , "test")
   _Simplificateur ($CheckTest2)

   $CheckTest3 = _CheckTest2 ("test" ,"word" , "test")
   _Simplificateur ($CheckTest3)
;~    If $CheckTest2 = 1 Then
;~       $SuccessText = "Check 2 OK"&@CRLF
;~       _Tooltip ($SuccessText)
;~       ConsoleWrite ($SuccessText)
;~    Else
;~       $SuccessText = "Check 2 NON OK"&@CRLF
;~       _Tooltip ($SuccessText)
;~       ConsoleWrite ($SuccessText)
;~    EndIf
EndFunc ;===> _ReadString ()

Func _Simplificateur ($CheckTest)
      If $CheckTest = 1 Then
         $SuccessText = "Check est OK"&@CRLF&"============"&@CRLF&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      Else
         $SuccessText = "Check est NON OK"&@CRLF&"============"&@CRLF&@CRLF
         _Tooltip ($SuccessText)
         ConsoleWrite ($SuccessText)
      EndIf
EndFunc

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@caramen
You could use arrays instead of using strings.

You want to check if your cliboard content has one of the strings you pass to the function that does the check; use an array in which you define all your strings, and loop through the array to see if in the clipboard content there is one of the strings.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@FrancescoDiMuro Read all xD 

Thx anyway

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

The issue is solved since post#5

 

And if you read all you will see that i dont want to use array here.

Was trying something./

 

To answer you i have no issue anymore. Thanks

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

5 hours ago, caramen said:

So your code is good yeah but with multiple keyword we have to add more and more function ;) Becose you're only checking one keyword actually.

If you look at the first example I wrote you will see it in fact checks ALL the keywords and returns either the keywords found or True if any of them exist.  Depending on what you want to do.  At that point you can check for True or False or the exact keyword list returned and then open whatever file you want.

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