With bulbPrgSave1, bulbPrgSave2
            .Value = 50
        End Wit

What would I need to create something as the above and set values to 2+ ProgressBars? A Structure? Property?

Recommended Answers

All 5 Replies

Hmm. Very interesting question. Would like to know the answer too.

commented: :D; nope, just to +.rep.members:) +12

I didn't quite get that. Is it this you're trying to do:

With ProgressBar1
  .Value = 50
End With
With ProgressBar2
  .Value = 50
End With

to get into

With Each ProgressBar
  .Value = 50
End With Each

Something as that With Each ProgressBar , although I would like to create something as the With statement and be able to control more than one ProgressBar just by adding another ProgressBar to the wit of the "With". With bulbPrgSave1, bulbPrgSave2, bulbPrgSave3, bulbPrgSaveEtc...

Here's a one idea

Public Sub WithEach(ByVal value As Integer, ByVal ParamArray VarArg() As ProgressBar)

    For Each pbr As ProgressBar In VarArg
        With pbr
            .Value = value
        End With
    Next

End Sub

and now you can write WithEach(50, ProgressBar1, ProgressBar2) and add more ProgressBars when needed.

HTH

Very good suggestion, especially with that ParamArray (:news.to.me:)

The only issue with using a Sub, is that I cannot really control all of the Properties as I can with a "With" statement.
ex:

With lvMain
            .Items.Add(New ListViewItem("item.1,subItem".Split(",")))
            .BackColor = Color.LightSteelBlue
            .Font = New Font("Verdana", 10, FontStyle.Bold)
            '.etc...
        End With

I would have to create a Sub for each Property and that can be...

In any case, I sent a p.m. to a daniweb.friend and he replied with this:

Thats just not going to happen. I messed around with it for a while but couldn't come up with much.

Teme64's idea of the sub with the ParamArray is probably the best.

I did come up with this that can do it in 3 lines but with no with.

For Each Item In New ProgressBar() {ProgressBar1, ProgressBar2}
      Item.Value = 45
Next

Like I said the with is just not going to happen.

Unhnd_Exception's solution is probably the best solution since I can actually use 3 lines of code and control more than one control's Properties.

Thanks everyone, thread solved.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.