Solved

Combining With Statements

Posted on 2013-05-20
4
201 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

697 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