Results 1 to 3 of 3

Thread: Running default web browser from VB.

  1. #1

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    Hi there.
    I am using the follwoing line of code to execute web browser (IE or Netscape), but this doesn't work out on my PC bcoz I know that my IE 5 (Default browser) has some errors in it. But I have some softwares which load IE when executed.

    Public Sub gotoweb()
    Dim Ok As Long
    url = txtWebsite.Text
    Ok = ShellExecute(0&, vbNullString, url, vbNullString, "C:\", SW_SHOWNORMAL)
    End Sub

    Is there any other way to open Default web browser through VB?

    Thanks

    Kinjal

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ...try this out...

    'open a browser and go to a www address
    'bas module
    '
    Public Declare Function ShellExecute Lib _
    "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation _
    As String, ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Function ShellToBrowser%(Frm As Form, ByVal URL$, ByVal WindowStyle%)

    Dim api%
    api% = ShellExecute(Frm.hwnd, "open", URL$, "", App.Path, WindowStyle%)

    'Check return value
    If api% < 31 Then
    'error code - see api help for more info
    Dim msg As String
    msg = "This item doesn't work with your system"
    MsgBox msg, vbCritical, "Error"
    ShellToBrowser% = False
    ElseIf api% = 32 Then
    'no file association
    Dim msg1 As String
    msg1 = "This item doesn't work with your system"
    MsgBox msg, vbCritical, "Error"
    ShellToBrowser% = False
    Else
    'It worked!
    ShellToBrowser% = True

    End If

    End Function
    '

    '<<< event from application...click event of button >>>>>>>>
    '
    Private Sub cmdWeb_Click()
    Dim Site As String
    Dim success As Integer
    Site = "http://xi.fairnet.com/" '& Trim(txtWeb.Text)
    success% = ShellToBrowser(Me, Site, 0)
    End Sub

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    Thanks a lot. I'll try it out and tell you whether it works on my corrupted IE5 like other softwares.


    Kinjal

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