×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

two While loops

two While loops

two While loops

(OP)
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

RE: two While loops

hi,

CODE

Input #1, En
    Input #2, Pa

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
Hi Skip

I am not able to interpret that in my code can you please do it for me and paste the code

RE: two While loops

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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

RE: two While loops

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
there is no loop happening at all just I get a message Macro Done

RE: two While loops

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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


RE: two While loops

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

Also, did you net read my post of 22 Aug 12 12:31?

Quote:


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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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

RE: two While loops

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
Hi skip do you have any program that is using two While loops just for reference purpose please post it

RE: two While loops

Please READ and TRY.

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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

RE: two While loops

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
        
        Close #2
        Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
        Input #2, En
        
        Input #1, Pa
    Wend 

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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

RE: two While loops

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
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

RE: two While loops

This is part of programming that you have to take responsibility for. My must use all the debug tools at your command to observe what is happening and then make appropriate changes, using thoughtful logic.

BTW, your description of what is happening is not at all very clear. FOCUS!

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
Hi

It works just added a blank row at the last for two input files

Below is the code
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

Close #2
Open "C:\Users\bzxllh\Desktop\Part.txt" For Input As #2
Input #2, En

Input #1, Pa
Wend

System.TimeoutValue = OldSystemTimeout
msgbox "macro done"
End Sub

thank you

RE: two While loops

(OP)
Hi Skip

If input starts from 0 (zero) i,e if input is 09 the 0 is neglected and only 9 is copied. I want 09 to be put at 20,12 in session but instead only 9 appears.

RE: two While loops

So are you stating that your INPUT TEXT file has "09"?

How did you declare En & Pa?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
Input #1
55236681
55242148
55242256

Input #2
14
13
09

In Input #2 after the value 13 at 20,12 in session, I should have a value of 09 in session @ 20,12, but 0 is neglected and only 9 is selected

RE: two While loops

You did not answer my second question.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
I did not declare at all

RE: two While loops

ALL variables ought to be declared!!!

Programming 101

Declare those 2 as string

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: two While loops

(OP)
Hi Skip

Thank you now everything works perfectly

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close