Link to home
Start Free TrialLog in
Avatar of wjshore
wjshore

asked on

Set up an exit flag in VB6

In a VB6 app. I have the following routine:

     'CSEH: ErrResumeNext
Public Sub CheckDupes()
    '<EhHeader>
    On Error Resume Next
    '</EhHeader>
Dim i As Integer
Dim j As Integer
For i = 0 To 23
     For j = i + 1 To 24
         If Movies(i) = Movies(j) Then
              Call FiveSeedMovies
         End If
     Next j
Next i
 
End Sub

The code is intended to look at the contents of array Movies() and check that none of its 25 components is a duplicate of the others.  If a duplicate is found, it's set up (intended) to send control back to 'FiveSeedMovies' to create a NEW ARRAY Movies() and try again.

I need to create and set a flag to tell me when the condition "No duplicates" exists and to send the app. on its way without returning.  Can someone suggest exactly how?
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image


Simply exit the routine after the condition is found:

Public Sub CheckDupes()
    '<EhHeader>
    On Error Resume Next
    '</EhHeader>
Dim i As Integer
Dim j As Integer
For i = 0 To 23
     For j = i + 1 To 24
         If Movies(i) = Movies(j) Then
              Call FiveSeedMovies
              Exit Sub
         End If
     Next j
Next i
 
End Sub
I don't know what logic is in FiveSeedMovies, but if you want it to be able to 'correct' the situation by deleting one of the duplicates, you could pass the duplicate name or perhaps the relevant indices to that procedure

e.g:
Call FiveSeedMovies(i,j)
Avatar of wjshore
wjshore

ASKER

I don't understand.  You have placed 'Exit Sub' inside an If statement loop in which a duplicate is found (Movies(x)=Movies(y))  How could that check for a 'no dupes' condition?
Avatar of wjshore

ASKER

I'm not asking to correct a condition.  I'm asking how to check for a 'No Dupes' condition.  Thanks, anyway.
Call the procedure after all the tests. We could pass a duplicate found  flag as well as/instead of the duplicate indices.

Public Sub CheckDupes()
    '<EhHeader>
    On Error Resume Next
    '</EhHeader>
Dim i As Integer
Dim j As Integer
For i = 0 To 23
     For j = i + 1 To 24
         If Movies(i) = Movies(j) Then
              Call FiveSeedMovies( True, i, j)
              Exit Sub
         End If
     Next j
Next i
Call FiveSeedMovies(False, 0, 0)
End Sub
Avatar of wjshore

ASKER

Thanks for your attention.  My problem is difficult to communicate.  The process of creating the Movies() array is very complex.  If it contains a dupe, it must be re-created - from scratch.  Therefore, I'm not trying to send a value back to FiveSeedMovies.  That's why the original routine simply sent control back to FiveSeedMovies until it avoided the "Dupe Loop" completely.

Obviously, this method can go back to FiveSeedMovies several times.  Later in the app, I need to reference a flag condition which says "It's passed thru CheckDupes successfully and won't return".
That's the flag I need to create.
OK. Just omit the indices.
In fact you can follow my first suggestion (before I decided to 'get clever'). Simply call the FiveSeedMovies when a duplicate is found and exit the checking procedure on the next line.
Avatar of wjshore

ASKER

That gets me out of the routine,but does not create a flag.  Once again, I need to create a flag.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial