Results 1 to 4 of 4

Thread: [RESOLVED] [Help]instr returning Wrong value?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    35

    Resolved [RESOLVED] [Help]instr returning Wrong value?

    Im having a problem with instr Its simply put, returning an unexpected value. I search for the position of 2 characters "(" and ")".

    String Im using instr on
    Code:
    INSERT INTO Drop_Data (dropperid, itemid, minimum_quantity, maximum_quantity, questid, chance) VALUES
    now the "(" returns the correct position of 23.

    However when instr looks for ")" it finds it incorrectly at position 94

    Code:
           If fline = 1 Then
                    TextOutPut(0) = ttext & vbCrLf
                    a = InStr(1, TextOutPut(0), "(")
                    b = InStr(1, TextOutPut(0), ")")
                    Debug.Print ttext
                    ttext = Mid(TextOutPut(0), a, b)
                    Debug.Print ttext
                End If
    thats the code im using right now I need ttext to be equal to the data inside the "(" and ")". Anyone got any ideas why instr isnt working?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [Help]instr returning Wrong value?

    I wouldn't be so sure about Instr not working properly, what I would be concerned about is the parameters you are passing to Mid:
    Code:
                    ttext = Mid(TextOutPut(0), a, b)
    The third parameter is not the end position, it is the amount of characters from the start position.

    For example: If a contained 2 and b contained 3, you would get 3 characters starting at character 2 (so the 2nd, 3rd, and 4th characters).

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [Help]instr returning Wrong value?

    in other words, instr is returning the correct position. ) is at the 93rd position in the original string... if you want to get it relative to the start position, you need to take that into account
    Code:
    ttext = Mid(TextOutPut(0), a, b-a)
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    35

    Re: [Help]instr returning Wrong value?

    Whoops Lol Thanks. Normally I only read 1 letter with mid so I wasnt thinking

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