Results 1 to 6 of 6

Thread: Code reduction help..

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I would like to reduce the following code:

    Code:
        If chkPrivate = 1 Then
            ValuePrivate = "on"
        Else
            ValuePrivate = "off"
        End If
    I know it's not a lot of code to begin with but I have a whole bunch of these
    to put into my program so it does add up and it's time consuming to maintain.

    Basically, what I'm trying to do is to convert the check box values of 1 and 0 to
    "on" or "off", respectively.

    Any ideas would be greatly appreciated..

    Dan

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    In school ?

    Try
    Code:
     chkPrivate.Value = not chkPrive.value

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    would the select case statement make it shorter?


  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    You could use a boolean value (?)

    Why don't you just make ValuePrivate Boolean and assign it the Boolean converted value of the checkbox?
    Code:
    ValuePrivate = CBool(chkPrivate)
    ValuePrivate will be TRUE if chkPrivate is Checked or Greyed, and FALSE if chkPrivate is UnChecked

    Hope that helps,
    ~seaweed

  5. #5
    What about this?

    Code:
    ValuePrivate = IIf(chkPrivate, "on", "off")
    Websurfer907

    ICQ: 11969470
    Website: programmerstuff.com

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    You could use the Immediate If statement

    Immediate if statements look cool but they run significantly slower than regular if/else statements. This also allows you to keep ValuePrivate as a string, which I assume was part of your requirement.
    Code:
        ValuePrivate = IIf(chkPrivate = 0, "off", "on")
    ' That is the shortest you can get...
    ~seaweed

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