...

View Full Version : VB.net Tabbed browser + database



Ludatha
10-01-2008, 09:45 AM
Using Visual Basic 2008 Express Edition

Hey guys, I have created a tabbed browser using a video tutorial, and it did work until I changed a few things around.

When I type a URL in the box and click go I get this error:

Object reference not set to an instance of an object

From this code:

Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate(WebURL.Text)
End Sub

also I have a search and I get the same error.
Ive checked the names or everything and they all match.
What do I do?


Now I have loads of questions to ask, but I really want to know how to use a database with VB.net, I connected a database which has tables such as history etc.
When 'DocumentCompleted' arrives how can I add the url and title to the database?

niceguy78
10-03-2008, 01:43 PM
Now I have loads of questions to ask, but I really want to know how to use a database with VB.net, I connected a database which has tables such as history etc.
When 'DocumentCompleted' arrives how can I add the url and title to the database?

What kind of database do you want to use? and Can you provide the code of your tabbed browser ?

Ludatha
10-04-2008, 10:16 AM
What kind of database do you want to use? and Can you provide the code of your tabbed browser ?

I want to use a Microsoft Access 2007 database.
Ive already conected it, I just dont know how to put and pull data from it.

My whole code is:

Public Class Main

Public BackCount As Integer
Public ForwardCount As Integer

Public SearchErrCount As Integer
Public SearchProvider As String

Dim i As Integer = 0

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).GoHome()
End Sub
Private Sub WebBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
Main.ActiveForm.Text = CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle + " - LudathaMicro"
WebURL.Text = CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Url.AbsoluteUri
If BackCount > 0 Then
cmdBack.Enabled = True
Else
cmdBack.Enabled = False
End If

If ForwardCount > 0 Then
cmdForward.Enabled = True
Else
cmdForward.Enabled = False
End If

End Sub

Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate(WebURL.Text)
End Sub

Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Stop()
End Sub

Private Sub cmdReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReload.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
End Sub

Private Sub cmdBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBack.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
ForwardCount = Int(1)
BackCount = Int(-1)
End Sub

Private Sub cmdForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdForward.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
BackCount = Int(1)
ForwardCount = Int(-1)
End Sub

Private Sub WebBrowser_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
BackCount = Int(1)
End Sub

Private Sub LoginToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginToolStripMenuItem.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.ludatha.com")
End Sub

Private Sub txtSearcher_DropDownItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles txtSearcher.DropDownItemClicked

End Sub

Private Sub GoogleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoogleToolStripMenuItem.Click
txtSearcher.Text = GoogleToolStripMenuItem.Text
txtSearcher.Image = GoogleToolStripMenuItem.Image
End Sub

Private Sub YahooToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YahooToolStripMenuItem.Click
txtSearcher.Text = YahooToolStripMenuItem.Text
txtSearcher.Image = YahooToolStripMenuItem.Image
End Sub

Private Sub cmdSearch_Click() Handles cmdSearch.Click
SearchErrCount = 0

If SearchErrCount = 0 Then
If txtSearcher.Text = "Google" Then
SearchProvider = "http://www.google.com/search?q="
ElseIf txtSearcher.Text = "Yahoo" Then
SearchProvider = "http://search.yahoo.com/search?p="

Else
SearchProvider = "http://www.google.com/search?q="
End If
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate(SearchProvider + txtSearch.Text)
End If
End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
About.Show()
End Sub

Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
Options.Show()
End Sub

Private Sub BookmarkThisPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BookmarkThisPageToolStripMenuItem.Click

End Sub

Private Sub BookmarksBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.BookmarksBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.LudathaMicro_DataDataSet)

End Sub

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LudathaMicro_DataDataSet.Bookmarks' table. You can move, or remove it, as needed.
Me.BookmarksTableAdapter.Fill(Me.LudathaMicro_DataDataSet.Bookmarks)

Dim browse As New WebBrowser
TabControl.TabPages.Add(i, "New Tab")
TabControl.SelectTab(i)
browse.Name = "b1"
browse.Dock = DockStyle.Fill
TabControl.SelectedTab.Controls.Add(browse)
i = i + 1

End Sub
Private Sub cmdNewTabToolBar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewTabToolBar.Click
Dim browse As New WebBrowser
browse.Name = "b1"
browse.Dock = DockStyle.Fill
AddHandler browse.DocumentCompleted, AddressOf browse_done
TabControl.TabPages.Add(i, "New Tab")
TabControl.SelectTab(i)
TabControl.SelectedTab.Controls.Add(browse)
i = i + 1
End Sub

Private Sub browse_done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
TabControl.SelectedTab.Text = CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
End Sub
End Class


I made a simple code to enable the forward and back buttons, but it kinda failed, so thats another reason for me to use the database xD

oracleguy
10-04-2008, 05:18 PM
When I type a URL in the box and click go I get this error:

Object reference not set to an instance of an object

From this code:

Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
CType(TabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate(WebURL.Text)
End Sub

That error means that one of the objects you are trying to use is null. Such as TabControl.SelectedTab.

niceguy78
10-06-2008, 10:25 AM
I want to use a Microsoft Access 2007 database.
Ive already conected it, I just dont know how to put and pull data from it.

I do not see connection line in your program, what kind of connection you use, I mean, do you use ODBC connection or SQL connection.

Ludatha
10-11-2008, 10:39 PM
Hey sorry for the late reply :O
I did actually remove the connection line, because I though I might have been the cause of the problems.
I am using SQL to connect to the database.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum