We help IT Professionals succeed at work.

Set up an exit flag in VB6

wjshore
wjshore asked
on
550 Views
Last Modified: 2013-11-26
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?
Comment
Watch Question

GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:

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
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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)

Author

Commented:
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?

Author

Commented:
I'm not asking to correct a condition.  I'm asking how to check for a 'No Dupes' condition.  Thanks, anyway.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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

Author

Commented:
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.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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.

Author

Commented:
That gets me out of the routine,but does not create a flag.  Once again, I need to create a flag.
Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.