Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep on macro running 1

Status
Not open for further replies.

limeg95

Programmer
Oct 22, 2009
124
CA
skip
this is the code i am using , when i step through it works fine but when it runs it keep on going ascenind gorder and descending order 48,47, 46, 45
becasue of j = j -1
coudl you help me. thanks
-------------
For j = 7 To 48
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6)))
DSFPT = Cells(j, 1).Text

If DSFPT <> "" Then
If DSFPT1 <> DSFPT Then
MyScreen.SendKeys ("<ENTER>")
j = j - 1
ELSE
' working fine this part
else
next j
 


If you change the value of the counter, your loop will not behave properly. I NEVER change a For...Next loop counter. If you want that kind of control, use a Do...Loop.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks for helping out.
but the screen value cahnged as next screen. but excel has not not changed
i changed it as
If DSFPT1 <> DSFPT Then
do while DSFPT1 <> DSFPT
MyScreen.SendKeys ("<ENTER>")
Loop
ELSE
 



Exactly what does this mean???

Please EXPLAIN what YOU SEE is happening, as I do not have a crystal ball, genie, medium or any other means of divining what is happening in Ontario Canada!
but the screen value cahnged as next screen. but excel has not not changed

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip
first time screen value changed when do loop perform
second time the screen value and excel value are same but still keep on changing screen value

If DSFPT1 <> DSFPT Then
do while DSFPT1 <> DSFPT
MyScreen.SendKeys ("<ENTER>")
Loop
 
Skip
Could you help me need to out of the loop.
DSFPT1 <> DSFPT Then
 



You have posted NOTHING that has to do with writing anything to Excel.
Could you help me need to out of the loop.
DSFPT1 <> DSFPT Then
Code:
DSFPT1 <> DSFPT Then Exit For


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks once again. writing anything to excel. it excit completly but screen has to go next page and excel and screen are same do somehting.
i have whole code here. coudl you please see that
if screen and excel has same it works fine, if it different, it goes to next page and see that matches with excel row.

-----------------------
For j = 7 To 48
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6)))
DSFPT = Cells(j, 1).Text

If DSFPT <> "" Then

If DSFPT1 <> DSFPT Then

MyScreen.SendKeys ("<ENTER>")
MyScreen.SendKeys ("<ENTER>")
' j = j - 1
Else
If DSFPT <> "SFCO" And DSFPT <> "SFEOE" Then
Set MyArea1 = MyScreen.Search("TOTALS")
MyScreen.moveto MyArea1.Bottom, MyArea1.Left
MyRw = MyScreen.Row
If MyRw <> 1 Then
Mytotal1 = Trim(MyScreen.GetString(MyRw, 44, 6))
End If
End If
Cells(j, (Mycol + 1)).Value = Mytotal1
MyScreen.SendKeys ("<ENTER>")
End If


End If
Else

End If
Next j
wbExcel.Close
MyScreen.SendKeys ("<PF3>")
MyScreen.SendKeys ("<PF3>")
MyScreen.SendKeys ("<PF3>")
End Sub
 



Please state ALL your logic in prose, not VBA code.

Explain why your are looping 7 to 48.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks for your valuable time.
7 to 48 excel rows
my logic is if the rows match with screen it grabe the information and put it in excel back. if the rows not match with screen, it goes to next screen and check it matches grab the inforamtion wrie in excel.
 



This is an instance where you ought to use a DO...Loop and only incriment the row counter when you have found a matcu on a screen...
Code:
x = 7
Do
'get screen 1
  Do
     'If {values Match} then exit do
     'get next screen
  Loop
  'now do what you need to do that the data is matched
  x = x + 1
Loop Until x > 48


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks again your time. but it has the same error
it completley escapes from the loop.
the screen does not match the rows it does goes completely out of the loop.
coudl you please help me
 



How can I help you if you do not post the code that you are referring to?????????

PLEASE HELP YOURSELF!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skip
thanks for your great help
this is the code i have it. it works when i step throug.
but when it runs it keep on within the for next loop.
it never ends
could you please check what is wrong in it.
-------------------

For j = 7 To 48
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6)))
DSFPT = Cells(j, 1).Text

If DSFPT <> "" Then

Do While DSFPT1 <> DSFPT
MyScreen.SendKeys ("<ENTER>")
MyScreen.SendKeys ("<ENTER>")
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6)))
Loop

If MYArea Is Nothing Then
Else
MyScreen.WaitHostQuiet (g_HostSettleTimE)
MyScreen.SendKeys ("<Enter>")
Set MyArea1 = MyScreen.Search("TOTALS")
MyScreen.moveto MyArea1.Bottom, MyArea1.Left
MyRw = MyScreen.Row
If MyRw <> 1 Then
Mytotal1 = Trim(MyScreen.GetString(MyRw, 44, 6))
End If
End If

Cells(j, (Mycol + 1)).Value = Mytotal1
MyScreen.SendKeys ("<ENTER>")

End If

Next j

wbExcel.Close

End Sub
 


Well you seem to think that you know how to code your control structure, as you have totally ignored my reply to your former questions.

good luck!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip
HAPPY NEW YEAR!!!
it works great, only one issue i am facing now
suppose if the screen is not match with excel go to next screen and check with row

HERE IS THE CODE
---------------------------
x = 7
Do
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6)))
DSFPT = Cells(x, 1).Text
If DSFPT = DSFPT1 Then


If MYArea Is Nothing Then
Else
MyScreen.WaitHostQuiet (g_HostSettleTimE)
MyScreen.SendKeys ("<Enter>")
Set MyArea1 = MyScreen.Search("TOTALS")
MyScreen.moveto MyArea1.Bottom, MyArea1.Left
MyRw = MyScreen.Row
If MyRw <> 1 Then
Mytotal1 = Trim(MyScreen.GetString(MyRw, 44, 6))
End If
End If
MyScreen.WaitHostQuiet (g_HostSettleTimE)
Cells(x, (Mycol + 1)).Value = Mytotal1
MyScreen.SendKeys ("<ENTER>")

End If
Do
If DSFPT = DSFPT1 Then Exit Do
MyScreen.SendKeys ("<ENTER>")
Loop

Else
x = x + 1
End If
Loop Until x > 48
 



"suppose if the screen is not match with excel go to next screen and check with row "

Please explain exactly what that means.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

skip
DSFPT1 = Trim(UCase(MyScreen.GetString(6, 9, 6))) ' screen location
DSFPT = Cells(x, 1).Text ' excel
i am running the macro against excel matcehs with screen
but excel does not match with screen
screen go to next screen at the same time excel go to next row
 



The OUTER loop controls Excel. Get the Excel values here.

The INNER loop controls the screen. Get Screen values here.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top