Forum Discussion

joffre's avatar
joffre
Regular Contributor
14 years ago

Logical doubt

retornoCadastrar2 = Aliases.iexplore.pageFpwebFolhaDePagamento.frameFrame2.formForm1.table2.cellEncargoNOCadastrado.innerText 

If retornoCadastrar <> retornoCadastrar2 Then

    Log.Error("Falha na inserção")

Else

    Log.Message(retornoCadastrar)

End If




I have the code above that isn't working as it was supposed to be.

The variable "retornoCadastrar" is being initialized with the value "Inserted Successfully" and retornoCadastrar2 is receiving the same value, but instead of entering the Log.Message statement, it is going to Log.Error.



What am I doing wrong?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm guessing that there may be extra non-printing characters (like a carriage return or something) that is causing the difference.   Put a breakpoint on your comparison line and see what the value of the two variables are.
  • joffre's avatar
    joffre
    Regular Contributor
    I'm guessing that there may be extra non-printing characters (like a carriage return or something) that is causing the difference.   Put a breakpoint on your comparison line and see what the value of the two variables are.




    I did what you told me to, and the result of both variables are the same... But instead of debugging, I generated a Log.Message() to see the results after the test.



    Here is my code:

    retornoCadastrar2 = lblResultado.innerText 

    If retornoCadastrar <> retornoCadastrar2 Then

        Log.Message("If " &retornoCadastrar& "<>" &retornocadastrar2)

        Log.Error("Falha na inserção!")

    Else

        Log.Message(retornoCadastrar)

    End If




    It keeps jumping into Log.Error() statement even the If conditional being False.



    And here is my Log.Message() result:

    If Encargo '102' inserido com sucesso. <>  Encargo '102' inserido com sucesso.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Try something else... try using aqString.Find to determine if the text in the first variable is found in the second...that MIGHT work better.



    From your post, though, it does look like in the second value there's a carriage return after the period.  This is why I suggested a debug rather than a log as this is a little clearer in "real-time" resolution of the data.
  • joffre's avatar
    joffre
    Regular Contributor
    I used aqString.Find as attached and still not working. Now I debugged to show you.



    What am I doing wrong?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Your syntax usage of aqString.Find is incorrect.  Reverse the two parameters and try again.
  • joffre's avatar
    joffre
    Regular Contributor
    So the example on aqString.Find article is wrong (or I understood it wrong)...



    It says that "If the substring was found, the method returns the number of the first matching character, otherwise, it returns -1."



    As my example is returning "-1" it means that the word "sucesso" wasn't found, or it means that it was found?!



    Sub StringOccurrenceDemo

      Dim aString, aSubString, Res

      aString = "Per aspera ad astra"

      aSubString = "astra"

      Res = aqString.Find(aString, aSubString)

      If Res <> -1 Then 

        Log.Message("Substring '" & aSubString & "' was found in string '" & aString & "' at position " & Res)

      Else 

        Log.Message("There are no occurrences of '" & aSubString & "' in '" & aString & "'")

      End If

    End Sub




    If I got that wrong, I'll need to practice my english!! ;(



    Thanks Robert.
  • joffre's avatar
    joffre
    Regular Contributor
    Oh my God...! You're right. Sorry! =x



    And thanks once again! ;D