dcsimg
Results 1 to 6 of 6

Thread: (solved)auto fill data from Visual Studio on Internet Explorer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Posts
    20

    (solved)auto fill data from Visual Studio on Internet Explorer

    Hello, I'm veri new in Visual Studio.I have this code (code is for VBA EXCEL) that uses for open Internet Explorer and auto fill data for login in hotmail but this code not work in Visual Studio. It is Posible to change this code to work in Visual Studio wher I click CommandButton3 need to Open InternetExplorer and auto fill data.

    I tried to search on google but I could not solve this problem
    Thank You.

    Code:
    Private Sub CommandButton3_Click()
    
        Dim objIE As InternetExplorer
       
    
       Set objIE = New InternetExplorer
    
       objIE.Navigate "http://www.hotmail.com"
       objIE.Visible = True
         
      'Loop unitl ie page is fully loaded
       Do Until objIE.ReadyState = READYSTATE_COMPLETE
       Loop
       
       On Error Resume Next
       objIE.Document.getElementById("i0116").Value = TextBox25.Value 'username
       objIE.Document.getElementById("i0118").Value = TextBox1.Value 'password
    
       objIE.Document.getElementById("idSIButton9").Click
       
       Set objIE = Nothing
    
    
    End Sub
    Last edited by Johan_Rosu; Jun 13th, 2013 at 05:47 AM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: auto fill data from Visual Studio on Internet Explorer

    The reason why it won't work in visual studios is because you can think that visual basic for applications(VBA) is a completely different language than vb.net(Visual Basic.Net). However, if you already have the ElementId, it's very simple to convert. Replace the New InternetExplorer with New WebBrowser, as well as replacing the Set with Dim. Next remove the god awful On Errors, and the Do loop. Next replace TextBox.Value with TextBox.Text. Finally place that into a button's click event(just double-click on a button on your form).
    Last edited by dday9; Jun 10th, 2013 at 09:48 AM. Reason: Gramur n splling

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Posts
    20

    Re: auto fill data from Visual Studio on Internet Explorer

    Quote Originally Posted by dday9 View Post
    The reason why it won't work in visual studios is because you can think that visual basic for applications(VBA) is a completely different language than vb.net(Visual Basic.Net). However, if you already have the ElementId, it's very simple to convert. Replace the New InternetExplorer with New WebBrowser, as well as replacing the Set with Dim. Next remove the god awful On Errors, and the Do loop. Next replace TextBox.Value with TextBox.Text. Finally place that into a button's click event(just double-click on a button on your form).

    Hello I try to Convert but now problem is in this Lines Probelm 1 " Dim objIE As InternetExplorer" and Problem 2 is "Do Until objIE.ReadyState" = READYSTATE_COMPLETE"
    HTML Code:
    'Problem 1 is Here "InternetExplorer"
     Dim objIE As InternetExplorer
    
    
            objIE = New WebBrowser
    
            objIE.Navigate("http://www.hotmail.com")
            objIE.Visible = True
    
            '1 Problem 2 Is Here in "READYSTATE_COMPLETE"
            Do Until objIE.ReadyState = READYSTATE_COMPLETE
            Loop
    
            Resume Next
            objIE.Document.getElementById("i0116").Value = EmailTextBox1.Text 'username
            objIE.Document.getElementById("i0118").Value = PasswordTextBox1.Text 'password
    
            objIE.Document.getElementById("idSIButton9").Click()
    
            objIE = Nothing
    Please Help me to fix this code Thank You.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: auto fill data from Visual Studio on Internet Explorer

    For problem number one, replace As InternetExplorer with As WebBrowser. For problem number two, just remove the whole loop all together. Remove this whole bit:
    Code:
    '1 Problem 2 Is Here in "READYSTATE_COMPLETE"
            Do Until objIE.ReadyState = READYSTATE_COMPLETE
            Loop
    
            Resume Next
    Edit - Basically what your code is doing is:
    1) Declaring an instance of a webbrowser and making it a new instance here:
    Code:
    Dim objIE As WebBrowser
    objIE = New WebBrowser
    2) Navigating it to Hotmail.com here:
    Code:
    objIE.Navigate("http://www.hotmail.com")
    3) Setting the webbrowser's visibility to true here:
    Code:
    objIE.Visible = True
    4) Setting an element's value based on it's ID here:
    Code:
    objIE.Document.getElementById("i0116").Value = EmailTextBox1.Text 'username
    objIE.Document.getElementById("i0118").Value = PasswordTextBox1.Text 'password
    5) Clicking an element here:
    Code:
    objIE.Document.getElementById("idSIButton9").Click()
    6) Setting the webbrowser to nothing here:
    Code:
    objIE = Nothing
    Step 3 really isn't necessary as it's true by default and step 6 should be removed. If you want to properly get rid of the webbrowser then I'd use the Using statement, that away the webbrowser get's properly disposed when End Using is called.

    Just out of curiosity, why do you want somebody to type their username/password into a textbox and click a button in your program so that your program can do exactly that in the website? Wouldn't it be easier for the user to simply navigate to Hotmail and enter in all that information directly to Hotmail's website?
    Last edited by dday9; Jun 12th, 2013 at 08:59 AM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Posts
    20

    Re: auto fill data from Visual Studio on Internet Explorer

    Bicause I have 10 Email and have DataGridView and wher i click email in DataGridView textbox fill automatic not needet to write everi times. Thanks For Help.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: auto fill data from Visual Studio on Internet Explorer

    No problem, just be sure to mark the thread resolved if it's resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width