...

View Full Version : [vb] How do you open an IE window with vb



Bry Man
02-11-2005, 02:57 AM
Hey,

I would like to know how I can get vb to open an internet explorer (or even better the default browser) with vb. I have done alot of googling into this matter but what I find doesnt work so I figuried Id ask here. I know that vb has a built in browser and Im using i currently but what im wanting to do requires a browser outside of the program, also it would help a great deal if I could open it at a certain size so that I could have the program that opened it visible as well. Here is some code that I found on the net, the only thing is when I click the button it does nothing, I had to make a reference to the Microsoft internet controls to get it to even run.


Public ie as InternetExplorer
Private Sub Command1_Click()
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate2 "http://visualbasic.about.com"
End Sub

tboss132
02-11-2005, 06:57 AM
There was something i tried once. Don't remember the code offhand and i don't have vb on this machine...
I had a page1 on my system which pops up page2 (using vbscript or javascript) when loaded. I used VB's browser control on the form and set it to invisible. It was something like this

Form Loads > browser control loads page1 > page1 pops open page2

Page2 opens in the default browser.

shmoove
02-11-2005, 02:02 PM
For the code you posted I'm guessing you need to find a method to make the application visible (Show or something like that).
Have you tried using the Win32 API function ShellExecute? I think it would open the default browser. Controlling the size of the browser you open with it would be tricky and I imagine you would need to use other Win32 functions to control that (FindWindow, etc.).

shmoove

Bry Man
02-11-2005, 03:23 PM
From what it sounds like Tboos, your method wouldnt work for me, I need something like in the code I posted that stores the instance of IE as a variable so I can pass information to the window thru the variable. As for shmoove, the Show property can't be used on the IE thing, gives me an error, and nothing else that It could use seemed to do the trick. I have not used the api functions cuz I really dont know em but Ill look into that later on today I suppose. :)

Anthony2oo4
02-11-2005, 09:00 PM
Your in luck, im useing the same type of thing for a project im on now :D

Here, use my code. It opens athe default browser with whatever you want, am not sure about how to specify the size tho, maybe someone here can edit it ;)


Option Explicit
'Browser Command
Private 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

Private Const SW_NORMAL = 1

Private Sub cmdBrowser_Click()

If txtAddBar.Text = "http://www." Then
msgError = MsgBox("Please enter a valid URL.", 64, "Error")
Else
blocation = txtAddBar.Text
ShellExecute Me.hwnd, vbNullString, _
blocation, vbNullString, _
"C:\", SW_NORMAL
txtAddBar.Text = "http://www."
End If
End Sub

Make a text box called "txtAddBar" and your set. This will take whateva is typed in a text box and open it in a default browser. Also make a button called "cmdBrowser", lol nearly forgot about that one.

If you want it to not have a text box, im sure ppl can edit it here, if not ill do it on request ;). Enjoy

*EDIT*

After reading your post, i see you do want it to open a specific webpage so use this code instaed. I'll leave that one there abouve incase anyone else needs it.

Use the same code as above, but for your button use this code:


Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, _
"http://visualbasic.about.com", vbNullString, _
"C:\", SW_NORMAL
End Sub

oracleguy
02-11-2005, 09:17 PM
This thread is your friend: http://www.vbforums.com/showthread.php?s=&threadid=213415 A great list of APIs to be used with VB.

Bry Man
02-11-2005, 09:56 PM
I appreciate your help as well but I dont think it will work either, I tried it out and all it does for me is open the default browser. Ill try and explain a bit more on what im attempting to achieve. I have a program already that sends commands to the built in browser that vb has, here is an example of the code that will send a serach value into googles serach box and search for it.


wbBrowser.Document.getElementsByName("q").Item(0).Value = "Coding Forums"
wbBrowser.Document.getElementsByName("btng").Item(0).Click

Im just trying to move away from the built in browser to the users default because it would be far more convienent for me and them and would open a few more windows for me to improve my existing program. I did look into the shellexecute stuff and have gotten it to open internet explorer, tho im sure it can be set so the user can pick, the only thing is that doesnt do what im looking for either.

Anthony2oo4
02-11-2005, 10:30 PM
I dont know if I full understand what you mean, is this the only thing you wanna throw over to the browser?

If so then why not try this:


Private Sub Command1_Click()
Dim gsearch As String
gsearch = "http://www.google.co.uk/search?hl=en&q=" & Text1.Text
ShellExecute Me.hwnd, vbNullString, _
gsearch, vbNullString, _
"C:\", SW_NORMAL
End Sub

Just simply make a text box and a command button.

If am wrong then im sorry i dont understand, can I have your project files to see more detail?

Thanks

Bry Man
02-11-2005, 11:53 PM
I could give you the project files, the thing is this is my first really big progam (over 6000 lines, prolly 50% overkill :) ) and its something that is highly coveted in the game I play, kings of chaos, it is an autobuyer and I dont really want it to fall into the wrong hands but if you really want it ill pm you the url to download the project.

EDIT: bah ill just post it here

Anthony2oo4
02-12-2005, 11:36 AM
I keep getting an error with this line


BuyVal1 = txtBuy1.Text

So i cant explore the program much :(

Bry Man
02-12-2005, 05:38 PM
Ya I just recently put all the stuff onto that tabbed thing so that may have messed it up a bit because I copyed the stuff deleted the ld stuff and re-pasted it onto the tabs. Also you have to be authorized to use the program or it wont work, also the site that I have the auth file on is down so you couldnt use it if you were authorized....ill put up the older untabbed version for you then. If you want to use it fully youll have to create an account on kings of chaos and tell me your name so I can authorize you when the sites back up. I am having a slight problem with it not filling in the site before moving on which should not happen but it will give a type mismatch error 91 on occasion, but it does work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum