Results 1 to 8 of 8

Thread: How would you do it?

  1. #1

    Thread Starter
    Lively Member Xcoder's Avatar
    Join Date
    Jan 2004
    Posts
    120

    How would you do it?

    I am wondering the best way to code this, I know it might not be a hard question, but this has been tickling me for a while:

    I am wondering, which constitutes the best coding practice while having Option Strict On:
    VB Code:
    1. Btn_toggleUSR.Image = DirectCast(IIf(toggle_usr, Image.FromFile("...\unpressed_down.bmp"), Image.FromFile("...\unpressed_up.bmp")), Drawing.Image)

    VB Code:
    1. If toggle_usr Then Btn_toggleUSR.Image = Image.FromFile("...\unpressed_down.bmp") Else Btn_toggleUSR.Image = Image.FromFile("...\unpressed_up.bmp")

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Cool Re: How would you do it?

    I my humble opinion, i would say do it like this:
    VB Code:
    1. If toggle_usr = True Then
    2.     Btn_toggleUSR.Image = Image.FromFile("...\unpressed_down.bmp")
    3. Else
    4.     Btn_toggleUSR.Image = Image.FromFile("...\unpressed_up.bmp")
    5. End If
    ~Peter


  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How would you do it?

    why not use an image list?... from the looks of things, this button will change its image somewhat often, and you will be constantly loading the image off the HD with your method.

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up Re: How would you do it?

    Duh. I should have thought of that.
    ~Peter


  5. #5

    Thread Starter
    Lively Member Xcoder's Avatar
    Join Date
    Jan 2004
    Posts
    120

    Re: How would you do it?

    Quote Originally Posted by kleinma
    why not use an image list?... from the looks of things, this button will change its image somewhat often, and you will be constantly loading the image off the HD with your method.
    Thanks I see your point, will test immediately.

    @MrGTI, thanks for the input

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How would you do it?

    Quote Originally Posted by MrGTI
    Duh. I should have thought of that.
    well in your defense.. out of his 2 original choices, I would have also picked the one you did

  7. #7

    Thread Starter
    Lively Member Xcoder's Avatar
    Join Date
    Jan 2004
    Posts
    120

    Re: How would you do it?

    Actually I thought of this afterwards, and it seems more logical for someone to read it like MrGTI proposes, although I did take out the '= true' part.

  8. #8
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Cool Re: How would you do it?

    Kleinma is right.... if you're going to be changing the image often, and only between a few "standard" images, then an image list is better - since you won't have an error in your app if the image is deleted from the hard drive.
    ~Peter


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