954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

.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?

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

Olivis
Newbie Poster
14 posts since Mar 2011
Reputation Points: 22
Solved Threads: 1
 

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
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

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

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

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

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: