# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  vb web browser tutorial

## zeidhaddadin

*UPDATED ON 18/6/2006*

In this thread i'm going to talk about all the things that you might need in building an internet web browser using visualbasic component.

*1- Adding components:*

Go to "Project" on the top menu, and choose "Components" or click CTRL-T, then check "Microsoft html object library" and "Microsoft internet controls" and "Microsoft Windows common Controls 5.0".

You will see that new objects are appearing in the left box of your menu, now choose the webbrowser icon which looks like an earth and add it to your form, and make its size as you want, (its name is WebBrowser1 in this tutorial)

Also click on the "Progress bar" component and add it to your form.

*2- Adding buttons and objects:*

Now add the "6" essential command buttons to your form, and name them as the following: "Back","Forward","Stop","Refresh","Home" and "GO", Now add 1 combo box which the user will enter the web address on it.

*3- Coding your application:*

First click on the "GO" button and write this code inside it: 

VB Code:
WebBrowser1.Navigate Combo1

Now We will code the other buttons as the following:

Back button: 


VB Code:
On Error Resume Next
WebBrowser1.GoBack

Forward button: 
VB Code:
On Error Resume Next
WebBrowser1.GoForward

Stop button: 
VB Code:
On Error Resume Next
WebBrowser1.Stop

Refresh button: 
VB Code:
WebBrowser1.Refresh

Home button: 
VB Code:
WebBrowser1.GoHome

NOW YOU CAN TRY USING YOUR NEW WEB BROWSER.

*4- Advanced codes:*

You can add the following codes to your application to make it work better, Just place these codes anywhere in your coding window.

* Add a progress bar


VB Code:
'This to make the progress bar work and to show a status message, and an image.
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
On Error Resume Next
    If Progress = -1 Then ProgressBar1.Value = 100 'the name of the progress bar is "ProgressBar1".
        Label1.Caption = "Done"
        ProgressBar1.Visible = False 'This makes the progress bar disappear after the page is loaded.
        Image1.Visible = True
    If Progress > 0 And ProgressMax > 0 Then
        ProgressBar1.Visible = True
        Image1.Visible = False
        ProgressBar1.Value = Progress * 100 / ProgressMax
        Label1.Caption = Int(Progress * 100 / ProgressMax) & "%"
    End If
    Exit Sub
End Sub

But here you will need to add an label which is called "Label1" and also an small image such as a smile or earth or anything you want and the name is "image1" 

* Open in new window


VB Code:
'This to open a new window with our browser.
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As Form1
Set frm = New Form1
Set ppDisp = frm.WebBrowser1.Object
frm.Show
End Sub

This to open the new window with your browser.


* History and current visited site.


VB Code:
'This keeps the visited sites history and also changes the title of the browser as the page title.
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    On Error Resume Next
    Dim i As Integer
    Dim bFound As Boolean
    Me.Caption = WebBrowser1.LocationName
    For i = 0 To Combo1.ListCount - 1
        If Combo1.List(i) = WebBrowser1.LocationURL Then
            bFound = True
            Exit For
        End If
    Next i
    mbDontNavigateNow = True
    If bFound Then
        Combo1.RemoveItem i
    End If
    Combo1.AddItem WebBrowser1.LocationURL, 0
    Combo1.ListIndex = 0
    mbDontNavigateNow = False
End Sub


*5- More coding:*

You can add more buttons to your browser as those:

* Find if a word is in the page (taken from a tutorial on this forum).


VB Code:
'This to tell you if a word is in the page, Here we call the WebPageContains function.
Private Sub Command7_Click()
    Dim strfindword As String
        strfindword = InputBox("What are you looking for?", "Find", "") ' what word to find?
            If WebPageContains(strfindword) = True Then 'check if the word is in page
                MsgBox "The webpage contains the text" 'string is in page
            Else
                MsgBox "The webpage doesn't contains the text" 'string is not in page
            End If
End Sub
 'This is the finding function.
Private Function WebPageContains(ByVal s As String) As Boolean
    Dim i As Long, EHTML
    For i = 1 To WebBrowser1.Document.All.length
        Set EHTML = _
        WebBrowser1.Document.All.Item(i)
          If Not (EHTML Is Nothing) Then
            If InStr(1, EHTML.innerHTML, _
            s, vbTextCompare) > 0 Then
            WebPageContains = True
            Exit Function
        End If
    End If
Next i
End Function

* Page properties

VB Code:
WebBrowser1.ExecWB OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT
This will run the page properties.

* Print a page

VB Code:
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT

* Save a page

VB Code:
WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT

* Delete cookies from your computer


VB Code:
'This code is used to empty the cookies from the user's computer / We call function from here.
Private Declare Function GetUserName _
Lib "advapi32.dll" Alias "GetUserNameW" ( _
ByVal lpBuffer As Long, _
ByRef nSize As Long) As Long
 Private Declare Function SHGetSpecialFolderPath _
Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" ( _
ByVal hwnd As Long, _
ByVal pszPath As String, _
ByVal csidl As Long, _
ByVal fCreate As Long) As Long
 Private Const CSIDL_COOKIES As Long = &H21
 'This calls the function that deletes the cookies.
Public Sub Command1_Click()
Dim sPath As String
sPath = Space(260)
Call SHGetSpecialFolderPath(0, sPath, CSIDL_COOKIES, False)
sPath = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "\*.txt*"
On Error Resume Next
Kill sPath
 End Sub


* Show webpage's source code:


VB Code:
Private Sub Form_Load()
Text1.Text = Form1.browser.Document.documentElement.innerHTML
End Sub


*6- Important codes:* New!


* Popups Blocker


VB Code:
Private Function IsPopupWindow() As Boolean
On Error Resume Next
If WebBrowser1.Document.activeElement.tagName = "BODY" Or WebBrowser1.Document.activeElement.tagName = "IFRAME" Then
IsPopupWindow = True
Else
IsPopupWindow = False
End If
End Function
 Private Sub webbrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As Form1
Cancel = IsPopupWindow
If Cancel = False Then
Set frm = New Form1
Set ppDisp = frm.WebBrowser1.object
frm.Show
End If
End Sub

This will block all the popups, but in the same time it will open links in a new window as usual.


* JavaScripts handeling


VB Code:
WebBrowser1.Silent = True

This will not show any errors from pages while you are using your web browser, put it in the form load event.

* The size of the browser and the scrollbars code


VB Code:
Private Sub Form_Resize()
On Error Resume Next
WebBrowser1.Width = Me.ScaleWidth
WebBrowser1.Height = Me.ScaleHeight - 1680
End Sub

This code will make your webbrowser fit with the overall form structure, and also will make the scrollbars compitable with the form.


Now you got a great web browser with many functions  :Wink: 

Need icons for your application? just do a fast forum search and you will find a great sites for icons or images.

----------


## TheBigB

Nice tutorial    :Thumb:   :Smilie:  

A real challenge would be making a browser without the 'Microsoft internet controls'

----------


## Static

This should be moved to FAQ or something since it is not a question...


But there is a lot more that can be added to this:

example:

using commandstatechange event u can enable/disable the back/forward buttons



VB Code:
Private Sub Webbrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
    On Error Resume Next
    DoEvents: DoEvents: DoEvents
    If Enable = True And Command = CSC_NAVIGATEBACK Then
        cmdBack.Enabled = True
    ElseIf Enable = False And Command = CSC_NAVIGATEBACK Then
        cmdBack.Enabled = False
    End If
    If Enable = True And Command = CSC_NAVIGATEFORWARD Then
        cmdForward.Enabled = True
    ElseIf Enable = False And Command = CSC_NAVIGATEFORWARD Then
        cmdForward.Enabled = False
    End If
End  Sub

----------


## Hack

Moved to the CodeBank.

----------


## zeidhaddadin

thanks for sharing, btw the text box which you can see in the screenshot if for writing notes while surfing or viewing pages, me personaly i need this thing in my browser  :Smilie:

----------


## KPS.

how can i get it to scale to become a full page browser not just a little one?

----------


## Al42

Static:
VB Code:
Private Sub Webbrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
    If Command = CSC_NAVIGATEBACK Then 
      cmdBack.Enabled = Enable
    Else If Command = CSC_NAVIGATEFORWARD Then
      cmdForward.Enabled = Enable
    End If
End  Sub

----------


## zeidhaddadin

> how can i get it to scale to become a full page browser not just a little one?


I didn't understand what exactly you mean, but this is a code to make the web page fit with the form and also the scrollbars.


VB Code:
'This to make the scrollbar fit with form size.
Private Sub Form_Resize()
WebBrowser1.Width = Me.ScaleWidth
End Sub

----------


## Ethernet

For some reason when i try to go to a website i get an 'Action Canceled' error.  Can anyone help me with this?

----------


## zeidhaddadin

Use "On Error Resume Next".

----------


## Ethernet

I'm using that already.  I'm using the same code used in the tutorial and am still having trouble with Page cannot be displayed errors and such.

----------


## will1233

this is a very good tutorial, it has helped me alot with a college assignment. and before anything is sed i didnt copy it so i cannot be failed lol i just read the code understood it in my mind and put it down on my program. anyway this was a very good example and i have learnd alot from it and developed on it. so THANKS!!!!

----------


## rjbudz

Use of the 'Microsoft internet controls' does hamper the functionality of this somewhat, though I agree, this is a really good tutorial.

Do you know of a way to prevent the WebBrowser control from reading from and writing to the same history as Internet Explorer? This drawback (and probably others) relegates the control to the status of Internet Explorer Jr., rather than its own app.

----------


## Strumthund

I just wanted to say this is a great tutorial. I'm using this for a school assignment and I think I'll get a pretty good grade on it.

----------


## zeidhaddadin

You are all welcomed  :Smilie:

----------


## Doc Scheinder

This is a great tutorial. How can you get the popup window to resize and/or close based on the webpage(s)'s original javascript code? Your code opens the popup window but does not close it. Thx

----------


## samaster1991

Wow, great tutorial. But  I was just wondering one thing. I use tabs in my web browser but I had to set the amount of tabs and its content before I created the  project. Is there a code to make any links clicked on a web page go straight to a new tab instead of opening IE up. And an option to create a new tab :Ehh:  

Thanks

----------


## MSWindowsUser

> Wow, great tutorial. But  I was just wondering one thing. I use tabs in my web browser but I had to set the amount of tabs and its content before I created the  project. Is there a code to make any links clicked on a web page go straight to a new tab instead of opening IE up. And an option to create a new tab 
> 
> Thanks


Here's a code sample


```
Private Sub TabStrip1_CLick()

Select Case TabStrip1.SelectedItem.Key

Case "Home Page"

WebBrowser1.GoHome

Case "New Tab"

Combo1.Text = "about:blank"
WebBrowser.Navigate (Combo1.Text)
End Select

End Sub
```

You can add more cases to your Tabs.

Merry Christmas,

MSWindowsUser
Visual Basic User and Advanced coder.

----------


## samaster1991

Thanks

Merry Christmas  :Smilie:

----------


## raghu_ktm@yahoo.com

Dear sir,
Please help me.
This is a great tutorial. How can you get the popup window close based on the webpage(s)'s original javascript code? In this code opens the popup window but does not close it. After submitting value to main window how to close popup window ?

Raghu Bhandari

----------


## MSWindowsUser

> Dear sir,
> Please help me.
> This is a great tutorial. How can you get the popup window close based on the webpage(s)'s original javascript code? In this code opens the popup window but does not close it. After submitting value to main window how to close popup window ?
> 
> Raghu Bhandari


Open menu editor (Ctrl + E), type in &Pop-ups in the Caption box, mnuPopups in the Name box, hit enter, add &Allow in the caption box, mnuAllow in the name box, check checked, hit the right arrow so that it can go into the pop-ups menu, add &Disallow in the Caption box, mnuDisallow in the name box, click on the right arrow to let it stay in the Pop-ups menu.



```
Private Sub mnuAllow_Click()
    mnuAllow.Checked = True
    mnuDisallow.Checked = False
    Dim frmNW As frmInternet
    Dim ppDisp As Object
    Dim Cancel As Boolean
    
    Set frmNW = New frmInternet
    frmNW.brwWebBrowser.RegisterAsBrowser = True
    Set ppDisp = frmNW.brwWebBrowser.object
    frmNW.Show
End Sub

Private Sub mnuDisallow_Click()
    mnuDisallow.Checked = True
    mnuAllow.Checked = False
    Dim ppDisp As Object
    Dim Cancel As Boolean
    Dim frmNW As frmInternet

    Cancel = IsPopupWindow
    
    If Cancel = False Then
        Set frmNW = New frmInternet
        Set ppDisp = frmNW.brwWebBrowser.object
        frmNW.Visible = True And False
    End If
End Sub

Private Sub brwWebBrowser_NewWindow2(ppDisp As Object, Cancel As Boolean)
    On Error Resume Next
    Dim frmNW As frmInternet
    
    Cancel = IsPopupWindow
    
    If mnuDisallow.Checked = False Then
        mnuAllow.Checked = True
        Set frmNW = New frmInternet
        frmNW.brwWebBrowser.RegisterAsBrowser = True
        Set ppDisp = frmNW.brwWebBrowser.object
        frmNW.Show
    ElseIf mnuAllow.Checked = False Then
        mnuDisallow.Checked = True
        Cancel = False
        Set frmNW = New frmInternet
        Set ppDisp = frmNW.brwWebBrowser.object
        frmNW.Visible = True And False
    End If
End Sub

Private Function IsPopupWindow() As Boolean
    On Error Resume Next
    If brwWebBrowser.Document.activeElement.tagName = "BODY" Or brwWebBrowser.Document.activeElement.tagName = "IFRAME" Then
        IsPopupWindow = True
    Else
        IsPopupWindow = False
    End If
End Function
```

Code sample above can be copied.

To disallow, go to Pop-ups > Click on Disallow and it will check the disallow menu.  ***NOTE: This cannot open links in a new window.  It will block the new window from opening. ***

----------


## MSWindowsUser

```
Private Function Popups() as Boolean
    Dim frmAds as Form1
    Dim ppDisp as Object
    Dim Cancel AS Boolean

    Set frmAds = New Form1
    Set ppDisp = Form1.WebBrowser1.Object

    If Popups = False Then
        Cancel = False
        frmAds.Visible = True And Fasle
        Unload frmAds
    End If
End Function

Private Sub WebBrowser1_NewWindow2(ppDisp as Object, Cancel As Boolean)
    Dim frmNewWindow As Form1

    Set frmNewWindow = New Form1
    Set ppDisp = Form1.WebBrowser1.Object
    WebBrowser1.RegisterAsBrowser = True
    frmNewWindow.Show
    Popups = False
End Sub
```

This block all pop-ups* and you can still open links in a new window.

*Do NOT go on websites that the domains expired.  If you go to another website, only ONE pop-up show up, close the pop-up.

----------


## raghu_ktm@yahoo.com

Dear sir,
I try like this to close my window.
but i got unspecified error and my application close.

Private Sub wbrBrowser_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
'On Error Resume Next
    If (IsChildWindow) Then
        Cancel = True
* Unload Me    *    (Error On this line)
    Else
        Cancel = False
    End If
End Sub

Private Function IsPopupWindow() As Boolean
On Error Resume Next
    If WebBrowser1.Document.activeElement.tagName = "BODY" Or WebBrowser1.Document.activeElement.tagName = "IFRAME" Then
        IsPopupWindow = True
    Else
        IsPopupWindow = False
    End If
End Function

Sir What i did mistake in code can u help me ?

Thanks
Raghu Bhandari

----------


## MSWindowsUser

> Dear sir,
> I try like this to close my window.
> but i got unspecified error and my application close.
> 
> Private Sub wbrBrowser_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
> 'On Error Resume Next
>     If (IsChildWindow) Then
>         Cancel = True
> * Unload Me    *    (Error On this line)
> ...


Remove the single quote from the On Error Resume Next line.

----------


## raghu_ktm@yahoo.com

Dear sir,
No no mistakenly i paste that wrong code but i already try without single quote. when my program execute this line VB application also close with unspecified error. Any Idea ?

----------


## MSWindowsUser

> Dear sir,
> No no mistakenly i paste that wrong code but i already try without single quote. when my program execute this line VB application also close with unspecified error. Any Idea ?


    If you are using Visual Basic 2005 then
        Me.Close()
    ElseIf you are using Visual Basic 6 Then
        Unload Me
    End If

----------


## raghu_ktm@yahoo.com

NO Sir
Because of JavaScript i am getting error 



```
Private Sub wbrBrowser_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
On Error Resume Next
If (IsChildWindow) Then
   Cancel = True
   Unload Me (Error On this line)
Else
   Cancel = False
End If
End Sub
```

Some page can close but some pages catch error on this line
So what can i do ?

----------


## MSWindowsUser

> NO Sir
> Because of JavaScript i am getting error 
> 
> 
> 
> ```
> Private Sub wbrBrowser_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
> On Error Resume Next
> If (IsChildWindow) Then
> ...


Remove the parentheces on "If (IsChildWindow) Then"
Add = True Or False after IsChildWindow.  Solved?

----------


## Visual Master

does someone know a code like when i press Enter it will load,just like "real" browsers?

----------


## Visual Master

> I'm running on 2008 so I don't know if this is the same for you...


No,i'm using vb6 now but maybe i'll get 2008 :Confused:

----------


## Visual Master

First,make a commandbutton and a textbox.
now double click on the command button and write this code:

vb Code:
Private Sub Command6_Click()
WebBrowser1.Navigate "http://www.google.com/search?hl=en&q=" & Text2.Text & "&btnG=Google+Search"
'change "WebBrowser" to the name of your own browser.
Form1.Caption = "WebBrowser - Search Results"
End Sub
Now,your browser has a search function! :Smilie:

----------


## nelton

where can i get a downlaodable version of this project??? urgent...

----------


## zeidhaddadin

> where can i get a downlaodable version of this project??? urgent...


sorry but i don't have it .. i made it a while ago!

----------


## nelton

plz cud sum1 make it for me.....i tried doing it on my own but i got many errors....still learning VB

----------


## nelton

also im using VB6.0....whenever i try 2 load d 'microsoft internet controls' comp it gives an error saying c:\windows\system32\ieframe.dll\1 cud not b loaded...what can b d prob

----------


## Coolblue

Hey Friends thanx a lot!! d tutorial was very helpful!!

*is there possibility to open a vb form in a IE xplorer???

as per my project i want 2 navigate inside a vb form just like the way we navigate using frames in html.....i mean wen i click on a command button or link i want d other form 2 load within d parent form..is it possible??

thanx a lott in advance.. ..My final yr project pendin coz of ds * 


Regards...

----------


## Visual Master

> also im using VB6.0....whenever i try 2 load d 'microsoft internet controls' comp it gives an error saying c:\windows\system32\ieframe.dll\1 cud not b loaded...what can b d prob


Hi,i asked that question also, see http://www.vbforums.com/showthread.php?t=492583

----------


## MSWindowsUser

> where can i get a downlaodable version of this project??? urgent...


Do you have VB6 on your PC?  If so, download mine.

Blocks Pop-ups and you can still open links in a new window.  :Smilie:

----------


## MSWindowsUser

> also im using VB6.0....whenever i try 2 load d 'microsoft internet controls' comp it gives an error saying c:\windows\system32\ieframe.dll\1 cud not b loaded...what can b d prob


Download my attachment, unzip the contents, copy the file to C:\WINDOWS\System, hit Ctrl + T, click Browse..., Go up one, double-click on the System Folder, for the file type, choose All Files (*.*) and type in shdocvw.DLL  This works 100%

The Only reason this doesn't open in Windows XP, it's because this file is not supported on VB6 with Windows XP on your PC.

----------


## vbsixer

First off...good tutorial this.  good work!

Next up ... the problems folks had, I believe relates to the version of IE you have.  When I updated mine from 7 to 8 (I think, version may be wrong but in any case, from one older version to the newest), this screwed my old VB6 IE Browser control.....

Sorry if thats whats been posted above!

----------


## --=KOK=--

*nice work & gud going guyz*

----------


## DigiRev

Would be nice if you also explained how to submit forms and stuff, since sometimes it's just easier doing it with the WebBrowser control.

----------


## calumrulez

> Do you have VB6 on your PC?  If so, download mine.
> 
> Blocks Pop-ups and you can still open links in a new window.


Hey man.
I have been making my web browser, and it rocks!!
but i downloaded yours, and was interested to see the "File, Tools, Internet Options"
This looks like a hugely useful tool, but i cant make it work!!!

What code did you use to open the Internet Options please??

Thanks man!

----------


## calumrulez

Here is the code i am using just now for my Internet Options button

It doesnt work  :Frown: 
can you help plz?


vb Code:
Private Sub IOptions_Click()
Shell ("Control Panel/Internet Options")
End Sub

----------


## calumrulez

Never mind, Hack helped me

if anyone is interested, the code to launch internet options is...


vb Code:
Private Sub IOptions_Click()
Shell "C:\Windows\System32\control.exe" & " Inetcpl.cpl", 1
End Sub

----------


## joebobfrank

Is there a way to encrypt URLs you enter into the combobox?

----------


## si_the_geek

That is not an acceptable question to ask on this site.

Assisting in violating your schools rules or security systems (no matter how justified you think it is) is against our rules - see the Acceptable Use Policy link at the bottom of all VBForums pages.

----------


## joebobfrank

that was just an example so that people would get what i meant, I'm not going to use it for malicious purposes, that would get me banned from the school computers.

and besides, if I wanted to do that I'd just use a proxy; there are hundreds of them lying around the interwebs.

Is it even possible to encrypt all URLs passing through the browser?

----------


## si_the_geek

I'm not aware of any valid reason for doing that - only for bypassing security systems (which often block proxies).

As you have not given another reason, I have serious doubts of your intentions, and cannot allow an answer (from anyone) unless you send me a valid reason via Private Message.

----------


## joebobfrank

```
Private Sub WebBrowser1_TitleChange(ByVal Text As String)
    Form1.Caption = WebBrowser1.LocationName
End Sub
```

Show page title in the forms caption.

----------


## calumrulez

> ```
> Private Sub WebBrowser1_TitleChange(ByVal Text As String)
>     Form1.Caption = WebBrowser1.LocationName
> End Sub
> ```
> 
> Show page title in the forms caption.


why did you post that?!

----------


## joebobfrank

It's a useful thing for a web browser to show page title... just posting code in the codebank...

----------


## joebobfrank

Ok here's how to open up the page source in notepad and not keep it stored on your hard drive (so you don't have to manually delete the source code text files)



```
 

Private Sub MenuSource_Click()
Text1.Text = Form1.WebBrowser1.Document.documentElement.innerHTML
    Dim hFile As Long
   Dim sFilename As String

   sFilename = "c:\tempsource.txt"
   
  'obtain the next free file handle from the
  'system and and save the text box contents
   hFile = FreeFile
   Open sFilename For Output As #hFile
      Print #hFile, Text1.Text
   Close #hFile
   
   
   Dim strtest As String
    Dim FileSystemObject As Object
    strtest = "notepad c:\tempsource.txt"

   Shell strtest, vbNormalFocus
   
   Kill "c:\tempsource.txt"
End Sub
```


Another thing to add to the tutorial



```
Private Sub MenuFind_Click()
    WebBrowser1.ExecWB OLECMDID_FIND, OLECMDEXECOPT_DODEFAULT
End Sub
```

----------


## vbnoobie

> Do you have VB6 on your PC?  If so, download mine.
> 
> Blocks Pop-ups and you can still open links in a new window.


What is the code for the status bar? How do you do it? Sorry I'm noob.  :LOL:

----------


## vbnoobie

i keep on getting this error
_Run-time error '-1 (ffffffff)'_
when i put these codes
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
Dim i As Integer
Dim bFound As Boolean
Me.Caption = WebBrowser1.LocationName
For i = 0 To cboAddress.ListCount - 1
If cboAddress.List(i) = WebBrowser1.LocationURL Then
bFound = True
Exit For
End If
Next i
mbdontnavigatenow = True
If bFound Then
cboAddress.RemoveItem i
End If
cboAddress.AddItem WebBrowser1.LocationURL, 0
cboAddress.ListIndex = 0
mbdontnavigatenow = False
End Sub
what will i do?
doesn't _mbdontnavigatenow_ needs to be declared?

----------


## MSWindowsUser

> i keep on getting this error
> _Run-time error '-1 (ffffffff)'_
> when i put these codes
> Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
> On Error Resume Next
> Dim i As Integer
> Dim bFound As Boolean
> Me.Caption = WebBrowser1.LocationName
> For i = 0 To cboAddress.ListCount - 1
> ...


Under Option Explicit
Type in Private mbdontnavigatenow as Boolean.

That will work. Trust me.



```
Option Eplicit
Private mbdontnavigatenow as Boolean
```

The other codes go below the "Option Explicit" and "Private mbdontnavigatenow as Boolean" lines

----------


## carl2k2

Yeah, im missing basic components in my vb6 app  :Frown: 

"Microsoft html object library" and "Microsoft internet controls"

----------


## jmsrickland

Browse to your system directory and add them

Microsoft HTML Object Library ---> mshtml.tbl
Microsoft Internet Controls ------> shdocvw.dll

----------


## carl2k2

> Browse to your system directory and add them
> 
> Microsoft HTML Object Library ---> mshtml.tbl
> Microsoft Internet Controls ------> shdocvw.dll


mshtml.tbl is missing  :Frown: 

I find mshtml.dll but cant be added anyway  :Frown:

----------


## carl2k2

getting runtime error '-2(fffffffe)'

----------


## jmsrickland

Sorry about the misspell: It should be *mshtml.tlb* not mshtml.tbl

----------


## carl2k2

> Sorry about the misspell: It should be *mshtml.tlb* not mshtml.tbl


yeah  i tried em both  :Frown:

----------


## jmsrickland

You were able to add the DLL, right, but not the mshtml.tlb?

Don't know exactly how you are doing it but the mshtml.tlb should be added to the reference list (not the components list). Is this what you are trying to do with out success?

----------


## yomamathecableguy

this is an awesome tutorial thanks!! ^_^

----------


## rusilja

How can I make a Tabbed webbrowser with TabStrips???? I have been looking for this for 2 days!!! Please help me!!!

I mean: When I click CommandButton1, then in tabStrip a second Tab appears with a second Webbrowser (like in IE7, Mozilla, Opera,....)


All I can find on website's Is Tabs for VB.net or VB2008 but NOTHING for VB6!! Please help!!

----------


## Smak_Rice

I am also trying to get a tabbed web browser, but on the moment I have problems with my progressbar. My progressbar doesn't stay on the place I want it to have with my screen maximized. If I resize my screen it replaces perfectly.

If someone could help me with Tabs or my progressbar, I would really appreciate that.

----------


## jcvamp

Using the method in the tutorial, how could you display the blocked pop-up? Using Internet Explorer 7, it displays the yellow bar and you have the option of allowing the pop-up, but it refreshes the page in order to do it. I've managed to achieve the same effect, however, is there a way of doing it without refreshing?

----------


## Deliriumxx

> Do you have VB6 on your PC?  If so, download mine.
> 
> Blocks Pop-ups and you can still open links in a new window.


I have been looking for a way to open links in new window when a user RIGHT clicks on the menu and selects Open In New Window. This app is the only one I found that opens a new window,,, but there is no Source for VB6...

Can anyone supply the actual example on HOW TO open a a link in new window when user right clicks on the link and selects OPEN IN NEW WINDOW

----------


## John1in2

I have tried to use this tutorial to open up a web page, fill out a form (you put in an IP address and info about that address comes out after submission) and extract the data from the form.

It works in the web browser window, I display the data from the filled out form successfully.

However, after the data is displayed the "WebBrowser1.Document.body.innerHTML" values do not match the displayed information.  

Why is this.

Here is my code-



```
Private Sub Command1_Click()
Dim doc As HTMLDocument
Dim strHTML As String

'go to the altavista (text) search page
WebBrowser1.Navigate "http://www.ip2location.com/free.asp"
'Wait until page is loaded
Do
DoEvents
Loop Until Not WebBrowser1.Busy

'Make doc reference to the document inside the webbrowser control
Set doc = WebBrowser1.Document

'Set field ipaddresses with the value of Text1
SetInputField doc, 0, "ipaddresses", Text1

'Submit the form
doc.Forms(0).submit

'Wait until result are loaded
Do
DoEvents
Loop Until Not WebBrowser1.Busy
'loop till we have some stuff in strHTML
Do
DoEvents
strHTML = WebBrowser1.Document.body.innerHTML
Loop Until (Len(strHTML) > 400)

'
' read in the text into string variable
'
strHTML = WebBrowser1.Document.body.innerHTML
Text2.Text = strHTML
'
'text is not matching the window.
'
```


What I want to do is put in some ip addresses and "submit" and then extract the results from a string variable.  I see in the screen the results but the variable does not match.  Using VB6 and IE6

----------


## jmsrickland

The information that you inserted into a field on the page is only valid for that page. After you submit the Form you sit and wait for the returned responses which will be a new page. The information on one page doesn't mean it is going to be there on another page. Another problem you should recode to have your fields that you want to fill in be done in the _DocumentComplete event and not as the result of a loop being terminated by *Loop Until Not WebBrowser1.Busy*. I say this because the indicator *.Busy* can be triggered before the document has actually completed the process but in the _DocumentComplete event you are gauranteed that the process has completed.

----------


## redback93

Hello VB Forums!
Since this is a Internet Explorer based web browser, the code for the search bar was simple:

All you need is :
-1x Text Box
-1x Button

(and one, pre-existing URL bar)

And the code:



```
Private Sub BUTTON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUTTON.Click
        WebBrowser1.Navigate("http://www.google.com.au/search?hl=en&source=hp&q=" + SEARCHBOX.Text + "&meta=&aq=null&oq=googl")
        URLBOX.Text = ("http://www.google.com.au/search?hl=en&source=hp&q=" + SEARCHBOX.Text + "&meta=&aq=null&oq=googl")
    End Sub
```

That's it!
Have Fun!

----------


## jmsrickland

First, your code is not for VB6.

Second, that is still not the way to do it because you are using hard-coded string URL to be placed in the textbox

----------


## John1in2

> The information that you inserted into a field on the page is only valid for that page. After you submit the Form you sit and wait for the returned responses which will be a new page. The information on one page doesn't mean it is going to be there on another page. Another problem you should recode to have your fields that you want to fill in be done in the _DocumentComplete event and not as the result of a loop being terminated by *Loop Until Not WebBrowser1.Busy*. I say this because the indicator *.Busy* can be triggered before the document has actually completed the process but in the _DocumentComplete event you are gauranteed that the process has completed.


I dont understand- how do I use _DocumentComplete event?

I have seen this code but don't really understand when its called, would you do a loop until Page_Loaded is True (obvoiusly you set it to False before calling)?-



```
Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.object) Then
    Page_Loaded = True
    End If
End Sub
```

After I submit the form how would I retreive the data?  

And finally how do I block the popup that results from the submission of the form?

EDIT-- I put a breakpoint into the part that read the data (breakpoint at strHTML = ***).   My code works excpet that upon form submission you get a popup and my code reads the popup not the form that I submited.  If I run this and close the popup manually when the breakpoint is hit I get the correct data.  So I guess the critical thing in addition to correctly figuring out when the pages are done is to figure out how to prevent the popup or to close it before reading in the data.  I have read the first page of this thread dealing with popups but it confuses my small brain!  help!

----------


## MrDavidThorn

Hi All I am new to the broswer and the tutorial is great thanks!  - Im using the VBA version which I assume is the same control as VB6. Just a quick issue - Im tying to create a versioning control software for Excel, that uses a web address to access an Excel file. Problem that I have is that when the webbrowser access a specified .xls document it opens the spreadsheet in the broswer itself not requesting the user to download the file. Im still new to the control and cant find how to force the control to download the file rather than just display it in the actual webbrowser, any help would be great!

----------


## MSWindowsUser

@ MrDavidThorn: Welcome to the VBForums!  :Smilie: 

New codes (attachments below)

Fixes:
Hyperlink in new window fixed
Popup block fixed
Back & Forward button enable fixed
Status fixed

Unfixed:
None as of now :-D

Enjoy my new project.  Feel free to rename the objects/program name if desired, and to fix the version number, go to: Project > Project1 Properties...
Make tab, type in a desired number (Integers only), click OK, save every form project, and the project, make an EXE, make an installation project from Start > Programs (All Programs for others) > Microsoft Visual Studio 6.0 > Microsoft Visual Studio 6.0 Tools > Package & Deployment Wizard

Follow the instructions, burn the files to a CD, install the program on other machines.

Next project might contain the Full Screen option & Windows Updates (Windows 95 & Higher only)

edit: to go onto the last visited site, remove the "Visited: Username@" line from the Text box, and click Go, but select the "Visited History" from the drop-down menu, click Get Cache, and select the site that you visited last.  :Smilie:

----------


## DoomFan

Thanks for the cool tutorial I am learning a lot form it to make my own little browser thanks agian. keep up the good work

----------


## tamasa

Hy guys I had a problem with that code in webbrowser tutorial

I need use a webbrowser with one single window. Then I used the example

"Open in new window
VB Code:
_'This to open a new window with our browser.Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)Dim frm As Form1Set frm = New Form1Set ppDisp = frm.WebBrowser1.Objectfrm.ShowEnd Sub "_


However if  i click on link  that open in other window the browser show a blank page. It cant open any link with new page 


Can someone  help me?

----------


## michaelhaseth

I am a bit confused on the progress bar, 
      When it says: If progress = -1 then progressbar1.value =...

What is Progress refering to?

----------


## ozzzo

Very useful. Thank all.

----------


## yacky

Hi,

how can I make Tabs in this web browser??

----------


## Ronny123

Hi,

I am trying to use the WebControl in VB6 as an activeX which I put in a cab file and then display in a html page.

Only problem is that I am not able to get to the URL of the current page :
locationURL does not work and documentCompleted does not run as I describe in http://www.vbforums.com/showthread.p...54#post3748554

Can somebody help me with this.

Thanks !

----------


## smith carlos

> ```
> Private Sub WebBrowser1_TitleChange(ByVal Text As String)
>     Form1.Caption = WebBrowser1.LocationName
> End Sub
> ```
> 
> Show page title in the forms caption.



can i have it for vb.net !! 2008

----------


## gep13

Hey,

Have a look here:

http://www.vbforums.com/showthread.php?t=506103

Gary

----------


## Ronny123

Hi Gary,

Thanks for the reply !

The problem here is I am using vb 6 and I am running an activeX in IE. When I use the activeX I created in a vb 6 desktop client all works well. But in the browser it does not.

I do not think the link you send me does answer this or did I miss something?

----------


## gep13

Ronny,

I was replying to the question from smith carlos regarding a .Net version, which is shown in the link that I posted.

Sorry, I have no idea about your question, I don't do VB 6  :Smilie: 

Gary

----------


## limpu.cool

Dear Sir,
Today only i visited this forum and found it very useful.

I know programming in VB6, and currently facing a problem.
The problem is that i want to open the link on my webbrowser control in in a new window.
If i am using the right click > open in new window then i am able to catch it via..



```
Private Sub wb_NewWindow2(index As Integer, ppDisp As Object, Cancel As Boolean)
  ........
  .........
  frmMain.wb(new_index).RegisterAsBrowser = True
  Set ppDisp = frmMain.wb(new_index).Object
End Sub
```

But what i want is even if somebody click the left mouse button on a link, i shall be able to open it in a new window (with session maintained).

Second thing is that i want to scroll the loaded page programatically (pagedown/pageup).

Is it possible to do the above two actions?

----------


## ts96

I can only give you a solution for your first question. Just use the following code:


```
Option Explicit
Enum BrowserNavConstants
    navOpenInNewWindow = 1
    navNoHistory = 2
    navNoReadFromCache = 4
    navNoWriteToCache = 8
    navAllowAutosearch = 16
    navBrowserBar = 32
    navHyperlink = 64
    navEnforceRestricted = 128
    navNewWindowsManaged = 256
    navUntrustedForDownload = 512
    navTrustedForActiveX = 1024
    navOpenInNewTab = 2048
    navOpenInBackgroundTab = 4096
    navKeepWordWheelText = 8192
    navVirtualTab = 16384
    navBlockRedirectsXDomain = 32768
    navOpenNewForegroundTab = 65536
End Enum
```

so you can now navigate to a site (e.g. google.com) by using:
WebBrowser1.navigate "www.google.com", 1
I can't give you an answer for your second question.

----------


## metamaster765

Does anybody know where I can find either an opera browser control, a google chrome control, a good non-glitchy firefox control, or just adding security to the standard IE control?  i have a firefox control already but it is probably the worst thing i have ever had to deal with so i think i need a different thing. oh and also a bookmarks thing. that would be great.

----------


## JarJarMP

> * Show webpage's source code:
> 
> VB Code:
> Private Sub Form_Load()
Text1.Text = Form1.browser.Document.documentElement.innerHTML
End Sub



Hi!

I would like to ask for a little help with this feature. It works great, but doesnt do everything what i really need. I want monitor every page's source code. But this code monitors only the page, what you typed in Combo1. After i click on the loaded page navigate to an other --> the source -Form1.browser.Document.documentElement.innerHTML- doesnt change. If i type other adress, it creates a new innerHTML. Hope, i could wrote my problem well.. 

So my question is: how can i monitor every page's source code

Thank you in advance

----------


## metamaster765

is there a code to load a saved page? if someone could post it, that'd be great.

----------


## jmsrickland

You should ask your questions in the main forum. I think you will get better responces there.

----------


## bishaw

Thnks you your oppertunity this is my first question reply you code gose here


```
If KeyAscii = vbKeyReturn Then
  Command1_Click
End If
```

----------


## bishaw

i'm sorry but will it be applied for the case of other search engines.How?

----------


## Lolmeh101

MSWindowsUser, I don't really need the attachment as mine came with it and i run 6.0 However, Nelton, I have made a Web Browser, Not with the timer or notes, but it does have searchbox..I have another with a history box. though i dont no why, but to add stuff to it, you need to highlight it all blue, and press backspace (erase key) for it to add... If anyone can give me code so it automaticly adds, then thanks!

----------


## bishaw

Thanks all the friends of vbforums

----------


## chukka32

Hi All... i've nearly finished building a web browser using visual studio 2005, but i'm just having trouble displaying the url of the current page displayed in the web browser control! 

i.e
urltxtbox1.text = WebBrowser1. ?????


Can anyone please help me....
Thanking you in advance...

----------


## MSWindowsUser

> Hi All... i've nearly finished building a web browser using visual studio 2005, but i'm just having trouble displaying the url of the current page displayed in the web browser control! 
> 
> i.e
> urltxtbox1.text = WebBrowser1. ?????
> 
> 
> Can anyone please help me....
> Thanking you in advance...


Hello.  Are you talking about when displaying the title of the site e.g. www.google.com - Google (title bar)? or the StatusBar e.g. Loading www.google.com/ladidadid Done?

----------


## chukka32

Hi MSWindowsUser,
What I'm trying to do is to keep the current page URL displayed in a separate textbox, so that when I browse back and fro with the navigate buttons then the textbox changes with the webbrowser control if that makes any sense?! I basically need the code to read the URL for the current page that is displayed in the web browser?!?! 
Thanks for your prompt response!!

----------


## gep13

> Hi All... i've nearly finished building a web browser using visual studio 2005, but i'm just having trouble displaying the url of the current page displayed in the web browser control! 
> 
> i.e
> urltxtbox1.text = WebBrowser1. ?????
> 
> 
> Can anyone please help me....
> Thanking you in advance...


Hey,

If you are creating a Web Browser in Visual Studio 2005, why are you posting/asking questions about it in the VB6 forum?!?

Take a look at the links in my signature, they will be of more help to you if you are using .Net.

Gary

----------


## seed19772003

this agood tutorial and it's agood work
but, in my project i need to using search engine such as google or yahoo to search about  any subject and then i need to store only html and pdf documents to hard disk , can any one known me how do that programatically, please answer me?

----------


## coolcurrent4u

Hello, how to you loop through all elements (input, select textarea etc) of a form and fill them?

----------


## jmsrickland

See post #91

----------


## silveraero

Hi, I'm new here. I know how to make a web browser in VB 2010 but I don't know how to let it access IP address like 192.168.1.1 or else. Please help me...

----------


## gep13

> Hi, I'm new here. I know how to make a web browser in VB 2010 but I don't know how to let it access IP address like 192.168.1.1 or else. Please help me...


Hello silveraero,

Welcome to the forums!

Can you please provide more information about what you are trying to achieve?  Are you saying that you want to restrict access to a site based on the client IP address, or are you saying that you want your web browser to be able to access a website that is hosted on 192.168.1.1.  If it is the latter, then it should simply be a case of navigating to http://192.168.1.1.

Gary

----------


## jmsrickland

> Hi, I'm new here. I know how to make a web browser in VB 2010 but I don't know how to let it access IP address like 192.168.1.1 or else. Please help me...


See post #91

----------


## silveraero

Sorry, it's double post. Thank you very much. Solved it.

I'm design a web base application. Here is the description: I have an Android phone and I installed a wifi transfer application. I build this application as an file transfer center, you know, like PC suite or sync ... (my country is not using English as main language so sorry for my bad English).

What I want to as is how can I list the phone that using the wifi transfer application so I just need to choose in the list to transfer?
And, when I resize the form, the right align control will not realign to the border and stay still. Here is my solution for this:
[qupte]Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
        cbPort.Top = 15
        cbIP.Top = 15
        cmdBack.Top = 10
        cmdForward.Top = 10
        cmdHome.Top = 10
        cmdStop.Top = 10
        cmdGo.Top = 10
        cmdStop.Left = Me.Width - cmdStop.Width - 40
        cmdGo.Left = Me.Width - (cmdStop.Width) * 2 - 45
        cbPort.Left = Me.Width - (cmdStop.Width) * 2 - 50 - cbPort.Width
        cbIP.Width = Me.Width - (cmdBack.Width) * 5 - cbPort.Width - 90
    End Sub
[/quote]
I just think about the controls size and scale. Does anyone have better solution?

----------


## virmil15

this is the browser I created you can download the sample if you want
here - _< link removed by moderator >_

----------


## si_the_geek

> this is the browser I created you can download the sample if you want


Welcome to VBForums  :wave: 

I have removed your link to protect our members, because we have no way of knowing what an executable file actually does - which could include something malicious, such as if there is a virus on your computer.

Feel free to post the code in an attachment (_without_ executable files).  You can do that by putting the files into a zip file, and when posting click on the "Go advanced", then "Manage attachments"

----------

