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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two While loops

Status
Not open for further replies.

rajesha24

Technical User
Aug 13, 2012
26
US
I have the below code where there is two While statements the while statement for Input 2 gets looped and then macro gets done, without looping the the while statement for input 1 please advice in this
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "SESSION1.EDP"
' Date: Tuesday, August 21, 2012 22:15:53
' User:
'--------------------------------------------------------------------------------

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 3000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events
close

Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
'Label:
'Input #1, FEWO
'Input #1, Eg1
'Input #1, Eg2
'Input #1, Eg3
'Input #1, Eg4


End_Of_File = Eof(1)

While End_Of_File = 0

Input #1, En


End_Of_Fil = Eof(2)
while End_Of_Fil = 0


Input #2, Pa
Sess0.Screen.MoveTo 04,02
Sess0.Screen.Sendkeys(En &"<tab><EraseEOF><tab><EraseEOF>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.MoveTo 04,47
Sess0.Screen.Sendkeys(Pa)
'Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<NewLine><NewLine>s<Pf5>")
Sess0.Screen.WaitHostQuiet(100)
NUB = Sess0.Screen.GetString (11, 36, 1)
if NUB = "U" then
Sess0.Screen.WaitHostQuiet(100)
NUE = Sess0.Screen.GetString (13, 17, 4)
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<NewLine>c<NewLine><NewLine><Tab><Tab><Tab>p<NewLine>gcgzk<EraseEOF>")

If NUE= "WFUO" then

Sess0.Screen.MoveTo 07,03

Sess0.Screen.Sendkeys("c")
Sess0.Screen.MoveTo 13,17

Sess0.Screen.Sendkeys("<EraseEOF>SOP<Tab><Tab><Tab><EraseEOF>")

End If
Sess0.Screen.Sendkeys("<Enter>")

End if
'Sess0.Screen.Sendkeys("<NewLine>c<NewLine><NewLine><Tab><Tab><Tab>p<NewLine>gcgzk<EraseEOF><Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet(100)

System.TimeoutValue = OldSystemTimeout
Sess0.Screen.WaitHostQuiet(100)


End_Of_Fil = Eof(2)

Wend



End_Of_File = Eof(1)

wend


MsgBox "Macro completed", 0
End Sub
 
hi,
Code:
    Input #1, En
    Input #2, Pa

    While EOF(1) = 0
    
        While EOF(2) = 0
            
            '[b]do stuff on the screen here[/b]
            
            Input #2, Pa
        Wend
        Input #1, En
    Wend

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip

I am not able to interpret that in my code can you please do it for me and paste the code
 
1) you step on End_of_file!!! Don't use THAT! It is unnecessary and you use that variable improperly anyhow!

rather use EOF(1) & EOF(2) respectively in the While statement.

Do you see where your two loops exist? COPY the screen processing stuff inside your second loop and PASTE it where my comment 'do stuff on the screen here appears.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I HAVE DONE LIKE THIS BUT DOES NOT WORK

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 3000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events
close

Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
'Label:
'Input #1, FEWO
'Input #1, Eg1
'Input #1, Eg2
'Input #1, Eg3
'Input #1, Eg4


Input #1, En
Input #2, Pa

While EOF(1) = 0

While EOF(2) = 0

'Input #2, Pa
Sess0.Screen.MoveTo 04,02
Sess0.Screen.Sendkeys(En &"<tab><EraseEOF><tab><EraseEOF>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.MoveTo 04,47
Sess0.Screen.Sendkeys(Pa)
'Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<NewLine><NewLine>s<Pf5>")
Sess0.Screen.WaitHostQuiet(100)
NUB = Sess0.Screen.GetString (11, 36, 1)
if NUB = "U" then
Sess0.Screen.WaitHostQuiet(100)
NUE = Sess0.Screen.GetString (13, 17, 4)
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<NewLine>c<NewLine><NewLine><Tab><Tab><Tab>p<NewLine>gcgzk<EraseEOF>")

If NUE= "WFUO" then

Sess0.Screen.MoveTo 07,03

Sess0.Screen.Sendkeys("c")
Sess0.Screen.MoveTo 13,17

Sess0.Screen.Sendkeys("<EraseEOF>SOP<Tab><Tab><Tab><EraseEOF>")

End If
Sess0.Screen.Sendkeys("<Enter>")

End if
'Sess0.Screen.Sendkeys("<NewLine>c<NewLine><NewLine><Tab><Tab><Tab>p<NewLine>gcgzk<EraseEOF><Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(100)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet(100)

System.TimeoutValue = OldSystemTimeout
Sess0.Screen.WaitHostQuiet(100)





Input #2, Pa
Wend
Input #1, En
Wend


MsgBox "Macro completed", 0
End Sub
 
What does "DOES NOT WORK" mean?

1. Absolutely NOTHING happens? Everything compiled? No errors? No Output of any kind?

2. Some compile error or error message? If so what message on what statement?

3. Some output but not as expected? If so what output, where versus what was expected, where?

4. Something else?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
there is no loop happening at all just I get a message Macro Done
 
Before you do all the screen manipulation, you need to make sure that your file manipulation and control works.

Check out the HELP on Debugging Macros. I'd strip out all the unnecessary code except for the basic conrol structrure for the file access and looping. Then step thru the code in order to observe what is happening and make adjustments accordingly if things do not happen as expected.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip

I tried it with simple program but I get error

INPUT PAST END OF LINE NUMBER 66 and it does not loop the second while

--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "SESSION1.EDP"
' Date: Thursday, August 23, 2012 17:17:00
' User:
'--------------------------------------------------------------------------------

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 3000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events
close
Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
Input #1, En
Input #2, Pa

While EOF(1) = 0

While EOF(2) = 0
Sess0.Screen.MoveTo 3,14
Sess0.Screen.Sendkeys(En &"<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 20,12
'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys(Pa)
'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Input #1, En
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Wend
Input #2, Pa
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Wend


System.TimeoutValue = OldSystemTimeout
End Sub


 
You SWITCHED the INPUT statements in the loops!!! No wonder.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Also, did you net read my post of 22 Aug 12 12:31?
Before you do all the screen manipulation, you need to make sure that your file manipulation and control works.

Check out the HELP on Debugging Macros. I'd strip out all the unnecessary code except for the basic conrol structrure for the file access and looping. Then step thru the code in order to observe what is happening and make adjustments accordingly if things do not happen as expected.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi
Yes I manipulated step by step, since it while within a while loop so I am stuck and I am not that good in programming concepts

can you tell me how to overcome that error

INPUT PAST END OF LINE NUMBER 66 and it does not loop the second while

 
I told you in my post of 23 Aug 12 12:56


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi skip do you have any program that is using two While loops just for reference purpose please post it
 
Please READ and TRY.

I already posted what you asked for on 22 Aug 12 10:19!!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
ok its working but the problem is

close
Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2

'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
Input #1, Pa
Input #2, En

While EOF(1) = 0


While EOF(2) = 0

Sess0.Screen.MoveTo 3,14
Sess0.Screen.Sendkeys(Pa &"<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 20,12
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys(En)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Input #2, En
wend

Input #1, Pa
Wend

First the second While loop gets done but the last row does not gets accounted, once the second while is done it goes to first while loop , the first while executes but nothing happens in the screen , and finally macro is done
 
Maybe you need to do this...
Code:
    Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
    Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
    
    'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
    Input #1, Pa
    Input #2, En
    
    While EOF(1) = 0
        
        
        While EOF(2) = 0
            
            Sess0.Screen.MoveTo 3, 14
            Sess0.Screen.SendKeys (Pa & "<Enter>")
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.MoveTo 20, 12
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.SendKeys (En)
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            
            Input #2, En
        Wend
   [b]     
        Close #2
        Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
        Input #2, En
    [/b]    
        Input #1, Pa
    Wend

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip

It works but the last row in both the input is not getting recognised , I have 3 rows in both inputs but only 2 rows are getting looped
 
Code:
Open "C:\Users\bzxllh\Desktop\New.txt" For Input As #1
    Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
    
    'Open "C:\Efiles\Delete\Out Delete.txt" For Output As #2
    Input #1, Pa
    Input #2, En
    
    While EOF(1) = 0
        
        
        While EOF(2) = 0
            
            Sess0.Screen.MoveTo 3, 14
            Sess0.Screen.SendKeys (Pa & "<Enter>")
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.MoveTo 20, 12
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.SendKeys (En)
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            
            Input #2, En
        Wend
        
        Close #2
        Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
        Input #2, En
        
        Input #1, Pa
    Wend

            Sess0.Screen.MoveTo 3, 14
            Sess0.Screen.SendKeys (Pa & "<Enter>")
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.MoveTo 20, 12
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
            Sess0.Screen.SendKeys (En)
            Sess0.Screen.WaitHostQuiet (g_HostSettleTime)


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip
the loop happens two times I want it to happen only once

Input #1
55236681
55242148
55242256

Input #2
14
13
12

from the Input #1 the part number 55236681 should get the value from Input #2 i,e 14, 13, 12 only once, but the part number 55236681 is getting the value from Input #2 only 14 & 13 that too two times and again the last row 12 is not recognised same for part numbers 55242148 & 55242256
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top