|
-
Mar 5th, 2004, 03:52 PM
#1
Thread Starter
New Member
InStr
S = "[test]"
If InStr(S, "[") And Instr(S, "]") then
B = True
Else
B = False
EndIf
In VB6 B = True, in .Net B = False
Can someone explain why?
Thanks,
Robb
-
Mar 5th, 2004, 04:36 PM
#2
Sleep mode
Did you try this and gives you the same result ?
VB Code:
S = "[test]"
If InStr(S, "[") And[B]Also[/B] Instr(S, "]") then
B = True
Else
B = False
EndIf
-
Mar 5th, 2004, 05:03 PM
#3
take a look at the IndexOf property , it replaces the InStr of vb6 , eg:
VB Code:
Dim s As String = "[test]"
Dim b As Boolean = False
If Not s.IndexOf("[") = -1 AndAlso Not s.IndexOf("]") = -1 Then
b = True
Else
b = False
End If
MessageBox.Show(b)
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Mar 8th, 2004, 08:16 AM
#4
Thread Starter
New Member
AndAlso makes it work.
I also found that:
If InStr(S, "[") > 0 And Instr(S, "]") > 0 then
works as well.
I didn't try the Not Index of -1 version. I am assuming it will work also because of the AndAlso instead of the And.
So can anyone tell me why the original works in VB but to get the same code to work in .net I have to explicitly say 'is greater than 0' or change the wording from And to AndAlso ?
The reason may become important in other scenarios down the road.
Thanks,
Robb
-
Mar 8th, 2004, 08:20 AM
#5
Conquistador
InStr returns the position of the character or -1 if it's not in the haystack.
in vb6
VB Code:
S = "[test]"
If InStr(S, "[") And Instr(S, "]") then
B = True
Else
B = False
EndIf
you'll find that B will always be false~
-
Mar 8th, 2004, 08:21 AM
#6
Conquistador
Also
Code:
If Not s.IndexOf("[") = -1 AndAlso Not s.IndexOf("]") = -1 Then
would work regardless of whether it's AndAlso or And
-
Mar 8th, 2004, 09:50 AM
#7
Thread Starter
New Member
I see it now.
Thanks for setting me straight.
-
Mar 8th, 2004, 08:18 PM
#8
Sleep mode
Check MSDN Help for the differences between And and AndAlso .
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
|