|
-
Sep 7th, 2008, 04:23 PM
#1
Thread Starter
Addicted Member
How do I see if a textbox contains this OR contains that properly?
I have this code driving a validator:
Code:
If TextBox1.Text.Contains(".urw") Or TextBox1.Text.Contains(".URW") = False Then
TextBox2.AppendText("Input file is not a valid. Please try again.")
But I also have an opposite one under the "true" condition.
However, no matter what I do, my utility only validates ".URW" correctly and not ".urw".
Does anybody know why?
-
Sep 7th, 2008, 04:33 PM
#2
Re: How do I see if a textbox contains this OR contains that properly?
shouldn't that be:
vb Code:
If TextBox1.Text.Contains(".urw") = False and TextBox1.Text.Contains(".URW") = False Then
TextBox2.AppendText("Input file is not a valid. Please try again.")
???
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2008, 04:58 PM
#3
Thread Starter
Addicted Member
Re: How do I see if a textbox contains this OR contains that properly?
Nope still getting the error 
I've also tried replacing the "and"s with "or"s
-
Sep 7th, 2008, 05:19 PM
#4
Re: How do I see if a textbox contains this OR contains that properly?
are you sure you're using it correctly? theres no reason it shouldn't work
vb Code:
If not TextBox1.Text.Contains(".urw") and not TextBox1.Text.Contains(".URW") Then
TextBox2.AppendText("Input file is not a valid. Please try again.")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2008, 05:22 PM
#5
Thread Starter
Addicted Member
Re: How do I see if a textbox contains this OR contains that properly?
I need to validate files that end with wither .urw or .URW.
-
Sep 7th, 2008, 05:23 PM
#6
Re: How do I see if a textbox contains this OR contains that properly?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2008, 05:27 PM
#7
Re: How do I see if a textbox contains this OR contains that properly?
vb Code:
If not TextBox1.Text.Contains(".urw") and not TextBox1.Text.Contains(".URW") Then
TextBox2.AppendText("Input file is not a valid file. Please try again.")
else
'file is valid
end if
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2008, 05:40 PM
#8
Re: How do I see if a textbox contains this OR contains that properly?
You should be using AndAlso and OrElse rather than And and Or, as they work better. In the first example, it may be that it was being evaluated in this fashion:
(contains(A) or contains(B)) = False
My usual boring signature: Nothing
 
-
Sep 7th, 2008, 06:44 PM
#9
Re: How do I see if a textbox contains this OR contains that properly?
Code:
If TextBox1.Text.Contains(".urw") OrElse TextBox1.Text.Contains(".URW") Then
Debug.WriteLine("TextBox1 contains .urw or .URW")
Else
Debug.WriteLine("TextBox1 does not contain .urw or .URW")
End If
'or
If Not (TextBox1.Text.Contains(".urw") OrElse TextBox1.Text.Contains(".URW")) Then
Debug.WriteLine("TextBox1 does not contain .urw or .URW")
Else
Debug.WriteLine("TextBox1 contains .urw or .URW")
End If
this
If TextBox1.Text.Contains(".urw") Or TextBox1.Text.Contains(".URW") = False Then
should only catch ".urw", at least that is what it did on my PC.
It is hard to know what you are trying to test for? Is it
.urw or .URW are valid?
.urw is valid but .URW isn't and vice versa.
Last edited by dbasnett; Sep 7th, 2008 at 06:48 PM.
-
Sep 8th, 2008, 02:27 AM
#10
Re: How do I see if a textbox contains this OR contains that properly?
Do you really want to limit the user to all upper case or all lower case? Should case matter at all?
vb.net Code:
If Me.TextBox1.Text.IndexOf(".urw", StringComparison.CurrentCultureIgnoreCase) = -1 Then
-
Sep 8th, 2008, 03:29 AM
#11
Re: How do I see if a textbox contains this OR contains that properly?
Or
Code:
If Me.TextBox1.Text.ToLower().Contains(".urw") Then
-
Sep 8th, 2008, 08:10 AM
#12
Re: How do I see if a textbox contains this OR contains that properly?
If you want to check for a certain file extension, don't use String.Contains method. It can give you false result. For example, if the textbox.text = "C:\Test\myfile.urw.txt", the actual file extension in this case is .txt yet string.contains will still return true since the file path does contain ".urw".
You should use System.IO.Path.GetExtension(filePath) to get the file extension and test to see if it is ".urw", something like this:
Code:
Dim filePath As String = TextBox1.Text
Dim ext As String = System.IO.Path.GetExtension(filePath).ToLower()
If ext <> ".urw" Then
TextBox2.AppendText("Input file is not a valid. Please try again.")
Else
'The file extension is valid, do whatever desired here
End If
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
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
|