Forum Discussion

s5h's avatar
s5h
Contributor
10 years ago

Aqstring.find cannot find the string

So I am using Aqstring.Find to find a substring of a string. My 2 strings are 

strcomp ="currdaybookvoucherinvoicedateduedateropenamount(tc)openamount(bc)withinterms1monthsoverdue2monthsoverdue3monthsoverdue4+monthsoverdue"



ss  = "daybookvoucherinvoicedateduedateropenamount(tc)openamount(bc)withinterms"



When I do aqstring.Find(strcomp, ss, 0, false) it returns -1 



The ss is an item from an array and strcomp is read from an excel. I converted both to string using aqconvert and checked using GetVarType and the both returned 8 so they are both strings. 



When I evaluate the expression in TestComplete using the Ctrl and F12:

aqsting.find(strcomp, ss) = -1 

aqstring.find(strcomp, "daybookvoucherinvoicedateduedateropenamount(tc)openamount(bc)withinterms") = 4



So it seems to be a problem with ss? 





7 Replies

  • p6s's avatar
    p6s
    New Contributor
    For everyone that tried to help, I had a look and there was nothing wrong with the code per se. It was a data issue.



    arySub(iCounter) there was an extra linefeed character at the end that didn't get stripped out.

    So while it appeared that 

       arySub(iCounter)  = "daybookvoucherinvoicedateduedateropenamount(tc)openamount(bc)withinterms"

    when I compared the lengths, i got this:

       len(arySub(iCounter) = 73

       len( "daybookvoucherinvoicedateduedateropenamount(tc)openamount(bc)withinterms") = 72



    So I knew something was up.



    Stripping out the linefeed character gave the expected value.
  • Tried it out and I always get '4'.



    Which version of TestComplete are you using?  Rather than trying to guess at your code, it would help if you could post a short routine showing the problem...



    Joe
  • Strange, I've just copy your strings and check on my TC. It works and all your cases get "4"
  • s5h's avatar
    s5h
    Contributor
    If I create a seperate script and do this and assign the values to strcomp and ss it works fine, but does not seem to work in my main script. Here is a snippet:

     

    '-----------------

    Dim arySub

    Dim iCounter, iPos


    Dim strComp


     


        arySub = Split(strMatch, WILDCARD_STRING)


        strComp = strTarget


        


        For iCounter = 0 to UBound(arySub)


          'Cater for if the last array is blank it wont return a match


          If strComp = "" And UBound(arySub)<> iCounter Then 


            IsWildMatched = false


            Exit function 


          End IF

     


            iPos = aqstring.find(strComp, arySub(iCounter))


            'not found


            If arySub(iCounter) = "" Then 


              'Ignore


              strIgnore = True


            else If iPos <= 0 Then


                IsWildMatched = False


                Exit Function


            End If


            end if


            


            If strIgnore = False Then  


              strComp = Mid(strComp, iPos + Len(arySub(iCounter)))


            End If 


          


            strignore = False 


                    


        Next


        


        'all sub-strings are found


        IsWildMatched = True



    I have attached a file of the watchlist during run time, maybe it is something small I cannot see but it looks like everything is ok. 



    Any ideas

  • s5h's avatar
    s5h
    Contributor
    Yes if I remove the script and put it in its own script unit it passes fine. It is when it is in my overall project it fails but the array value checked before this one is found ok 



  • I have no answers but only suggestion...



    - StrComp() is a VBScript function.  Try changing the name of your strComp variable.



    - Your attachment showed an error in the Evaluation window saying "Unterminated string constant".  Perhaps you've used two apostrophes (') instead of a double quote (")?



    - That it works OK outside your project pretty much means that we aren't going to reproduce it with standalone routines.



    See how much you can cut out of your project and still show the error, then submit a support case and provide your cut-down project.



    Joe