Solved

Combining With Statements

Posted on 2013-05-20
4
192 Views
Last Modified: 2013-05-21
How can I combine the following into one With statement in VB6?

With Cbo1
.Additem "One"
.Additem "Two"
.Additem "Three"
End With

With Cbo2
.Additem "One"
.Additem "Two"
.Additem "Three"
End With
0
Comment
Question by:al4629740
4 Comments
 
LVL 4

Expert Comment

by:frankd
ID: 39181979
Cbo1.Additem "One"
Cbo1.Additem "Two"
Cbo1.Additem "Three"
Cbo2.Additem "One"
Cbo2.Additem "Two"
Cbo2.Additem "Three"
0
 

Author Comment

by:al4629740
ID: 39182006
Is it possible to do something like this?


With Cbo1,Cbo2
.Additem "One"
.Additem "Two"
.Additem "Three"
End With
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 39182133
The nearest thing would be to create a separate procedure
FillCombo Cbo1
FillCombo Cb02
'...

Sub FillCombo (cbo as Combobox)
With cbo
.Additem "One"
.Additem "Two"
.Additem "Three"
End With 
end sub

Open in new window

0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 total points
ID: 39183920
You could also do it this way.
Sub Q_28133515()
    Dim vItem As Variant
    For Each vItem In Array("One", "Two", "Three")
        Cbo1.AddItem vItem
        Cbo2.AddItem vItem
    Next
End Sub

Open in new window


Or, passing a parameter array:
Sub Q_28133515(ParamArray parmControls())
    Dim vItem As Variant
    Dim ctlThing As Variant
    For Each ctlThing In parmControls
        For Each vItem In Array("One", "Two", "Three")
            ctlThing.AddItem vItem
        Next
    Next
End Sub

Open in new window

The invoking code would look like this, resembling your multiple parameter With statement.
    Q_28133515 Cbo1, Cbo2

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question