Click to See Complete Forum and Search --> : IsEmpty()


wwc_um
February 16th, 2000, 09:50 PM
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

Lothar Haensler
February 17th, 2000, 01:19 AM
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

Kyle Burns
February 17th, 2000, 07:06 AM
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.

The Matrix
February 17th, 2000, 09:37 AM
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

Chris Eastwood
February 17th, 2000, 10:01 AM
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

Cakkie
February 17th, 2000, 10:03 AM
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
slisse@planetinternet.be

The best way to escape a problem, is to solve it.