CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: IsEmpty()

  1. #1
    Join Date
    Jan 2000
    Posts
    24

    IsEmpty()

    txtTrgPath.text is a text box where I type in the pathname. I wanna to check whether the textbox is empty or not. I'm using the isEmpty function as stated below, but I keep receiving the message "Path is not empty" even though I typed or didn't type in the path name. And, how to check whether the pathname I typed in is exist or not, if doesn't exist, how can I create the the directory.

    If Not IsEmpty(txtTrgPath.Text) Then
    MsgBox "Path is not empty"
    else
    MsgBox "Path empty"
    End If


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: IsEmpty()

    to check a textbox for "emptyness":
    if text1.text = "" then
    msgbox "empty
    end if

    to check if directory exists:
    If Dir("c:\winnt", vbDirectory) = "" Then
    ' doesn't exist


  3. #3
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: IsEmpty()

    The reason your control's .Text is not empty is because .Text has a data type of String. To my knowledge, the only data type that can be empty is a Variant. What you need to be concerned with is whether you have a zero-length String in this control. You can do what has been suggested and check to see if it is equal to "", but this is not the most efficient way to check. When you check against "", a new String is created in memory with the contents "". The value of the .Text property is checked against this new String. The constant vbNullString is a zero-length String that is automatically created by VB and checking against this doesn't allocate more memory for the variable. It won't be a huge difference (or even much of a tiny one), but I prefer to write as efficient code as I know how.


  4. #4
    Join Date
    Feb 2000
    Location
    garden grove, california
    Posts
    64

    Re: IsEmpty()

    Private Sub Command1_Click()
    Dim str As String
    If Text1 <> str Then
    MsgBox "text1 has something in it"
    Else
    MsgBox "nothing in text1!"
    End If
    End Sub



  5. #5
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: IsEmpty()

    Or...


    private Sub Command1_Click()
    '
    ' Check for empty
    '
    ' Dim bIsEmpty as Boolean
    ' bIsEmpty = len(Text1.Text)=0
    '
    MsgBox "Text 1 is " & IIf(len(Text1.Text) = 0, "empty", "Not empty")
    '
    End Sub





    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  6. #6
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: IsEmpty()

    You are just making things harder then they are. Why first declare a string, f you could use ""? Well, i'm sure it works, but why the hard way if the easy way works better. Besides, what are you goint to do if the value of str changes before the check is performed?

    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured