Results 1 to 5 of 5

Thread: Index was outside the bounds of the array

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Index was outside the bounds of the array

    This is my function

    Code:
    	Public Function GetText(ByRef Get_hWnd As Integer) As String
            'Dim retVal As Integer
    		Dim lenTxt As Short
    		Dim retText As String
    		lenTxt = SendMessageLong(Get_hWnd, WM_GETTEXTLENGTH, 0, 0)
    		retText = New String(" ", lenTxt + 1)
    		Call SendMessageByString(Get_hWnd, WM_GETTEXT, lenTxt + 1, retText)
    		GetText = Left(retText, lenTxt)
    	End Function
    and this is the line of code i have

    Code:
    		Dim click_Renamed As Short
    		Dim SplitSplit() As String
    		Dim TheUsername As String
            Dim splitArr() As String
    		Dim TheText As String
            Dim intCount As Short
    		
            lngHandles = FindWindow("#32770", "Window")
    		
    		If lngHandles = 0 Then Exit Sub
    		
            lngHandle = FindWindowEx(lngHandles, 0&, "Static", vbNullString)
    		strText = GetText(lngHandle)
    		lngHandleButton = FindWindowEx(lngHandles, 0, "Button1", vbNullString)
    		
    		splitArr = Split(strText, Chr(9))
    		intCount = UBound(splitArr)
            SplitSplit = Split(splitArr(3), Chr(10))
    		
    		TheUsername = Trim(SplitSplit(0))
    		TheText = splitArr(intCount)
    		
    		My.Computer.Clipboard.Clear()
    		
    		If optGetID.Checked = True Then
    			My.Computer.Clipboard.SetText(TheText)
    		ElseIf optGetPerson.Checked = True Then 
    			My.Computer.Clipboard.SetText(TheUsername)
    		Else
    			MsgBox("Choose it first")
    		End If
    		
    		click_Renamed = SendMessage(lngHandleButton, WM_KEYDOWN, VK_SPACE, 0) 'sends a left button down
    		click_Renamed = SendMessage(lngHandleButton, WM_KEYUP, VK_SPACE, 0) 'sends a left button up
    	End Sub
    This is supposed to get information of an window that appears after right clicking on a person but i get Index was outside the bounds of the array error on SplitSplit = Split(splitArr(3), Chr(10))

    Anyone can help ?

    thanks in advance

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Index was outside the bounds of the array

    Apparently, splitArr does not contain any item with index 3. That means it has only 3 (or less) items (0, 1, 2).

    Put a breakpoint (click on the area on the left of your code until a red dot appears) on the "splitArr = Split(strText, Chr(9))" line. Look what strText contains, and then press F8 to move the code one step further. Now look what splitArr contains (especially how many items).

    Finally, you should use the VB.NET way of splitting:
    Code:
    splitArr = strText.Split(separator)

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Re: Index was outside the bounds of the array

    i actually did that ..putting a breakpoint and it doesnt contain anything. i guess i m doing something wrong in the code and its frustrating if you know what i mean..

  4. #4

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Re: Index was outside the bounds of the array

    what im trying to do is, every person has unique ID, if you right click on the and choose Show ID, it brings up the ID number and person's name..

    i got the handle and class name right i am sure of that

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