How to open a Bing Maps from vb.net? - vb.net

I would like to pass and address to and open Bing Maps from a vb.net app. Anywhere I can find an example of how to do this?

You're going to want to check out the Bing Maps Web Services SDK. It allows you to use Bing to Geocode (retrieve a location from an address) as well as Download Imagery Data. Another place for Bing developers information can be found here.
Edit: I just reread your question and I think you can do what you need using a simple string concatenation to create a url. This might work:
Dim MyURL As String
Dim Location As String
Location = "Pittsburgh, PA"
MyURL = "http://www.bing.com/maps/?v=2&where1=" + HttpUtility.UrlEncode(Location) + "&encType=1"
System.Diagnostics.Process.Start(MyURL)
My VB is a little rusty, but this should get you started. You will also need to import the System.Web Namespace for the HttpUtility Class.
Refrences:
Launch Browser from VB.NET
HttpUtility.UrlEncode Method - MSDN
Bing URL Parameters

'In addition to kersney's example this uses the webbrowser control in a vb form
Imports System.Web
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Location As String = "Pittsburgh, PA"
Dim MyURL As String = "http://www.bing.com/maps/?v=2&where1=" + HttpUtility.UrlEncode(Location)
Dim WebBrowser1 As New WebBrowser
Me.WindowState = FormWindowState.Maximized 'maximize window
Me.Controls.Add(WebBrowser1) 'add browser control
WebBrowser1.Dock = DockStyle.Fill 'fill to form
WebBrowser1.Navigate(MyURL) 'display page in form
End Sub

Try the nerd dinner asp.net mvc tutorial. It's near the end and you can download a working example.

Related

Manipulate text in a loaded html-page of the Webbrowser control in the DocumentCompleted event (vb.net)

I already tried some solutions provided here, but I cannot get it to work. On my winform I have a webbrowser control which should load a webpage (aspx). In case the webpage isn't found, I want to let the user know that this page isn't found. To get this to work I use the following code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (WebBrowser1.Document.Url.ToString().StartsWith("res:")) Then
Dim curDir As String = Directory.GetCurrentDirectory()
Dim Url As Uri = New Uri(String.Format("file:///{0}/Html/PageNotFound.html", curDir))
WebBrowser1.Navigate(Url)
End If
End Sub
This is working fine. The page PageNotFound.html is shown. However, I would like to provide the user with some additional information which I want to insert into the PageNotFound.html at realtime (i.e. using document.getElementById to manipulate a Label-tag). I just don't know how I can do this, or if it is even possible. Maybe I use the wrong event. something I also tried is:
With WebBrowser1
.Navigate("about:blank")
.Document.OpenNew(False)
.Document.Write(HtmlString)
.Refresh()
End With
Where the HtmlString contains a complete webform.(like: "")
Maybe someone put me the right direction? TIA

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub

Visual Basic - Web browser load URLs from text

i am not so great with Visual basic, but i need some help on creating a web browser that would load several links import from a text file, and for the web browser to navigate to them. This is what i have so far
Dim link As String = OpenFileDialog2.FileName
Dim links As String = IO.File.ReadAllText(link)
MsgBox(links)
WebBrowser1.Navigate(links)
You help means a lot. Thank You.
The WebBrowser Control either will show the webpage in the Control which will limit you to one page, or you can tell it to open the pages in separate windows which will open an Internet Explorer window for each link. I also used the File.ReadAllLines Method in order to get an array of the Links so that you can iterate through the Web Pages . This works for me but might not be what you are wanting.
Public Class Form1
Dim wb As New WebBrowser
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim filename As String = "C:\temp\links.txt"
Dim links As String() = IO.File.ReadAllLines(filename)
For Each link As String In links
wb.Navigate(link, True)
Next
End Sub
Public Sub New()
InitializeComponent()
Controls.Add(wb)
wb.Dock = DockStyle.Fill
End Sub
End Class
My text file called Links.txt looks like this:
www.google.com
www.msdn.com
www.bing.com

NO WAY to get the text from a panel control of another application

I'm trying to get information from a windows form of another application.
I can read data from textbox or label of this application but not from a PANEL,because this panel doesnt contain controls.
I need your suggestions.
Thanks in advance.
Here the code that i'm using :
For Each top As windowsAPIoutils.ApiWindow In enumerator.GetTopLevelWindows()
For Each child As windowsAPIoutils.ApiWindow In enumerator.GetChildWindows(top.hWnd)
If top.MainWindowTitle.StartsWith("TITLE_Of_APPLICATION") Then
'The class name of the control
If child.ClassName = "TEdit" Then
textbox1.Text = child.MainWindowTitle
End If
End If
Next child
Next top
The only way that you can use the Win32 API to do this is if the item whose text you want to grab is a Win32 control, backed by an actual window.
That's why it works fine if the other item is a textbox or a label, because those are both implemented using Win32 EDIT and STATIC controls, respectively.
I don't know exactly what you mean by a "panel", but my guess is that it has been custom drawn by the other application. You'll therefore need to ask that application for the text it contains. Windows cannot give it to you because it is not a standard Windows control. If you cannot ask the other application, for whatever reason, you will need to research alternative methods, like UI automation.
If by "panel", you mean a group box, well then that is just a standard Windows button control and it has a caption (displayed at the top). You can retrieve that in the same way you'd retrieve the caption of a label control. In Win32 terms, that means sending a WM_GETTEXT message to the control.
Here is a solution that i used:
Tesseract an open source OCR engine and here the link to get it : https://code.google.com/p/tesseract-ocr/
how to use it :
Imports System.IO
Imports System.Threading
Imports System.Collections.Specialized
Public class myClass
Private ProcessList As New Hashtable
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim croppedFile as String = "C:\image.tif"
Dim OCRProcess As Process = New Process()
OCRProcess.StartInfo.FileName = "C:\tesseract\tesseract.exe"
OCRProcess.StartInfo.Arguments = croppedFile & " " & croppedFile & " -l eng"
OCRProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
OCRProcess.StartInfo.CreateNoWindow = True
OCRProcess.EnableRaisingEvents = True
AddHandler OCRProcess.Exited, AddressOf Me.ProcessExited
OCRProcess.Start()
ProcessList.Add(OCRProcess.Id.ToString, croppedFile & ".txt")
Do While Not OCRProcess.HasExited
Application.DoEvents()
Loop
End Sub
Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Proc As DictionaryEntry
Dim oRead As StreamReader
Dim EntireFile As String = ""
For Each Proc In ProcessList
If (sender.id.ToString = Proc.Key) Then
oRead = File.OpenText(Proc.Value)
EntireFile = oRead.ReadToEnd()
End If
Next
MsgBox(EntireFile)
End Sub
End Class
Hope it will help someone

How to get HTML from the URL and display it in certain place?

I'm in progress with my first application in visual basic, and I'm using the visual basic studio - My question is, how can I get raw HTML data from specified URL, and then display it in my form on the certain position?
I havent tried anything yet, because I havent found much solutions about this on the internet.
You need to use the HttpClient class or the WebClient class to get the raw HTML as a string. Then, you can simply display the string in any control on your form such as a TextBox or Label control.
For instance:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim client As WebClient = New WebClient()
Label1.Text = client.DownloadString("http://www.stackoverflow.com")
End Sub