Results 1 to 6 of 6

Thread: please tell me how to use Instr() function?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    VIETNAM
    Posts
    209

    please tell me how to use Instr() function?

    Would you mind telling me how to find out if the string i type in the textbox contains the word "name" or not?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    This really doesn't need to be in the API section, because InStr() (and what you are asking) isn't related to API.


    VB Code:
    1. If (InStr(1, string, "name", vbBinarCompare) > 0) Then
    2.     'its there
    3. End If

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by «°°phReAk°°»
    This really doesn't need to be in the API section, because InStr() (and what you are asking) isn't related to API.


    VB Code:
    1. If (InStr(1, string, "name", vbBinarCompare) > 0) Then
    2.     'its there
    3. End If

    Phreak
    Just a typo I guess but it's vbBinaryCompare


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315
    It can be used like Phreak and Manavo11 said:

    VB Code:
    1. If (InStr(1, string, "name", vbBinaryCompare) > 0) Then
    2.     'its there
    3. End If

    But it can be used also like this:

    VB Code:
    1. Dim FindString as integer
    2. FindString = Instr (1 , string, "name")
    3. Do While FindString > 0
    4. 'Do something when is > 0
    5. FindString = Instr (1 , string, "name")
    6. Loop


    I know that i am saying the same as Phreak and Manavo11 said but in my opinion it is better using Do...Loop and not If...Else..End If!

    Sorry guys!

    Also can i make a question?
    "Why to use this:InStr(1,string , "name" , vbBinaryCompare) and not this: InStr (1, string, "name"), isn't the same thing?
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    vbBinaryCompare and vbTextCompare

    If you use InStr() to search for, "name", it will also find:

    "name" "NAME" "nAME" "NaMe"...

    But if you use vbBinaryCompare, it will find the EXACT string:

    VB Code:
    1. InStr(1, "Enter name:", "name", vbBinaryCompare)

    That will only find "name", and not "NAME" "NaMe" or any other combination.

    PS: Im not at home atm, so thats why im not on MSN


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315
    Ok! Thanks Phreak!

    See u on MSN , when u will return!
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width