We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,613 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

3
Contributors
5
Replies
23 Hours
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8

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
Skill Endorsements: 0

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,040 posts since Aug 2008
Reputation Points: 218
Solved Threads: 206
Skill Endorsements: 5

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
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8

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,040 posts since Aug 2008
Reputation Points: 218
Solved Threads: 206
Skill Endorsements: 5

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
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
Question Answered as of 1 Year Ago by Teme64 and Olivis

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3094 seconds using 2.75MB