Solved

Combining With Statements

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now