Instr() Function Error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Instr() Function Error

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Instr() Function Error

    [Originally posted by Terry Ward]

    I am receiving the following error message when searching within the RichTextBox. Please help!

    ERROR:
    Runtime error '6'
    Overflow


    CODE:

    Private Sub FindText(ByVal start_at As Integer)

    Dim pos As Integer
    Dim target As String

    target = CStr(Search.Text)

    pos = InStr(start_at, CStr(Locator.Text), target)

    'MsgBox "" & pos

    If pos > 0 Then

    ' We found it.
    TargetPosition = pos
    Locator.SelStart = TargetPosition - 1
    Locator.SelLength = 68 'Len(target)

    'MsgBox "" & Locator.SelLength
    Else

    ' We did not find it.
    MsgBox "No more matches found.", 64, "Search Result"

    'Search.SetFocus

    End If

    End Sub

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Instr() Function Error

    [Originally posted by Jamie Pocock]

    Use this instead

    Private Sub FindText()
    Dim VArray() As String
    Dim HArray() As String
    Dim VRecCnt As Integer
    Dim HRecCnt As Integer
    Dim FoundStr As Boolean
    FoundStr = False
    VArray = Split(RTB.Text, vbCr, 200, vbTextCompare)
    VRecCnt = UBound(VArray) 'Put vertical(Row)splits into an array

    If Len(RTB.Text) > 0 Then
    For I2 = 0 To VRecCnt
    DoEvents
    HArray = Split(VArray(I2), " ", Len(RTB.Text), vbTextCompare) 'Split horizontal(Col) lines up in each vertical(Row) by splitting at vbTab
    HRecCnt = UBound(HArray) 'Put horizontal(Col) splits into an array
    For i1 = 0 To HRecCnt
    If InStr(1, LCase(HArray(i1)), LCase(CStr(Search.Text)), vbTextCompare) Then
    FoundStr = True
    RTB.SelStart = InStr(1, LCase(HArray(i1)), LCase(CStr(Search.Text)), vbTextCompare) - 1
    RTB.SelLength = Len(Search.Text)
    RTB.SetFocus
    End If
    Next i1
    Next I2
    End If

    If FoundStr Then
    MsgBox "Found"
    Else
    MsgBox "Not Found"
    End If

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center