|
-
February 16th, 2000, 10:50 PM
#1
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
-
February 17th, 2000, 02:19 AM
#2
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
-
February 17th, 2000, 08:06 AM
#3
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.
-
February 17th, 2000, 10:37 AM
#4
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
-
February 17th, 2000, 11:01 AM
#5
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
-
February 17th, 2000, 11:03 AM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|