?
Solved

Combining With Statements

Posted on 2013-05-20
4
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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 46

Assisted Solution

by:aikimark
aikimark earned 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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