Tuesday, November 11, 2008

Fri Nov 14: part two

OK, so as you may have guessed, what we're going to try to do is to be able to open up a webpage in your textbox, where you can change it's code. Then, you can save the changes, THEN you can open up this new improved webpage in a webbrowser so you can see the differences.

Now, here's the rest of the steps in how to do that:

A) Add a label to the bottom of Form1, somewhere underneath the textbox. No need to rename this either

B) Add this code to the "Open in Browser menu item code, just above the one line of code you already have there (ya know, the one that says Form2.visible = true)

'set the value of the current file being worked on into this Label
Label1.Text = theFileName
'call the function in the module that makes use of the text value of this label
'in assigning a URL to the webbrowser control in Form2
ShowInBrowser( )

C) Since we're going to be passing information from one form to another, it would easier to use a module. So, create a module by clicking on the "Project" menu, then clicking Add Module

D) In this module, you will need to add a simple function that will receive the value of the text in that new label you made, and return it as a String variable to Form2. Here's how my function looks:


Public Function ShowInBrowser( ) As String
Dim sendPageInfo As String
sendPageInfo = Form1.Label1.Text
Return sendPageInfo
End Function

E) Finally, you have to get into the code for the "Form Load" event for Form2. You should know how to get there already; when you do arrive, add this code to it:

'show which webpage we're loading into the browser
MsgBox(ShowInBrowser())
'make the browser go to the webpage we want
WebBrowser1.Navigate( New Uri(ShowInBrowser( ) ) )

OK, that should do it. Compile, make sure you gots no errors, then run the program. You should be able to open a webpage in your textbox so that you only see its code, you can change that code, save the changes then observe the changes by opening it in a browser you made yourself!

cheers,
Mr. L

PS If you need a webpage to play with, I uploaded one to the VBdepot folder on Box.net

No comments: