Home

Press Releases and News

Bookstore

Software

Links

About VB2Java.COM

Articles:

Visual Basic Articles

VB 2 Java Articles

Java Articles

Misc. Articles

Updated on:
Tuesday, May 05, 1998


Top


Top


Top

Visual Basic Meets Java

Appeared August 1997 issue of Internet Java and ActiveX Advisor Magazine. Page 30.

By Tom Taulli

Itís an incredible combination: allowing millions of Visual Basic programmers to convert programs into pure Java. This is what TVObjects has done with its new tool called the Applet Designer.

In September 1996, the company introduced version 1.0. Being a native Visual Basic programmer, I was impressed with how easy it was to create Java applets.

Of course, there were many functions not supported, but it was a good start. Then, over several months, TVObjects kept upgrading the product. By March 1997, TVObjects launched version 1.5. Not only did this product support new functions and controls, but also added support for JDBC (Java Database Connectivity), which is Sun Microsystemís standard for database connectivity.

TVObjects also has been aggressive in forming strategic alliances to improve the Applet Designer. For example, TVObjects teamed-up with Asymetrix (www.asymetrix.com), the developer of the SuperCede Java development tool.

How does it work?

The Applet Designer is a Visual Basic Add-in and appears on the screen as a floating toolbar with six buttons: New Java Applet, Java Data Access Wizard, Make Java Applet, Run Java Applet, Options and Help.

To create a Java applet, you will first click New Java Applet. A Visual Basic form appears on your screen with a .jav extension. As with any other VB form, you can drag-and-drop controls onto it. Applet Designer supports the following controls: CheckBox, ComboBox, CommandButton, Image, Label, Line, ListBox, PictureBox, OptionButton and TextBox.

The Applet Designer also supports many control properties (such as Visible, Enabled, Height, Alignment, and so on), methods (AddItem, SetFocus, etc.) and events (MouseDown, KeyPress, DblClick, and so on).

Once you have a form, you can start creating code. First, you need to declare all your variables. Supported variable types are: Boolean, Byte, Currency, Date, Double, Integer, Long, Single and String. You can convert these variables using Val, Str, CStr, Cbyte, Cint, Clong, CDbl, and CSng. You can also manipulate strings with Len, Left, Mid, Right, Trim, inStr, UCase, LCase and Chr. If you need to convert a date, you can use Year, Month, Day, Hour, Minute, Second and Now.

Arrays are even supported. However, the Applet Designer will not support Variant, which converts a variable according to the value itís assigned, or Object, which basically instantiates an object.

You can use such control structures as If/Then/Else, For/Next, While/Wend, and Select/Case. (However, there are limitations on Select/Case. The test expression must be numeric and there is only one expression per Case statement).

Once youíre finished writing your program, you click on the Make Java Applet button. This converts your .jav file into Java source code with an extension of .java. A report indicates whether your code has any bugs. If not, the Applet Designer creates a .class file from the .java source code and generates an HTML file with an <APPLET> tag, so the .class file is executed. If you click on Options, you can launch the applet in J++ or Visual Café.

Itís that simple.

Database Connectivity

The real power of Applet Designer is the ability to create applications with JDBC support.

To do this, click on New Java Applet and design your form. The Applet Designer supports such DAO objects as DBEngine, Database and Recordset. With the Recordset object, you can use the methods of Move, MoveNext, MoveLast and Close. Properties supported include EOF, RecordCount, Fields.Count, Fields.Name and Fields(I).Value.

After you finish creating the database form, you need to define the JDBC drivers and data sources. You do this by clicking Options > Drivers. Youíll see a dialog box that asks for:

1. Driver Name: So far, there are not many drivers for JDBC. Applet Designer comes with the JDBC-ODBC Bridge Driver and the JDBC OpenLink driver.

2. Driver: You will browse your system to find the correct driver class file.

3. Server Class Path: This is the relative path of the driver on the Web server.

Now you can create a data source by clicking on Add. In the dialog that appears, fill in the necessary information for:

1. Data Source Name: This is any name you want.

2. Database URL: This string includes the hostname and port number.

3. Database Name: This is the name of the database file.

4. JDBC Driver: This is a drop-down box of all the JDBC drivers that have been added.

Now, you need to click on the Java Data Access Wizard, which connects your applet with the database table. Enter the following information:

1. Procedure: You can use any name you want (the default is JDBCGetRecordSet).

2. Java Data Source: Click the drop-down box and select the database.

3. User: This is a valid user name (if you want).

4. Password: This is also optional.

5. SQL Table: This will select a certain table as the data source for the applet.

Test this program within Visual Basic. If there are no bugs, convert the program into Java by clicking on the Make Java Applet button. Because JDBC requires support for JDK 1.1, you will need to execute your database programs using the Applet Viewer (which is bundled with the Applet Designer). As of this writing, Explorer and Navigator do not support this JDK version 1.1.

Odds and Ends

 

The Applet Designer creates a .java file so you can load it into a word processor or a compiler (such as J++) and see the Java code. In fact, the Applet Designer creates well-structured code and is well-commented. This can be a great learning tool because it shows how the code syntax in VB relates to Java.

But the Applet Designer does not do everything. For example, there is no exception handling, which is vitally important in Java.

Another drawback is that, as your applets get more sophisticated, youíll need to be able to add code to the .java sourceómeaning that you will need more than a passing understanding of Java.

However, if you are familiar with the VB GUI, you can easily create the interface, as well as functionality for your applications. I found this to be a faster process than writing a program completely in a Java IDE.

If you want a sneak-preview of the product, you can download a demo copy of the Standard edition from the TVObjectsí Web site (www.tvobjects.com). When you do this, youíre also entered into a contest to win a free copy. The demo copy works for only two VB sessions.

The Applet Designer is easy to install and runs on Windows 95 and NT. As for Visual Basic, you need at least the 32-bit version of VB 4.0.

When you purchase the Applet Designer, you receive 30 days of free technical support. Thereís a Knowledge Base on TVObjectsí Web site, but itís not very comprehensive. Rather, it is an update of the productís specifications. It would be nice to see an FAQ.

The documentation is sparse. Iíd like to see more examples (thereís only one example for the database features).

Conclusion

This program is fun and Iím sure it will get better. TVObjects seems to be intent on creating a rapidly evolving product--which is necessary, since the trajectory of Java is so quick. If you are a VB programmer and want to try Java, then Applet Designer is the product for you.

Pros:

1. Easy to build JDBC databases.

2. Is a great learning tool.

3. Creates well-documented and structured code.

Cons:

1. Documentation is sparse.

2. Should have provided more examples.

3. No exception handling.