PDA

Click to See Complete Forum and Search --> : Opening URL in browser


pipes
Sep 25th, 2000, 03:39 AM
Hi everyone, this is my first post to the forum, but I've been reading it for a while. I'm fairly new using VB, compared with some other people, and having some trouble with something which I'm sure is quite basic.

I've designed an Active X Document DLL embedded into a webpage. When the command button is clicked on, my code is processed and the output is an html file. Once the code has finished processing I want the browser to go to the location of this generated html file. Does anyone know how I can do this?

I've tried using a combination of the Inet component, with Inet1.OpenURL in my code, but it doesn't seem to work. As the Active X is embedded into an html page already, I don't want the system to open a new instance of the program, just load the new html page into the current window.

Thanks in advance for any replies,

Paul

reeset
Sep 26th, 2000, 12:16 AM
I'm a little confused. I guess what I need to know is if the active x dll is being run on the server side (via asp), or been loaded into the webpage as an ocx. Anyway, I will assume that it is being run on the server side (via asp). If this is the case, then this should really be quite easy. It would kindof look something like this:



<html>
<head>
<title>Test asp</title>
<%

Dim sDll 'holds the created object
dim variables 'variables that you pass
Dim sURL 'returns the file name
Dim lret 'return variable of function to test if successful
Dim rootaddress 'this is your servers address up the directory where the html file is generated.

rootaddress="http://www.myserver.com/"

Set sDll=Server.CreateObject("MyDLL.Class1")
lret=sDll.GenerateHtml(variables,sURL)
If lret <> 0 then
window.open(rootaddress & sURL,'','width=400,height=400,scrollbars=yes,resizable=yes')

Else
response.write "An Error has occurred"
end if

%>

</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
</body>
</html>




Now the sDll.GenerateHtml would need to be a function with either 1 of two syntaxs. You can use the syntax that I have used in my example, where the function would look like:



Public Function GenerateHtml(Byval variables as string, sURL as string) as long
On Error GoTo ErrorHandler
....some code here......
sURL=Name of the File as appearing on the server
GenerateHtml=1
exit function
ErrorHandler:
GenerateHtml=0
End Function



Or you could just have the function return the filename, rather then a long, so it would look something like:



Public Function GenerateHtml(Byval variables as string) as string
On Error goto ErrorHandler
...Do something....

GenerateHtml=Filename
Exit function
ErrorHandler:
GenerateHtml=""
End function




There are a lot of different ways that you could do something like this. I'm just giving you one that I have used before. I hope this helps.

pipes
Sep 26th, 2000, 02:35 AM
Hi Reeset, thanks for replying. That's not exactly the type of thing I had in mind though. I'm not using asp or any servers here, it's just a small demonstration program. I've designed it as an Active X Document DLL, compiled the dll file, and run the application setup wizard to create a .vbd file. This file is then referenced in an html page, ie:

<SCRIPT LANGUAGE="VBScript">
Sub Window_OnLoad
Document.Open
Document.Write "<FRAMESET>"
Document.Write "<FRAME SRC=""UserDocument1.VBD"">"
Document.Write "</FRAMESET>"
Document.Close
End Sub
</SCRIPT>

So "UserDocument1.vbd" is loaded into a webpage, basically just looking like a VB app but in the browser. I am not concerned about distributing on the Internet, this is just for a demonstration on a local machine at the moment.
Let's say for simplicity, that all the program does is takes two values from a user, adds them together and writes the result to an html file called results.htm, just using the normal code:

Open "C:\Example\results.htm" For Output As #1

This all works fine, but once the the processing has finished, in this case the numbers have been added together and html page created, I want the browser to then display the results.htm page. So all I want it to do is load the results page over the current page. I'm sure it's just a few lines of simple code, but I just can't seem to get it to work! The path of the html page will always be the same, so it can just be set in the program, no problems there.

I hope this is a bit clearer! Any further help would be greatly appreciated.

Paul

reeset
Sep 26th, 2000, 01:58 PM
This use to be a whole lot easier then it use to be. The reason is that in IE 5.0, microsoft removed interactivity with the frames collection. Now, if memory servers me, you can only request the number of frames on a page. Anyway, if you can avoid using frames, this would be much easier.
There are a couple of ways, I suppose that one could go about do this. (using the Findwindow API and then Setting the Text), but I prefer to call the shell application object. Now what this is basically doing, is enumerating the shell object, and finding those objects that have application properties. Remember, all IE is, is explorer, with an application object. So this is what I would do.

1) Have your program do what it does, and generate the html output file. Then, pass the path of this file to the following sub.



Private sub GeneratePage(byval sresults as variant)

Dim objShell as object
Dim objShellWindows
Dim objIEApp


Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

'Here we place all open sessions of IE into a collection.
'So the first instance of IE would be item(0), the
'second item(1), the third Item(2) and so on. You can
'the Window count by using objShellWindows.Count

'The objShellWindows.Item references a particular ie object
'within the collection. 0 is the first, 1 the second and so
'on. Anyway, if you have multiple ie windows opened, you
'will need to find the right one out of the collection. The
'easiest way to do this, (since you are looking for the same
'page everytime) is to have it look for a particular
'document title. Here is an example of the loop:

x=0
Do

Set objWindow = objShellWindows.Item(x)


'Set the on Error, just in case an instance of IE does
'not exist.

On Error Resume Next
'Once set, you can do anything with IE that you could
'do with the Webbrowser control. You have total control
'of the available features.

Set objIEApp = objWindow.Application 'get the application object
If Err<>0 then
exit sub
end if

Loop Until objIEApp.document.title="Testpage"

'without frames, you would use this syntax to simply change
'the address and navigate to a new page.

objIEApp.document.location.href="c:\windows\desktop\bg.html"

'With frames, you would have to use the something like
'[object] [framename] [src=]
'or
'[object] [framename] [document] [location] [href]
'but I would recommend against using frames if you don't have to

'Destroy the object

Set objIEApp=Nothing
Set objWindow=Nothing
Set objShellWindows=Nothing
Set objShell=Nothing
end sub



I hope that this helps.

pipes
Sep 27th, 2000, 06:59 AM
So assuming I don't use frames, the only part of the code I need to customise is:

Loop Until objIEApp.Document.Title = "Testpage"

objIEApp.Document.location.href="c:\windows\desktop\bg.html"

Is that right? I just change those values to the ones I want? I am trying to call the procedure at the end of my code, just by typing in GeneratePage, but it gives me a Compile Error: Argument not optional. How do I call it?

When I tried to run the code on its own, it told me firstly that "x" hadn't been defined, so I added "Dim x as Integer" to the top. Then it says "Run time error 429: ActiveX component can't create object". Debug sends me to the line Set objShell = CreateObject("Shell.Application").

I don't know if I'm being stupid here or whether it's just hard!

Thanks for your continued help though..

So what now?

Paul

pipes
Sep 28th, 2000, 06:18 AM
Reeset,

I found a great file at download.com called weblink.ocx When installed as a component, I just drag and drop it like a normal command button. Then just set the url in the property and everything works out exactly how I wanted it to!

Thanks for your help though, much appreciated.