Error in Function, System.IndexOutOfRangeException

-1

I'm doing a login system, when I click the start button it starts the following code:

 Function Prencher2()

    Dim line() As String
    Dim emailsenha As String = List.Lines(0)
    line = Split(emailsenha, "|")
    Me.WebBrowser1.Document.GetElementById("liubw-user").SetAttribute("value", line(0))
    Me.WebBrowser1.Document.GetElementById("liubw-password").SetAttribute("value", line(1))
    Me.WebBrowser1.Document.GetElementById("liubw-submit").InvokeMember("click")
    WaitForPageLoad()
    Verificar()

End Function

NOTE: List is the name of the textbox

In case it will put the email and password that is in the textbox and will click the enter button. I'm using the Function method because it's much faster to do what I want, but in the emailsenha As String = List.Lines(0) part it gives the System.IndexOutOfRangeException error: 'The index was outside the bounds of the array.'

What can I do to fix this? All my codes are correct because I already tested them manually.

    
asked by anonymous 16.05.2017 / 22:52

1 answer

0

I took your code and tested it locally, and it works normally, the problem that in your test, you should be sending an empty value, so this is giving the error, I think I'd better put an if to check if what is coming of the textBox is empty, place before the line:

Dim emailsenha As String = List.Lines(0)
    
19.05.2017 / 15:26