CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2000
    Posts
    14

    Calling INTERNET object in VB

    Hi,

    How do you call an instance of INTERNETEXPLORER in VB?

    eg Shell( " INTERNETEXPLORER.exe ") BUT in Windows the file name is not INTERNETEXPLORER, what is it??

    Also do we need to Declare the InternetExplorer Object, & how?

    Rgds


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Calling INTERNET object in VB

    dim ie as object
    set ie = createobject("InternetExplorer.Application")

    from now on use automation to trigger IE.


  3. #3
    Join Date
    Jan 2000
    Posts
    14

    Re: Calling INTERNET object in VB

    Hi,

    I coded IE Object, but it does not show up. Am I not using the Automation properly here to trigger IE.
    Also, do I need to declare something...before I can use events like
    IE_BeforeNavigate2 instead of WebBrowser1_BeforeNavigate2 (of WebBrowser Event Controls)


    Thanks






    Option Explicit
    Dim CONNECTED As Boolean
    Dim ie As Object


    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as string, you must pass it By Value.
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Const HKEY_LOCAL_MACHINE = &H80000002

    Public Function IsConnected() As Boolean
    Dim lRegKey As Long
    Dim bData(3) As Byte

    If RegOpenKey(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\RemoteAccess", lRegKey) = 0 Then
    'Opened RegKey Successfully..
    If RegQueryValueEx(lRegKey, "Remote Connection", 0&, 1&, bData(0), 4) = 0 Then
    'Query the Value of "Remote Connection" 1 - Connected, 0 - Not Connected
    IsConnected = bData(0)
    Else
    'Counldn't find the Value, assume no Connection
    IsConnected = False
    End If
    'Close the Registry Key
    Call RegCloseKey(lRegKey)
    End If
    End Function



    Private Sub Form_Load()
    Shell ("adialer.exe /d")
    Do
    CONNECTED = IsConnected()
    If CONNECTED = True Then
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Navigate "http://www.microsoft.com"
    End If
    Loop Until CONNECTED = True

    End Sub

    Private Sub ie_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    Shell ("adialer.exe /d")
    Do
    CONNECTED = IsConnected()
    Loop Until IsConnected() = True
    End Sub



  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: Calling INTERNET object in VB

    you need to set
    ie.visible = true
    to make IE visible.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: Calling INTERNET object in VB

    here is a complete sample


    option Explicit
    Dim withevents ie as InternetExplorer

    private Sub Command1_Click()
    set ie = new InternetExplorer
    ie.Visible = true
    ie.Navigate2 "yourURL"

    End Sub

    private Sub ie_DownloadComplete()
    MsgBox "downloaded"
    End Sub

    private Sub ie_NavigateComplete2(byval pDisp as Object, URL as Variant)
    MsgBox "navigated"
    End Sub





    watch the WithEvents in the Dim statement. You need that to trap the events.


  6. #6
    Join Date
    Jan 2000
    Posts
    14

    Re: Calling INTERNET object in VB

    Hi,

    Code is tidy.

    I use Visual Studio v.6 BUT had this Error Msg 430 below?!




    here is a complete sample



    option Explicit
    Dim withevents ie as InternetExplorer


    Private Sub Command1_Click()
    set ie = new InternetExplorerie ----->** ERROR 430 Doesn't support Automation
    ie.Visible = true or Not expecting this class** interface
    ie.Navigate2 "yourURL"
    End Sub

    private Sub ie_DownloadComplete()
    MsgBox "downloaded"
    End Sub

    private Sub ie_NavigateComplete2(byval pDisp as Object, URL as Variant)
    MsgBox "navigated"
    End Sub


    watch the WithEvents in the Dim statement. You need that to trap the events.




  7. #7
    Join Date
    May 1999
    Posts
    3,332

    Re: Calling INTERNET object in VB

    sorry, you need to add a reference to shdocvw.dll to make it work.
    That DLL contains the InternetExplorer "object".


  8. #8
    Join Date
    Jan 2000
    Posts
    14

    Re: Calling INTERNET object in VB

    Hi,

    complete sample below


    Option Explicit
    Dim CONNECTED As Boolean
    Dim WithEvents ie As InternetExplorer



    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as string, you must pass it By Value.
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Const HKEY_LOCAL_MACHINE = &H80000002

    Public Function IsConnected() As Boolean
    Dim lRegKey As Long
    Dim bData(3) As Byte

    If RegOpenKey(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\RemoteAccess", lRegKey) = 0 Then
    'Opened RegKey Successfully..
    If RegQueryValueEx(lRegKey, "Remote Connection", 0&, 1&, bData(0), 4) = 0 Then
    'Query the Value of "Remote Connection" 1 - Connected, 0 - Not Connected
    IsConnected = bData(0)
    Else
    'Counldn't find the Value, assume no Connection
    IsConnected = False
    End If
    'Close the Registry Key
    Call RegCloseKey(lRegKey)
    End If
    End Function



    Private Sub Form_Load()
    Shell ("adialer.exe /d")

    Do
    CONNECTED = IsConnected()
    If CONNECTED = True Then


    Set ie = New InternetExplorer **ERROR MSG 430 **
    ie.Visible = True
    ie.Navigate "http://www.microsoft.com"
    End If
    Loop Until CONNECTED = True

    End Sub




    Private Sub ie_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    Shell ("adialer.exe /d")
    Do
    CONNECTED = IsConnected()
    Loop Until IsConnected() = True
    End Sub


  9. #9
    Join Date
    Jan 2000
    Posts
    14

    Re: Calling INTERNET object in VB

    Hi,

    same Error Msg 430 after replacing INTERNETEXPLORER with SHDocVwCt1.INTERNETEXPLORER.
    Pls show REFERENCE codes for SHDocVwCt1.

    OR perhaps we need to create an EVENT SINK, & hook the EVENT SINK with an instance of the INTERNETEXPLORER??



    option Explicit
    Dim withevents ie as SHDocVwCtl.InternetExplorer

    private Sub Command1_Click()
    set ie = new SHDocVwCtl.InternetExplorer **ERR MSG 430 **

    ie.Visible = true
    ie.Navigate2 "yourURL"
    End Sub

    private Sub ie_DownloadComplete()
    MsgBox "downloaded"
    End Subprivate Sub

    ie_NavigateComplete2(byval pDisp as Object, URL as Variant)
    MsgBox "navigated"
    End Sub





  10. #10
    Join Date
    Jan 2000
    Posts
    14

    Re: Calling INTERNET object in VB

    Hi,


    Thanks very much, WELL DONE! It works after I click on Reference Command (instead of Component Command)in Project Menu, Scroll to Microsoft internet Control (shdocvw.dll) reference & check the check box.


    Rgds


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

Featured