Results 1 to 5 of 5

Thread: Very Simple Instr malfunction

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    2

    Question Very Simple Instr malfunction

    Public global_searchstring As String

    Code:
    some_first_sub
    
    form_number_str = textbox3.text ' form_number_str is successfully filled verified by debugger
    'form_number_str successfully equals "pa600"
    end sub

    Code:
    some_second_sub()
    
    global_searchstring = some_html_document with lots of text '  global_searstring returns successully filled verified by debugger
    
    end sub


    Code:
    Function get_app_status() As String
    
    
    Dim pos16 As Long
    Dim teststr As String
    
    pos16 = InStr(1, "jklo>pa600<", form_number_str) 'returns successfully position 5
    pos16 = InStr(1, global_searchstring, form_number_str) ' erroneouslly returns 0........... WHY???????????:ehh::confused:
    TextBox1.Text = global_searchstring ' successfully fills textbox with entire global_searchstring including "pa600"
    teststr = TextBox1.Text ' successfully assigns teststr = global_searchstring
    TextBox2.Text = teststr ' successfully fills textbox2 with teststr including "pa600"
    pos16 = InStr(1, teststr, form_number_str) ' erroneouslly returns 0...... WHY???????????:ehh::confused:
    
    
    end function

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Very Simple Instr malfunction

    Hello and welcome to the forums. All i see is code and no question. What is your question. Most members here tell you NOT to use vb run time functions such as instr.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Very Simple Instr malfunction

    Ident missed the fact that all your questions are comments in your code, which is easy to do. InStr is a legacy function, as he noted. I haven't used it in over a decade, so whether or not it has any quirks I couldn't say. One option is to try:

    pos16 = teststr.IndexOf(form_number_str)

    That would be the more modern equivalent. Another alternative would be to use RegEx, but it doesn't seem like it would be needed for this.
    My usual boring signature: Nothing

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Very Simple Instr malfunction

    I didn't miss it. I did not read it since i want members to take the time to write in full. SH your a regular member. If you had to read each members code searching for whats wrong you would be a busy many here. More then you already are.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Very Simple Instr malfunction

    I deny that I am regular....unfortunately, I also deny that I am busy at the moment. I've managed to return to a curiously empty plate, though that will change in the next few days.

    I actually read through the post and didn't even realize that the question was in the code until I read your response. I agree that it could be written more clearly with an actual text question, but I got wrapped up in the suspense and was wondering what a cryptic string of characters such as pa600 could mean. It was like some kind of mystery...such as you might find on the back of a cereal box (short and decidedly odd). Unfortunately, there was no resolution.

    Still, you are right that the question should have been more plainly stated, and you are right that the problem could be InStr itself, but it could turn out to be a curious problem in the end.
    My usual boring signature: Nothing

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