[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

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?
0
wjshore
Asked:
wjshore
  • 5
  • 4
1 Solution
 
GrahamSkanCommented:

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
0
 
GrahamSkanCommented:
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)
0
 
wjshoreAuthor 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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
wjshoreAuthor Commented:
I'm not asking to correct a condition.  I'm asking how to check for a 'No Dupes' condition.  Thanks, anyway.
0
 
GrahamSkanCommented:
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
0
 
wjshoreAuthor 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.
0
 
GrahamSkanCommented:
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.
0
 
wjshoreAuthor Commented:
That gets me out of the routine,but does not create a flag.  Once again, I need to create a flag.
0
 
GrahamSkanCommented:
You can pass True (for dupes found) to your FiveSeedMovies procedure. I woull call that a flag. Alternatively you could Dim a boolean value in the declarations secion of your code module and set that

Dim bDupesFound as Boolean

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
              bDupesFound = True
              Call FiveSeedMovies
              Exit Sub
         End If
     Next j
Next i
bDupesFound = False
End Sub
back to top
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now