Results 1 to 9 of 9

Thread: instr() error question *resolved*

  1. #1

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261

    Question instr() error question *resolved*

    The line
    VB Code:
    1. textlocation = InStr(start, text, test, vbTextCompare)
    produces an error, but I can't figure out why... This is part of a larger sub, but I don't want to bore you guys with that
    Does anyone know why this is giving an error ??


    VB Code:
    1. 'declarations'
    2. Dim dbase As Database
    3. Dim recset As Recordset
    4. Dim length As Integer
    5. Dim str As String
    6. Dim htmltag As String
    7. Dim str2 As String
    8. Dim result As String
    9. Dim textlocation As Long
    10. Dim start As Integer
    11. Dim endlocation As Long
    12.  
    13.  
    14. Set dbase = OpenDatabase(dblocation)
    15.  
    16. start = 0
    17. Do
    18.     'look for the space and replace with &nbsp tag'
    19.     test = Chr(32)
    20.     textlocation = InStr(start, text, test, vbTextCompare)
    21.     start = textlocation
    22.     'exit the do in case of nothing found. The 0 value would cause errors in the subsequent lines'
    23.     If textlocation = 0 Then
    24.         Exit Do
    25.     End If
    26.     'read the part before the space, the -1 ensures the space itself is not read'
    27.     str = Mid(text, 1, (textlocation - 1))
    28.     'read the part after the space, the +1 ensures the space itself is not read'
    29.     str2 = Mid(text, (textlocation + 1))
    30.     'insert the space tag in between'
    31.     text = str & " &nbsp " & str2
    32. Loop Until textlocation = 0
    Last edited by The Dutch Dude; Jul 2nd, 2002 at 09:25 AM.
    Obey the dragon thing. Or not. Or possibly just a bit.

  2. #2
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    I think because start = 0.
    I don't think you can start at position 0. It has to be position 1.

    Denk ik.

  3. #3
    Member otherones's Avatar
    Join Date
    Jun 2002
    Location
    Milk Factory
    Posts
    59
    If you are [start]ing at 0, you don't need to put anything in that argument so try:




    textlocation = InStr(text, test, vbTextCompare)
    CSC

  4. #4

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    damn! that fixed it..
    and the stupid thing is that in the mid() statements I DID use 1 as a start! Thanx allot!!
    Obey the dragon thing. Or not. Or possibly just a bit.

  5. #5

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    If you specify the compare you must also specify the start (or so my MSDN library says...
    And specifying it makes it easier to read, but that could just be me..
    Obey the dragon thing. Or not. Or possibly just a bit.

  6. #6
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Just a thought - why aren't you using the Replace function - it seems that you are finding spaces, and replacing them with something.

    In that case you can do

    Replace(ThisText," ","XX")

    which would replace all the spaces in This Text with XX
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  7. #7

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    because I kind of didn't know it exsisted...
    Sounds like a very handy thing.
    This replaces even more lines of code. Finding out instr() exsisted already trimmed the line count considerably

    That's what I love about programming: finding out that something exsists that makes you look like a complete gimp, but it is alse something you can't live without the moment you hear about it..
    Obey the dragon thing. Or not. Or possibly just a bit.

  8. #8

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    because I kind of didn't know it exsisted...
    Sounds like a very handy thing.
    This replaces even more lines of code. Finding out instr() exsisted already trimmed the line count considerably

    That's what I love about programming: finding out that something exsists that makes you look like a complete gimp, but it is alse something you can't live without the moment you hear about it..
    Obey the dragon thing. Or not. Or possibly just a bit.

  9. #9
    Lively Member
    Join Date
    Jun 2002
    Location
    Kuwait
    Posts
    85

    Re: instr() error question

    You start your search from the first character, i.e

    start=1
    Your attitude determines your altitude!!!

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