Solved

Get a For/Next to only process once.

Posted on 2015-01-14
15
99 Views
Last Modified: 2015-02-07
I have an odd request...  There is a dynamic table of records in a QTP sheet that is "y" and for each record I am grabbing a value in the row and setting it to SOLN_Qty.  Ln 1-4.  Then I am trying to move that value assigned to SOLN_Qty to a dynamic WebTable and place it in the first row "z", column 4.  However it places that value in all the WebTable rows and I only want the current value of SOLN_Qty in that first WebTable row.

It then proceed to the next y, and assigns SOLN_Qty to whatever the next y rows value is.  Then assigns all the WebTable cells, (z,4) to that.  and on and on, until the last row of y is reached, and that is the value that each row in the WebTable gets.

Is there a way to tell the second For/Next, or z, to only execute once and not go thru all the rows in the Webtable?  We need it to increment z, and go get the next y value, and assign that to the next z.  Hope this makes sense.  Please advise and thanks.

Actually z and y are equal to the same thing. 3.  Unless someone knows of a different way to get the value assigned to SOLN_Qty to the WebTable?  Any Idea's?

Dim record_counta
record_counta = DataTable.GetSheet("SOLNData").GetRowCount
For y = 1 to record_counta  'Goes thru all rows.
   SOLN_Qty=Datatable.Value("OrderQty","SOLNData") 'Sets SOLN_Qty to whatever is in row 1

   rCount = Browser("SAP NetWeaver Portal").SAPPortal("SAP NetWeaver Portal").Frame("213414_FRAME").WebTable("Number").RowCount  'WebTable row count = same as y

     For z = 2 to rCount  'start at row 2, because row one is the headers

'Issue: next line loops through all rows and puts the value of SOLN_Qty in each row of the WebTable, and we only need it in whatever row "z" is.  Only need the next line to execute once.  Then go get the next y, put it in the next z.

       Browser("SAP NetWeaver Portal").SAPPortal("SAP NetWeaver Portal").Frame("213414_FRAME").WebTable("Number").ChildItem(z,4,"WebEdit",index).Set SOLN_Qty  
    Next


DataTable.GetSheet("SOLNData").SetNextRow
Next

Open in new window

0
Comment
Question by:RWayneH
  • 9
  • 6
15 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40548853
You could use an "Exit For" statement
0
 

Author Comment

by:RWayneH
ID: 40548859
I did not even think of that...  trying it now.  Thanks.
0
 

Author Comment

by:RWayneH
ID: 40548875
How would I get Ln8 to increament down to the next row of the WebTable?  Is'nt it going to go back to row 2 and overwrite?
0
 

Author Comment

by:RWayneH
ID: 40548881
I made an incorrect statement that y and z are the same.  Actually in this case y is 3 and z is 4.  z contains row 1 which are headers.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40548882
"For Next" will only exit the inner-most loop. So if you put it after line 12, then it will continue with the "y" loop.
0
 

Author Comment

by:RWayneH
ID: 40548948
Yup I was right. It overwrote row 2 column 4, with the new y.  It does not increment z to row 3 when the next y is selected.  How would I address keeping z incrementing as y does so that the next y, increments z to the next WebTable row down from row 2 column 4 and is row 3 column 4?
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40548958
Have before line 2

z = 2

Change to the

For z = 2 to rCount / Exit For / Next

to

Do...
z = z + 1
Exit Loop...
Loop until z = rCount

This way, z will retain its value through the y loop.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:RWayneH
ID: 40549065
I am working with removing z and the inner For/Next. Instead using y+1 in the WebTabe.  So far so good.  If this does not work I will use your suggestion. Thanks.

For y = 1 to record_counta  'Goes thru all rows.
SOLN_Qty=Datatable.Value("OrderQty","SOLNData") 'Sets SOLN_Qty to whatever is in row 1
Browser("SAP NetWeaver Portal").SAPPortal("SAP NetWeaver Portal").Frame("213414_FRAME").WebTable("Number").ChildItem(y+1,4,"WebEdit",index).Set SOLN_Qty  
DataTable.GetSheet("SOLNData").SetNextRow
Next
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40549074
Good luck.
0
 

Author Comment

by:RWayneH
ID: 40549158
Question on this....  new code with no z

I sequenced the qty's in the table to be 5, 10 and 15.  so they should be loaded into the Webtable that way.  How come when it runs then out of seqence and loads them as 10,15 and 5?  Some thing is up?
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40549163
Sounds like it is in alphabetical order rather than number order.
0
 

Author Comment

by:RWayneH
ID: 40549228
Any idea how to fix this?  I thought because y is 1 it is referring to 1, that is the first row?... not the first row in alphabetical order?  So, 1,2,3 will work, but 5,10,15 will not?  This very disturbing and I am guessing something in QTP?  Is there a way the make 1 the first row and not alphabetically?  My testing is show this consistent, as you say.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40549247
You should sort your datatable, maybe using the Select method - see http://msdn.microsoft.com/en-us/library/zk13kdh0%28v=vs.71%29.aspx for more details.

Or - you should have use the NumberFormat on the column in question - see https://datatables.net/reference/option/formatNumber for more details.
0
 

Author Comment

by:RWayneH
ID: 40570754
It was the column format in QTP, once I changed it, it started behaving correctly.  THANKS!!
0
 

Author Closing Comment

by:RWayneH
ID: 40595980
Thanks for the help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel copy picture into Outlook email 7 47
increment numbers by 10 11 31
Excel 2016: auto-number column of merged cells. 47 31
Excel 17 37
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now