Professional Documents
Culture Documents
Table of Contents
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data
sources and Web Services ............................................................................................................ 1
Exercise 1 Create the InteropForm Library ...................................................................................................................2
Exercise 2 Create the web service .................................................................................................................................4
Exercise 3 Create a Visual Basic 6 Application and Utilize the InteropForm Library ..................................................7
Conclusion .....................................................................................................................................................................9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Page 1 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Exercise 1
Create the InteropForm Library
Scenario
We’ll start off by creating our InteropForm library, which will be called from our Visual Basic 6 application. This
form will include data from 2 tables, and will call a web service to retrieve data.
Page 2 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Tasks Detailed Steps
h. Click on CategoryID, choose the arrow, and select [None].
i. Now drag “Products” over to your form in the designer.
Note: Because we selected “Details”, we are given controls based upon the data type
of each element in the Products table.
4. Create a a. Drag our InteropForm1 form to resize it bigger. We need to add room to the right
DataGridView for of our current text boxes. Make it roughly double it’s current size.
the Suppliers table b. Under Data Sources, click on the arrow next to Suppliers, and choose
DataGridView.
c. Drag Suppliers to our InteropForm1 form, to the right of our last control.
d. Expand the DataGridView to fill in the area next to the text boxes.
e. Choose File | Save All. Press the Save button when Save Project dialog comes up.
Note: We now have a form that will display information in both a data grid and in text
boxes.
Page 3 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Exercise 2
Create the web service
Scenario
This web service will return information back to our InteropForm Library. Creating the service and consuming it is
very easy, as illustrated below.
<WebMethod()>_
Public Function GetQuote(ByVal ticker As String) As
String
End Function
Note: As stated earlier, we are returning static values for our 3 different companies
we are tracking with this sample. In an actual web service, we would put in code to
get the real-time value of the stocks and return those values. For future web service
development, you can have many different functions available to the calling program,
all residing the same service. Just as we now have GetQuote and HelloWorld, we can
add many more funcitons to this service. You would then just call the appropriate
function that’s going to return the specific data you’re looking for.
2. Add the web service Note: Visual Studio 2005 has a built in web server to test your web based projects on.
into our InteropForm This prevents you from having to have IIS fully installed and configured, as well as
Library giving us a very controlled environment over your development projects. We need to
start our debugger here to find what port it starts our web service on, since it chooses
a different port every session visual studio is run. For the most part, if Visual Studio
Page 4 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Tasks Detailed Steps
is left open, the same port will be used for that entire session.
a. Right-Click on TestWebService, and select Set As Startup Project
b. Click Debug | Start Debugging.
c. Click on OK when the “Debugging Not Enabled” prompt comes up.
Note: A new browser will open up with a Directory Listing to the TestWebService
folder.
d. Copy the URL in the address bar of the browser.
e. Close the browser.
f. Under Solution Explorer, Right-Click on InteropForm, and select Add Web
Reference.
g. Paste in the URL that we copied before into the URL text box, and add
Service.asmx?wsdl to the end of it.
Note: The entire url will end up looking similar to
http://localhost:1097/TestWebService/Service.asmx?wsdl
(The port number will in all likelihood be different than 1097)
h. Press the Go button.
i. Visual Studio will attach to the web service, and then show what methods are
available. Here, we see there is our newly created GetQuote method and the auto-
generated HelloWorld method.
j. Under Web reference name, name it myWebService, and press Add Reference.
Note: We will now be able to connect to this web service and utilize the functions
available through it.
3. Add a call to the web a. In the Solution Explorer, double click on InteropForm1.vb
service Note: This brings up our form in the designer
b. From the Toolbox, drag a button to the bottom left of the Form.
c. In the properties window, change the Text attribute to “Get Quote”.
d. From the Toolbox, drag a ComboBox to just above our Get Quote button.
e. Click on the ComboBox Tasks button “>” and choose Edit Items.
f. Add “msft”, “ctso”, and “fabk” to our String Collection Editor. Click OK.
g. From the Toolbox, drag a Label to the right of our button.
h. In the properties, change the Text property to “quote price”.
i. Double click on our Get Quote button. This will generate a click event.
j. Add the following code to the Button1_Click function
Page 5 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Tasks Detailed Steps
Note: That’s it, we’re all set now. Because we generated the wrapper classes, then
built the solution, it’s now registered in Visual Basic 6 so we can add a reference to it.
Page 6 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Exercise 3
Create a Visual Basic 6 Application and Utilize the
InteropForm Library
Scenario
To show the interoperability of our new .NET form with Visual Basic 6, we need a simple application that will
initialize and show an instance of our new form.
Page 7 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Tasks Detailed Steps
combo box, and click the Get Quote button.
Note: This calls the web service, which returns back the stock quote. We now have
successfully displayed information out of a database, and from a web service, all from
our new .NET form which was launched from Visual Basic 6.
Page 8 of 9
Interop Forms Toolkit 1.0: Bringing the Power of .NET to Visual Basic 6, Utilizing Data sources and Web Services
Conclusion
Making Visual Studio .NET 2005 forms available to Visual Basic 6 applications allows you to keep your existing
program, while leveraging the power of .NET, preventing you from having to rewrite applications. All of this was
able to be performed while only adding 2 lines of code to our Visual Basic 6 application. This will allow your old
applications to live on, while taking full advantage of .NET technologies and libraries.
Page 9 of 9