Ask a Question

Trouble to use aqString.Find in a if condition

SOLVED
slaugier
Occasional Contributor

Trouble to use aqString.Find in a if condition

Hello

 

I have a text file, I want to copy it to a new file.

I want to modify it by using aqString.Replace with some substrings found by aqString.Find.

But aqString.Find seems to find nothing.

At the end, I have the exact copy of my file.

 

Do you have any advice? 

 

count = 1;
while (foundFiles.HasNext()) { aqFile.Create(fHTMLFile); aFile=foundFiles.Next(); bFile = aqFile.OpenTextFile(aFile.Path, aqFile.faReadWrite, aqFile.ctUTF8); bFile.Cursor = 0; while(! bFile.IsEndOfFile()){ bLine = bFile.ReadLine(); if (aqString.Find(bLine, "data")) { aqString.Replace(bLine,"data", "data" + count) } if (aqString.Find(bLine, "idChart")) { aqString.Replace(bLine,"idChart", "idChart" + count) } if (aqString.Find(bLine, "chart")) { aqString.Replace(bLine,"chart", "chart" + count) } aqFile.WriteToTextFile(fHTMLFile, bLine, aqFile.ctUTF8); } bFile.Close(); count = count+1 ; }

Thank you !

 

 

2 REPLIES 2
tristaanogre
Esteemed Contributor

aqString.Find returns an integer value (see https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/find.html).  if statments need a boolean value to execute.  basically, you're saying if 2 then...  That doesn't exactly execute.

 

Basically, all your if clauses add != -1... like so.

 

  if (aqString.Find(bLine, "data") != -1) 
   {               
   aqString.Replace(bLine,"data", "data" + count)               
   }              
  if (aqString.Find(bLine, "idChart") != -1) 
   {                
   aqString.Replace(bLine,"idChart", "idChart" + count)               
   }              
  if (aqString.Find(bLine, "chart") != -1)  
   {                
   aqString.Replace(bLine,"chart", "chart" + count)                
   }  

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
slaugier
Occasional Contributor

Thank you! It helped me a lot! 

 

And I had to correct this way to solve everything :

 

  if (aqString.Find(bLine, "data") != -1) 
   {               
   bLine = aqString.Replace(bLine,"data", "data" + count)               
   }              
  if (aqString.Find(bLine, "idChart") != -1) 
   {                
   bLine = aqString.Replace(bLine,"idChart", "idChart" + count)               
   }              
  if (aqString.Find(bLine, "chart") != -1)  
   {                
   bLine = aqString.Replace(bLine,"chart", "chart" + count)                
   } 
cancel
Showing results for 
Search instead for 
Did you mean: