Ask a Question

split number into individual digits c# script and then use for loop

SOLVED
DainiusA
Contributor

split number into individual digits c# script and then use for loop

Hello,

 

I need a script to get me on the right road. I have a variable that parses a number from an SQL query example: 128 or 258 and any other combination possible.

 

I need to separate those numbers and click the coordinates(can't map the buttons because of overlapping windows).

Example how it should look:

 

Variable SQL query returns 2589

 

Separated number 2 needs to click the coordinates that are set.

Separated number 5 needs to click the other coordinates that are set 

and so on....

 

I think it is possible to do with a for loop. But I am quite new to scripting and don't know how to do it.

 

Or maybe is it possible to accomplish all of this through the KeywordTests ?

 

If my explanation is unclear do not hesitate to ask anything I will try to put all the information you need. 

1 ACCEPTED SOLUTION

Accepted Solutions
Marsha_R
Community Hero

Re: split number into individual digits c# script and then use for loop

You can convert that number to a string

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/index.html

 

then pick the string apart for your coordinates

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/index.html

 

Then convert the separate coordinates back to numbers using aqconvert again.

 

Try the examples and then with your numbers and let us know if you get stuck.

 

 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

2 REPLIES 2
Marsha_R
Community Hero

Re: split number into individual digits c# script and then use for loop

You can convert that number to a string

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/index.html

 

then pick the string apart for your coordinates

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/index.html

 

Then convert the separate coordinates back to numbers using aqconvert again.

 

Try the examples and then with your numbers and let us know if you get stuck.

 

 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

DainiusA
Contributor

Re: split number into individual digits c# script and then use for loop

Hello,

 

Thank you for the right path. Now my code looks like this:

 

function VariablesTest()
{
var Znr = Project["Variables"]["Znr"]("Znr");
for (var i = 0; i < aqString["GetLength"](Znr); i++)
Log["Message"]( aqString["GetChar"](Znr, i) );
}

 

And the output looks like this:

 

DainiusA_0-1629436205207.png

 

 

I got stuck and try to understand how can I take the first, second and third digits separately and click the desired coordinates for each of them.

Really appreciate your help.

 

I have tried to do something like this, but i ended up pressing just the first coordinate:

 

function VariablesTest()
{
var window = Aliases["UvsSco"]["HwndSource_Window"]["Window"];
var richTextBox = window["exclusivecontrolled_localattendant_localattendanttexts_attenderrortext"];
var Znr = Project["Variables"]["Znr"]("Znr");
for (var i = 0; i < aqString["GetLength"](Znr); i++)
Log["Message"]( aqString["GetChar"](Znr, [1]) );

if(Znr, [1] == '1')
richTextBox["Click"](97, 87); //1
else if (Znr, [1] == '2')
richTextBox["Click"](151, 86); //2
else if (Znr, [1] == '3')
richTextBox["Click"](210, 85); //3
else if (Znr, [1] == '4')
richTextBox["Click"](97, 128); //4
}

 

Edit:

 

Found my mistake:

 

Instead of if(Znr, [1] == '1'), replaced with  if( aqString["GetChar"](Znr, [1]) == '1') 

 

and clicks the button I need. Thank you again for the right path !

cancel
Showing results for 
Search instead for 
Did you mean: