.beyond the wit of a With.

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?

Featured Replies in this Discussion

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

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

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

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

End Sub

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



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.

With lvMain
            .Items.Add(New ListViewItem("item.1,subItem".Split(",")))
            .BackColor = Color.LightSteelBlue
            .Font = New Font("Verdana", 10, FontStyle.Bold)
        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

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.:)

Question Answered as of 3 Years Ago by Teme64 and Olivis
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

This question has already been solved: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: