Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21237

How to loop code to execute for each item in a ComboBox control

$
0
0
Hello,

I have the following form in my application

http://imgur.com/T7IddGO

The Master City combobox is called "MasterCity", and the Slave City combobox is called "SlaveCity". The ListView that has the classes listed is called "Mismatch". Basically, what this form does is when you click the Check Button, it checks all classes that are scheduled for the Master City, and if it finds that the same class is not held on the same date for the Slave City, the Master city class is added to the Mismatch ListView.

I'm currently trying to create a Check All button (seen on the right side of the prior screenshot), which would basically do the same thing as the Check button but would check ALL Slave cities at once instead of just the one Slave city currently selected in the SlaveCity combobox, but I don't know how to loop the current Check button functionality to occur for every item in the SlaveCity combobox.

Below is the relevent code for the current function that fires when the Check button is clicked
Code:

Private Sub CheckForMismatches(ButtonSent As Integer)

  Dim SlaveCityID As Long
  Dim MasterCityID As Long
  '-Dim all the other variables needed by this function…

  Me.MousePointer = vbHourglass
  Mismatch.ListItems.Clear
  MasterCityID = masterCity.ItemData(masterCity.ListIndex)

          '-// I'm guessing the loop would need to be started here

  SlaveCityID = SlaveCity.ItemData(SlaveCity.ListIndex)    '-This line gets the SlaveCityID from the ComboBox, which is an important value I need in order to identify the Slave City in SQL statements
 
  If MasterCityID >= 0 And SlaveCityID >= 0 Then

        '- **All the Code that identifies classes scheduled for the Master City but NOT the Slave City is inside this If statement.  The class information is then output to the Mismatch ListView control. This is the code that needs to be looped for every  item in the SlaveCity dropdown**

  End If

          '-// The loop would probably be ended here

  StatusBar.Caption = "Out of " & masterCount & " classes " & Mismatch.ListItems.count & " differences found."
  If Mismatch.ListItems.count > 0 Then
      Create.Enabled = True
  End If
 
  Me.MousePointer = vbNormal
End Sub

So, my question is: How do I code a loop that will do the following:

1) Get the SlaveCityID for the first item in the SlaveCity comboBox
2) Execute all the code in that main If statement
3) Get the next SlaveCityID for the next SlaveCity comboBox item, and run through the loop again?

Viewing all articles
Browse latest Browse all 21237

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>