Jump to content

Strings comparison error


 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

My bad. Should be

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

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

 

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,
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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