Results 1 to 4 of 4

Thread: Cleaner Code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Cleaner Code

    ok here is what I do have:

    Code:
    'Disable TextBox1 and change background color
    If CheckBox2.Checked = True Then TextBox1.Enabled = False
    If CheckBox2.Checked = True Then TextBox1.BackColor = system.Drawing.SystemColors.Control
    why can't I do something like so???

    Code:
    'Disable TextBox1 and change background color
    If CheckBox2.Checked = True Then TextBox1.Enabled = False and TextBox1.BackColor = system.Drawing.SystemColors.Control
    I have tried replacing the and with "then" but that doesnt seem to work... I keep getting the blue underline with errors....

    Any ideas?


    Anjari

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this

    VB Code:
    1. If CheckBox2.Checked = True Then
    2.    TextBox1.Enabled = False
    3.    TextBox1.BackColor = system.Drawing.SystemColors.Control
    4. EndIf
    Dont gain the world and lose your soul

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You need to use an If...End If block
    VB Code:
    1. If CheckBox2.Checked = True Then
    2.      TextBox1.Enabled = False
    3.      TextBox1.BackColor = system.Drawing.SystemColors.Control
    4. End If

    And DevGrp beats me again.
    Last edited by Edneeis; Dec 10th, 2002 at 01:35 AM.

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Since in both lines you're checking for the same thing, why not use a block If...End If? Can't get much cleaner than that. Besides, single line If's are hell to read (IMO)

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