473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InStr test

hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?

thanks,
rodchar
Nov 7 '06 #1
12 2966
kpg
As =?Utf-8?B?cm9kY2hhcg= =?= once said in
microsoft.publi c.dotnet.framew ork.aspnet
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?
Yes. You are not using the wrong syntax for Instr.

I surprised this even compiles.
Nov 7 '06 #2
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:8A******** *************** ***********@mic rosoft.com...
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?
Er, well it's been a while since I've used any flavour of Basic, but doesn't
InStr require more than one argument...?

Switch Option Strict on...
Nov 7 '06 #3
"kpg" <no@way.comwrot e in message
news:Xn******** *************** ********@207.46 .248.16...
Yes. You are not using the wrong syntax for Instr.
I think the OP *is* using the wrong syntax for InStr...
I surprised this even compiles.
I bet it doesn't...
Nov 7 '06 #4
Try this:

If InStr("test1")> =0 and InStr("test2")> =0 Then

Also, to add efficiency you should use AndAlso instead of And.

--
I hope this helps,
Steve C. Orr
MCSD, MVP, CSM
http://SteveOrr.net
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:8A******** *************** ***********@mic rosoft.com...
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?

thanks,
rodchar

Nov 7 '06 #5
rodchar wrote:
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?

thanks,
rodchar
The first reason is that the code will not compile at all. The InStr
function requires two parameters.

Furthermore, the InStr function returns an integer, not a boolean. If
you use the and operator between two integers, it will perform a binary
and between the operators. With your example, the first InStr returns
the value 1 and the second returns the value 8. The binary and operation
between 1 and 8 gives the value 0. That is then converted to the boolean
value False when it's used in the If statement.
Nov 8 '06 #6
"Steve C. Orr [MVP, MCSD]" <St***@Orr.netw rote in message
news:O5******** *****@TK2MSFTNG P04.phx.gbl...
If InStr("test1")> =0 and InStr("test2")> =0 Then
Does that even compile...?
http://msdn.microsoft.com/library/de...vafctinstr.asp
Nov 8 '06 #7
Hi,

rodchar wrote:
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?
what exactly are you wanting to do?
Using InStr, you can look for the position of the first occurance of a
string within another, starting at a certain position within the string.

dim strLookFor as string="test"
If (InStr(1, "test1", strLookFor)+InS tr(1, "test2", strLookFor))>0 Then
'Inside
EndIf

BTW - instead of InStr, you may as well use the IndexOf-function which is a
member of system.string. IOW, if you are checking a string-variable, use
strYourString.I ndexOf(...).

Guess it'd be better if you explained what exactly you're looking for.

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 8 '06 #8
kpg
As Mark Rae once said in microsoft.publi c.dotnet.framew ork.aspnet
>Yes. You are not using the wrong syntax for Instr.

I think the OP *is* using the wrong syntax for InStr...
! um, yes, that's what I meant...
Nov 8 '06 #9
My apologies to everyone i should have state that i was not strict on syntax
and i was focused more on the concept of this:
I thought, 0 meant false and >0 meant true without having to be explicit.

If I'm explicit like you, it works:
If InStr("test1")> =0 and InStr("test2")> =0 Then
....
"Steve C. Orr [MVP, MCSD]" wrote:
Try this:

If InStr("test1")> =0 and InStr("test2")> =0 Then

Also, to add efficiency you should use AndAlso instead of And.

--
I hope this helps,
Steve C. Orr
MCSD, MVP, CSM
http://SteveOrr.net
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:8A******** *************** ***********@mic rosoft.com...
hey all,
i'm getting a result that i don't understand

i have a string "test1, test2"

If InStr("test1") and InStr("test2") Then
'Inside
EndIf

The inside is not running for some reason. Any ideas?

thanks,
rodchar


Nov 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
309877
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide some key functionality I need. Here is an example of the Oracle code: if Instr( sTg , cDelim, 1, 3 ) > 0 then sd := SubStr( sTg, Instr( sTg , cDelim, 1, 1 ) + 1, Instr( sTg, cDelim, 1, 2 ) - Instr( sTg , cDelim, 1, 1 ) - 1)
5
189330
by: Jim | last post by:
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be appreciated. Is there a tutorial on string maniputation using C# in ASP.net ? Thanks, Jim
5
24961
by: PJSimon | last post by:
Let's say I want to find the occurance of SearchString in MyString, but I want to search without regard to case ... Which is better and why in VB.Net? Index = Instr(MyString, SearchString) - 1 or Index = MyString.ToUpper.IndexOf(SearchString.ToUpper)
6
4000
by: Chris Calzaretta | last post by:
Hello Everybody, Question instr function will give you the first instance of the finding so EX: so your string looks like string1 = "testing>This is > just a test > testtesttest" instr(string1,">")
4
1983
by: Gordon | last post by:
Hi; I am trying to extract a substring using a combination of the mid() and Instr() i.e. aString = "Jones, Thomas R, Dr." hold = InStr(1, aString, " ," , 1) newString = Mid(aString, 1, hold) + Mid(aString, hold + 2, InStr(hold + 1,
3
2590
by: Mary | last post by:
MemberID VID 1002 1001 1003 1002 1004 1003 1005 1003 1007 1001 1012 1002 <% MemberList = "1001, 1003, 1002"
4
3912
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field. ie "McCarthy,John Doe Willy". I have to split up Familyname and the 1st FirstName. The FamilyName works perfect, just looking up the comma with InStr and use Left(). Now can someone throw me a bone to help me get the 1st Firstname. "John" according...
3
2621
by: lstrudeman | last post by:
Hello; A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and breaks apart the pieces of the key for other uses. The field looks like this 1234567*AWD*07FA (or 1234567*FPER*07FA). I just need to understand how the numbers behind the TA_2007_ID field work to break apart they key?? The first one is easy.. it just...
3
2238
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to get this to only run on NON MISSING Project Dates? Thanks! Alex
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.