Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is better an optional parameter or another function?!

Status
Not open for further replies.

paulette33

Technical User
Mar 15, 2002
27
US
I have a function with optional variable parameter that queries the database, stores the results in an array, and then populates the combo box. This function is uses for different combo boxes and list boxes (that's why the variables are optional). The business class stores the data in the array and passes that into the GUI class which then populates the combo box. I have 2 combo boxes that I need populate with the same information. Is it more efficient add another optional variable to the function for the second combo box or would it be better to call a different function in the business class to send the array to the GUI class? I'm pretty new to VB, does an optional variable effect the performance? Here are some pieces of the code. The code is currently has the additional optional variable.

Thanks for the help!!

Paulette


' This call is from the form
blnCheck = pobjPartBO.CheckForData(strViewDB, "qryManuf", False, , cboViewManuf, _
cboPartManuf, , cboViewManuf.ListIndex, 2, False)
************************************************************************
' This function is in the business class
Public Function CheckForData(Optional ByVal strDBName As String, _
Optional ByRef strQryName As String, _
Optional ByRef blnParameter As Boolean, _
Optional ByRef strParameter As String, _
Optional ByRef cboComboBox As ComboBox, _
Optional ByRef cboComboBox2 As ComboBox, _
Optional ByRef lstListBox As ListBox, _
Optional ByRef intComboIndex As Integer, _
Optional ByRef intSelect As Integer, _
Optional ByRef blnArray As Boolean) As Boolean

On Error GoTo CheckForDataError

Dim intRecordCount As Integer

' Procedure in Data Class to access database and run query
Call pobjPartDO.GetData(strDBName, strQryName, blnParameter, _
strParameter, intRecordCount, parrViewBO)
If intRecordCount > 0 Then
Select Case intSelect
Case 1
Call pobjPartGUI.ViewComboPopulation(cboComboBox,
intRecordCount, parrViewBO, blnArray)
Case 2
'Populate 2nd combo box
Call pobjPartGUI.ViewComboPopulation(cboComboBox,
intRecordCount, parrViewBO, blnArray)
Call pobjPartGUI.ViewComboPopulation(cboComboBox2,
intRecordCount, parrViewBO, blnArray)
End Select
CheckForData = True
Else
CheckForData = False
End If

CheckForDataErrorExit:
Exit Function

CheckForDataError:
strMsg = "Error #" & CStr(Err.Number) & " was generated by " &
Err.Source _
& Chr(13) & Err.Description
MsgBox strMsg, vbDefault, "CheckForData Procedure"
Resume CheckForDataErrorExit

End Function
*************************************************************************

'Procedure in GUI class that populates combo box from array in Business
class
Public Sub ViewComboPopulation(ByRef pobjComboBox As ComboBox, _
ByRef intRecords As Integer, _
ByRef arrViewGUI() As Variant, _
ByRef pblnArray As Boolean)

On Error GoTo ViewComboPopulationError

Dim intCombo As Integer 'row/record

pobjComboBox.Clear

' boolean used to determine what data to populate in array
If Not pblnArray Then
Do While intCombo <> (intRecords)
With pobjComboBox
.AddItem (arrViewGUI(1, intCombo))
End With
intCombo = intCombo + 1
Loop
Else
'Populate Parent Part in part frame - displays 2 fields of data
Do While intCombo <> (intRecords)
With pobjComboBox
.AddItem (arrViewGUI(2, intCombo)) & &quot; - &quot; & (arrViewGUI(1,
intCombo))
End With
intCombo = intCombo + 1
Loop
End If

ViewComboPopulationErrorExit:
Exit Sub

ViewComboPopulationError:
strMsg = &quot;Error #&quot; & CStr(Err.Number) & &quot; was generated by &quot; &
Err.Source _
& Chr(13) & Err.Description
MsgBox strMsg, vbDefault, &quot;ViewComboPopulation Procedure&quot;
Resume ViewComboPopulationErrorExit
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top