Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey - this may be a simple one, I just haven't done it so I'm not sure of the syntax. I have a tabbed application. Two of the tabs have a similar combobox - a list of all shipments for the day. The comboboxes are populated from a SQL server db. I have one function to populate one of the boxes, and now that I've added a second box I would like to reuse the function to populate that one. However inside the function I have to reference the combobox - how can I vary this depending on which combobox I want to populate/update? Here's my populating function - can someone help me revise it so it makes no hardcoded references to any one control?

 

Public Sub Build_ShipmentCBO(ByVal iShipSelectedID)
       '*** Initialize Stuff
       iShipSelectedIndex = 0
       i = 1
       cboShipments.Items.Clear()
       ObjConn.Open()
       ObjSQLCmd.Connection = ObjConn
       '*** Get Record Count for redim-ing object
       sSQL = "SELECT count(*) FROM tShipments WHERE iEventID=" & eventItems(cboEvents.SelectedIndex - 1).ID
       ObjSQLCmd.CommandText = sSQL
       iRecordCount = ObjSQLCmd.ExecuteScalar()

       '*** Select all shipments for event and put into record set
       sSQL = "SELECT iShipmentID, sShipDesc FROM tShipments WHERE iEventID=" & eventItems(cboEvents.SelectedIndex - 1).ID & " ORDER BY sShipDesc"
       ObjSQLCmd.CommandText = sSQL
       ObjReader = ObjSQLCmd.ExecuteReader

       '*** Redim object to size it needs to be
       ReDim shipmentItems(iRecordCount + 1)

       '*** Make first entry always be "Choose"
       shipmentItems(0) = New Class1
       shipmentItems(0).Text = "Choose Shipment"
       shipmentItems(0).ID = 0
       cboShipments.Items.Add(shipmentItems(0)) '*** NEED TO CHANGE THIS LINE

       While ObjReader.Read()
           '*** Instantiate our item object and fill it with useful information.
           shipmentItems(i) = New Class1
           shipmentItems(i).Text = ObjReader("sShipDesc").ToString
           shipmentItems(i).ID = ObjReader("iShipmentID")
           If ObjReader("iShipmentID") = iShipSelectedID Then
               iShipSelectedIndex = i
           End If
           cboShipments.Items.Add(shipmentItems(i)) '*** NEED TO CHANGE THIS
           i = i + 1
       End While

       ObjReader.Close()
       ObjConn.Close()
       cboShipments.SelectedIndex = iShipSelectedIndex '*** NEED TO CHANGE THIS
   End Sub

 

Thanks

Jenn

  • *Experts*
Posted

Make your sub accept another argument of the ComboBox type:

Public Sub Build_ShipmentCBO(ByVal iShipSelectedID ,ByVal ComboB As ComboBox)

Then pass in the instance of the ComboBox you want to modify to the function. Then in your function simply change the occurences of your hardcoded name with the name that you accept, in this example ComboB.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...