Results 1 to 3 of 3

Thread: [2005] Clear multiple Checkboxes with With End-With Statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    1

    [2005] Clear multiple Checkboxes with With End-With Statement

    Hey guys

    i have a small college project on the go, the lecturer insists that we must use a with end-with statement to clear 3 checkboxes inside a groupbox

    i know how to change multiple properties of 1 object using with end-with, but im lost as to how i can change 1 property of multiple checkboxes using it?

    anyone point me in the right direction?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Clear multiple Checkboxes with With End-With Statement

    this works

    vb Code:
    1. With Me.GroupBox1
    2.      For x As Integer = 1 To 3
    3.           DirectCast(.Controls("checkbox" & x), CheckBox).Checked = False
    4.      Next
    5. End With

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Clear multiple Checkboxes with With End-With Statement

    Just so you know, that is a stupid use for a With block. Your lecturer is presumably trying to make a point but you'd never actually use a With block in a situation like this. A With block does nothing for the app. It exists solely so you don't have to type as much. In Paul's code you end up typing more.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width