Results 1 to 14 of 14
Thread: Do while loop (I think)

20090812, 11:41 #1
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
Code:pcommConnMgr.autECLConnList.Refresh intSessCount = pcommConnMgr.autECLConnList.Count If intSessCount = 0 Then Exit Sub End If
I want to refresh and count, then check if zero. If it is zero, i would like to repeat the process a further 2 times, then exit sub if the count is still zero.
I'd appreciate a little help with the syntax....

20090812, 11:48 #2
 Join Date
 Mar 2002
 Posts
 84,353
 Thanks
 0
 Thanked 28 Times in 28 Posts
Code:Dim i As Integer For i = 1 To 3 pcommConnMgr.autECLConnList.Refresh intSessCount = pcommConnMgr.autECLConnList.Count If intSessCount > 0 Then Exit For End If Next i If i = 4 Then Exit Sub End If

20090812, 12:38 #3
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
Thanks Hans, what would I do without you?
My Do until loop below is working ok, but has a danger of never ending (I [think] I have learned something today) Please would you check that my logic is correct in converting this to a for next loop with a maximum counter of 5.
Code:If pcommPS.GetText(1, 2, 4) = "PROD" Then Do Until pcommPS.GetText(3, 16, 52) = "x" pcommPS.SendKeys "[clear]" pcommOIA.WaitForAppAvailable 5 pcommOIA.WaitForInputReady Loop 'Artificially end the loop intLoop = intSessCount booProcessed = True Else booProcessed = False End If 'Conversion to a For next loop with a max counter of 5 If pcommPS.GetText(1, 2, 4) = "PROD" Then For i = 1 To 5 If pcommPS.GetText(3, 16, 52) <> "x" Then pcommPS.SendKeys "[clear]" pcommOIA.WaitForAppAvailable 5 pcommOIA.WaitForInputReady If pcommPS.GetText(3, 16, 52) = "x" Then 'Artificially end the loop intLoop = intSessCount booProcessed = True Exit For Else booProcessed = False End If End If Next i End If

20090812, 14:00 #4
 Join Date
 Mar 2002
 Posts
 84,353
 Thanks
 0
 Thanked 28 Times in 28 Posts
I don't know what exactly the requirements are. Should you check that pcommPS.GetText(1, 2, 4) = "PROD" within the loop or isn't that necessary?

20090812, 14:08 #5
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
Good catch. That If only needs to be evaluated once, outside the loop, but I do need to add an else "booProcessed = False" there.

20090812, 14:23 #6
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
[quote name='VegasNath' post='788692' date='12Aug2009 20:08']Good catch. That If only needs to be evaluated once, outside the loop, but I do need to add an else "booProcessed = False" there.[/quote]
Aah but...
Will that be evaluated when the fornext loop is exited with "booProcessed = True"

20090812, 14:27 #7
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts

20090812, 14:27 #8
 Join Date
 Mar 2002
 Posts
 84,353
 Thanks
 0
 Thanked 28 Times in 28 Posts
If you use
Code:If pcommPS.GetText(1, 2, 4) = "PROD" Then For i = 1 To 5 If pcommPS.GetText(3, 16, 52) <> "x" Then pcommPS.SendKeys "[clear]" pcommOIA.WaitForAppAvailable 5 pcommOIA.WaitForInputReady If pcommPS.GetText(3, 16, 52) = "x" Then 'Artificially end the loop intLoop = intSessCount booProcessed = True Exit For Else booProcessed = False End If End If Next i Else booProcessed = False End If

20090812, 15:51 #9
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts

20090813, 03:00 #10
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
On testing, this is still a little off.
If pcommPS.GetText(1, 2, 4) = "PROD"
AND
If pcommPS.GetText(3, 16, 52) = "x" on first evaluation, I am getting booProcessed = False, which should be true
The logic is as follows:
If pcommPS.GetText(1, 2, 4) <> "PROD" Then Get out, booProcessed = False. The End.
If pcommPS.GetText(1, 2, 4) = "PROD"
AND
If pcommPS.GetText(3, 16, 52) = "x" Then Get Out, booProcessed = True. The End
If pcommPS.GetText(1, 2, 4) = "PROD"
AND
If pcommPS.GetText(3, 16, 52) <> "x" Then
pcommPS.SendKeys "[clear]"
pcommOIA.WaitForAppAvailable 5
pcommOIA.WaitForInputReady
max 5 times UNTIL
If pcommPS.GetText(1, 2, 4) = "PROD"
AND
If pcommPS.GetText(3, 16, 52) = "x" Then booProcessed = True, ELSE booProcessed = False
Hope this makes sense.

20090813, 04:09 #11
 Join Date
 Mar 2002
 Posts
 84,353
 Thanks
 0
 Thanked 28 Times in 28 Posts
Try
Code:booProcessed = False If pcommPS.GetText(1, 2, 4) = "PROD" Then If pcommPS.GetText(3, 16, 52) = "x" Then booProcessed = True Else For i = 1 To 5 pcommPS.SendKeys "[clear]" pcommOIA.WaitForAppAvailable 5 pcommOIA.WaitForInputReady If pcommPS.GetText(3, 16, 52) = "x" Then 'Artificially end the loop intLoop = intSessCount ' What is this for? booProcessed = True Exit For End If Next i End If End If

20090813, 07:39 #12
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
' What is this for?
Hans, this is the count of available sessions. when we find one available session and use it, we are ensuring that the process is not carried out in the next available session.
Thanks, slightly modified, this seems to work.
Code:booProcessed = False If pcommPS.GetText(1, 2, 4) = "PROD" And pcommPS.GetText(3, 16, 52) = "x" Then 'Artificially end the loop intLoop = intSessCount booProcessed = True Else For i = 1 To 5 pcommPS.SendKeys "[clear]" pcommOIA.WaitForAppAvailable 5 pcommOIA.WaitForInputReady If pcommPS.GetText(1, 2, 4) = "PROD" And pcommPS.GetText(3, 16, 52) = "x" Then 'Artificially end the loop intLoop = intSessCount booProcessed = True Exit For End If Next i End If

20090813, 07:51 #13
 Join Date
 Mar 2002
 Posts
 84,353
 Thanks
 0
 Thanked 28 Times in 28 Posts
I don't know the external application that you're using so I have no idea why it would become nonresponsive.

20090813, 10:24 #14
 Join Date
 Sep 2007
 Posts
 1,203
 Thanks
 0
 Thanked 0 Times in 0 Posts
[quote name='HansV' post='788783' date='13Aug2009 13:51']I don't know the external application that you're using so I have no idea why it would become nonresponsive.[/quote]
I do, and I don't either.
As always, Thanks for your help!