Results 1 to 4 of 4

Thread: which one to use?

  1. #1

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

    which one to use?

    I am doing some form validation and I simply want to check if a given text box was filled in.. doesnt matter with what.

    simple enough, I know... but which one of these methods for doing so would you say is the best. or is it all just preference?
    VB Code:
    1. txtName1.Text = String.Empty
    2.   txtName1.Text.Length = 0
    3.   Len(txtName1.Text) = 0
    4.   txtName1.Text = ""
    5.   txtName1.Text.Equals(String.Empty)

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I would say

    if txtName1.Text.Length = 0 then...

    is best because it's just fetching a property that is already known, rather than some of your other suggestions that have to do extra string comparison processing.


    $0.02
    I don't live here any more.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by wossname
    I would say

    if txtName1.Text.Length = 0 then...

    is best because it's just fetching a property that is already known, rather than some of your other suggestions that have to do extra string comparison processing.


    $0.02
    valid point. Although who knows what the code looks like in the get of the Length property... could be more (or just as) cumbersome than one of the other methods.. but to be honest, I guess all would be just fine..

    I guess am just trying to find the one I wont get laughed at for when a better coder looks at and says "what in the hell are you doing it this way for"

  4. #4
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    i usually just do
    = "" I learnt it that way from vb6 tho so i haven't changed. See no reason to, it does exactly the same.

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