AzgarD

Strings comparison error

13 posts in this topic

#1 ·  Posted

Hello guys. So, i'm trying to do simple comparison between two given strings, but the problem is that on of these string are given by the ClipGet() function, but the real problem is the place where i get this info, because every copy from there, every "CTRL+C, CTRL+V" puts an extra caracter on the end of every string, more like and "ENTER" in the end. Them i cant get a match using the "==" operator. I try to use the StringInStr function, but i always get the error "Subscript used on non-accessible variable", like you can see in the script. Anyway, i need to do a function to detet a match in this Strings. The error happens in the While in the "ApertaF4" function. Any help? Thanks guys.

 

Quote

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <StringConstants.au3>
Global $gui = GUICreate("Dados do Terminal 10MB", 220, 140)
Global $sigla = GUICtrlCreateInput("Sigla ", 10, 10, 80, 20)
Global $terminal = GUICtrlCreateInput("Terminal ", 10, 40, 120, 20)
Global $button = GUICtrlCreateButton("OK", 65, 100, 90, 20)
Dim $copia2 = ""

HotKeySet("{ESC}", "ExitProg")


 Func ExitProg()
    Exit
 EndFunc

Terminal()

Func Terminal()
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $button
            GUISetState(@SW_HIDE)
            RodarMacro()
    EndSelect
WEnd
EndFunc

Func RodarMacro()
   WinActivate("1 - STC (10.31.9.100)")
   WinSetState("1 - STC (10.31.9.100)","",@SW_MAXIMIZE)
      Send (GuiCtrlRead($sigla))
      Send ("{ENTER}")
      Send (GuiCtrlRead($terminal))
      Send ("{F4}")
      MouseMove(518, 378, 1)
      MouseClick($MOUSE_CLICK_LEFT)
      MouseClick($MOUSE_CLICK_LEFT)
      Send ("^c")
      $copia2 = ClipGet()
      ApertaF4 ($copia2)
EndFunc

Func ApertaF4($temp)
         While (StringInStr ( $temp, "Sigla" [, casesense = 2 [, occurrence = 1 [, start = 1 [, 5]]]] ) = True)Then
         Send ("{F4}")
         MouseMove(518, 378, 1)
         MouseClick($MOUSE_CLICK_LEFT)
         MouseClick($MOUSE_CLICK_LEFT)
         Send ("^c")
         $temp = ClipGet()
      WEnd
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Welcome to AutoIt and the forum!

Your usage of StringInStr is wrong. [ and ] denote optional parameters. Please try this:

While StringInStr($temp, "Sigla", 2, 1, 1, 5) = True Then

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

3 minutes ago, water said:

Welcome to AutoIt and the forum!

Your usage of StringInStr is wrong. [ and ] denote optional parameters. Please try this:

While StringInStr($temp, "Sigla", 2, 1, 1, 5) = True Then

 

Oh well, i'm very early steps of AutoIt. I think you managed to solve the problem, but now we have another one.

 

Capturar.JPG

Share this post


Link to post
Share on other sites

#4 ·  Posted

My bad. Should be

While StringInStr($temp, "Sigla", 2, 1, 1, 5) = True

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 

StringInStr ( "string", "substring" [, casesense = 0 [, occurrence = 1 [, start = 1 [, count]]]] )

, [...] represents the fields not mandatory entry, which means using the default values!

StringInStr ( "string", "substring")
StringInStr ( "string", "substring", 0, 1, 1)
StringInStr ( "string", "substring", 2, 1, 1, 5)

 

Keyword Reference

While...WEnd

While <expression>
statements
...
WEnd

If...Then...EndIf

If <expression> Then
statements
...
EndIf

 

Edited by VIP
StringInStr

Regards,
 

Share this post


Link to post
Share on other sites

#6 ·  Posted

4 minutes ago, VIP said:

 

StringInStr ( "string", "substring" [, casesense = 0 [, occurrence = 1 [, start = 1 [, count]]]] )

, [...] represents the fields not mandatory entry, which means using the default values!

StringInStr ( "string", "substring")

 

Keyword Reference

While...WEnd

While <expression>
statements
...
WEnd

If...Then...EndIf

If <expression> Then
statements
...
EndIf

 

AzgarD try this:

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <StringConstants.au3>
Global $gui = GUICreate("Dados do Terminal 10MB", 220, 140)
Global $sigla = GUICtrlCreateInput("Sigla ", 10, 10, 80, 20)
Global $terminal = GUICtrlCreateInput("Terminal ", 10, 40, 120, 20)
Global $button = GUICtrlCreateButton("OK", 65, 100, 90, 20)
Dim $copia2 = ""

HotKeySet("{ESC}", "ExitProg")


Func ExitProg()
    Exit
EndFunc   ;==>ExitProg

Terminal()

Func Terminal()
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $button
                GUISetState(@SW_HIDE)
                RodarMacro()
        EndSelect
    WEnd
EndFunc   ;==>Terminal

Func RodarMacro()
    WinActivate("1 - STC (10.31.9.100)")
    WinSetState("1 - STC (10.31.9.100)", "", @SW_MAXIMIZE)
    Send(GUICtrlRead($sigla))
    Send("{ENTER}")
    Send(GUICtrlRead($terminal))
    Send("{F4}")
    MouseMove(518, 378, 1)
    MouseClick($MOUSE_CLICK_LEFT)
    MouseClick($MOUSE_CLICK_LEFT)
    Send("^c")
    $copia2 = ClipGet()
    ApertaF4($copia2)
EndFunc   ;==>RodarMacro

Func ApertaF4($temp)
    If StringInStr($temp, "Sigla") Then
        Send("{F4}")
        MouseMove(518, 378, 1)
        MouseClick($MOUSE_CLICK_LEFT)
        MouseClick($MOUSE_CLICK_LEFT)
        Send("^c")
        $temp = ClipGet()
    EndIf
EndFunc   ;==>ApertaF4

 

Now the script goes smooth, but we have ther problem. But i need to Loop that condition until it turns False

Share this post


Link to post
Share on other sites

#7 ·  Posted

When you reply to a post please use the "Reply" not the "Quote" button. We know what we posted ;)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

Ok, sorry about that.

Share this post


Link to post
Share on other sites

#9 ·  Posted

I did a minor change in that function since i need a Loop. But still not loopping. Why is that?

 

Quote

Func ApertaF4()
        Send("{F4}")
        MouseMove(518, 378, 1)
        MouseClick($MOUSE_CLICK_LEFT)
        MouseClick($MOUSE_CLICK_LEFT)
        Send("^c")
        $copia = ClipGet()
    While StringInStr($copia, "Sigla") = True
        Send("{F4}")
        MouseMove(518, 378, 1)
        MouseClick($MOUSE_CLICK_LEFT)
        MouseClick($MOUSE_CLICK_LEFT)
        Send("^c")
        $copia = ClipGet()
   WEnd
EndFunc   ;==>ApertaF4

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

I think the StringInStr function isnt do what i need. So, the function inst finding a match.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Insert a MsgBox so you see what you compare

Func ApertaF4()
        Send("{F4}")
        MouseMove(518, 378, 1)
        MouseClick($MOUSE_CLICK_LEFT)
        MouseClick($MOUSE_CLICK_LEFT)
        Send("^c")
        $copia = ClipGet()
    MsgBox(0, "Value to compare", ">" & $copia & "<") ; Display what you get from the Clipboard
    While StringInStr($copia, "Sigla") = True
        Send("{F4}")
        MouseMove(518, 378, 1)
        MouseClick($MOUSE_CLICK_LEFT)
        MouseClick($MOUSE_CLICK_LEFT)
        Send("^c")
        $copia = ClipGet()
   WEnd
EndFunc   ;==>ApertaF4

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

I tried that in the raw way (lol). I paste it in a note pad. Anyway i figure it out, was a deay problem. I put a Sleep function in the beginning of the Loop. Just testing the faster way without "crashing" the script. Thank you guys. Thanks a lot

Share this post


Link to post
Share on other sites

#13 ·  Posted

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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