Results 1 to 3 of 3

Thread: strings

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    strings

    I have a sort of interesting task. I have text loaded where I must find a certain line that starts with a certain word and then from there parse out a piece. This what I got. It find the positions ok but Im confused about having it start at the specified line and then finding the piece to parse.It hits a error where retval is (error 5) All it has to do is count the number of occurences. here's the code

    Code:
    hum = InStr(1, searchstring, "Human", vbTextCompare)
    
    Do
        hum = InStr(hum + 1, searchstring, "Human", vbTextCompare)
            ReDim Preserve humpos(humcount)
            humpos(humcount) = hum
            humcount = humcount + 1
    Loop While hum <> 0
    
    counter2 = 0
    
    For i = LBound(humpos) To UBound(humpos)
        retval = InStr(humpos(i), searchstring, find, vbTextCompare)
            Debug.Print
            If retval Then
                counter2 = counter2 + 1
            End If
    Next i
    
    Debug.Print counter2
    Matt

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    This worked fine for me...

    Code:
    Private Sub Form_Load()
    Const searchstring = "Human is a Human for Humans to Human powere Human Human oifh ajsdhfsa sfouash ukshcfas Human"
    Dim humpos() As Long
    hum = InStr(1, searchstring, "Human", vbTextCompare)
    
    Do
        hum = InStr(hum + 1, searchstring, "Human", vbTextCompare)
            ReDim Preserve humpos(humcount)
            humpos(humcount) = hum
            humcount = humcount + 1
    Loop While hum <> 0
    
    counter2 = 0
    
    For i = LBound(humpos) To UBound(humpos)
        retval = InStr(humpos(i), searchstring, find, vbTextCompare)
            If retval Then
                counter2 = counter2 + 1
            End If
    Next i
    
    Debug.Print counter2
    
    End Sub
    What are your DECLARATIONS and SEARCHSTRING?


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    I have everything declared but did not post it
    What does it return when you run it?
    Matt

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