cancel
Showing results for 
Search instead for 
Did you mean: 

Looping script

jayj07
Active Participant
0 Kudos

Good Day!

Hope you can guide me on how to do below.

I have the VB line and I would like to run the script multiple times - changing the value inside the quotation marks ("").

session.findById("wnd[1]/usr/sub:SAPLSWOT:0200/ctxtOBJID-VALUE[0,21]").text = "XXXXXXXXXX"

How do you do this? Thanks!

Jayj

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Joseph,

welcome to this forum.

You can do it e.g. like this:

For i = 1 to 10

  varText = CStr(i)

  session.findById("wnd[1]/usr/sub:SAPLSWOT:0200/ctxtOBJID-VALUE[0,21]").text = varText

Next

In this case you set the content of to 1, 2, 3 ... 10 - as character.

Or you can do this:

For i = 1 to 10

  varText = "4711" & CStr(i) & "Ja"

  session.findById("wnd[1]/usr/sub:SAPLSWOT:0200/ctxtOBJID-VALUE[0,21]").text = varText

Next


In this case you set the content to 47111Ja, 47112Ja, 47113Ja ... 471110Ja.


Important is to use a variable to set the content.


Cheers

Stefan

jayj07
Active Participant
0 Kudos

Thanks for this Stefan!

Is there a way where I won't need to declare it one by one? I'm thinking of using an array but that will have the same problem. I have around 50-70 strings that I need to loop on so setting it to the variable may be tedious. And each string can be random so I'm having a hard time integrating it with a counter inside a for loop.

Jayj

stefan_schnell
Active Contributor
0 Kudos

Hello Jayj,

the loop with the counter was only an example.

You can contain it into a function:

Function setText(varText)

  session.findById("wnd[]1]/usr/sub:SAPLSWOT:0200/ctextOBJID-VALUE[0,21]").text = varText

End Function

With this way you can set the text in your Loop, e.g. like this:

Dim arText("YourText1", "YourText2", "YourText3")

For Each Text in arText

  setText(Text)

Next

Cheers

Stefan

Answers (0)