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
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)
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..
Re: Index was outside the bounds of the array
I don't know what exactly you are doing to fill the strText string, so I can't help you on that. All I know is that you should make sure the array contains a third item before using it.
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