Conversion Guidelines
and Troubleshooting





Conversion Guidelines

  • You can insert Java code in the generated code by prefacing each line of Java code inside your VB code with the following 6 characters 'java . This will make the line a comment which VB will ignore but will be executed when running in Java. Make sure you end the line with a ; as is required in Java. This only works inside a Function or Sub. For example:

    'java Text1.setSelectionColor( Color.yellow );

  • You can cause VB code to not show up in Java by prefacing the lines with 'vb_only. Then after the last line to be ignored add in a 'end_vb_only. This is not recommended outside of a Function or Sub. For example:

    Text1.Text = "hello"

    will cause that line of code to show up as comments in the Java code. If you do not want them to appear as comments you can set the preference KeepVBOnlyAsComments=0 in the <product name>.ini file in the windows directory.
  • The VB Converter add-in requires you to be at the latest service pack. For example, SP3 of Visual Basic 5.
  • If you have written an ActiveX Control in VB you should include it in the project that makes reference to it. The control will be converted to Java and all references to the control will made automatically.
  • If you have a project that creates a DLL and that DLL is used in another EXE project then you will want to create a new EXE project that contains all of the modules, classes, UserControls, etc from all of the DLL projects and the original EXE project. Then use the converter to convert the entire code base at one time.
  • If you are using a variant and did not use one of the conversion routines when you are using a variant someplace that another type is expected, Java cannot automatically coerce the Variant to the right type. You must call one of the toInt, toDouble, toDate, or toString functions on the Variant to access the value.
  • The static modifier on functions and property get/set functions are not supported.
  • Must set user.timezone property for the Now, Date, Time, functions to have the date and time in the correct timezone. Otherwise, it will always be returned using the GMT timezone. You can set it by:
    java -Duser.timezone=MST MyApp
  • With statement is not supported in all contexts. If you get an error on a line using the '.' operator then just add the full object reference before the '.'
  • The IsObject and IsNumeric will have compile time errors for variables whose type can be determined by the programmer looking at the code. This will make for faster programs by removing this unneccessary logic.
  • File IO
    Only text files are supported. Open "file" For Random or Binary is not supported.
  • If you are passing a control as an argument to a function be sure to specify the exact type and not just Control. Otherwise, you will not be able to access the properties specific to that type of control. For example:

    Sub Foo( text As Control )

    Should be:

    Sub Foo( text As TextBox )

  • If you programatically move or resize controls you must use pixels instead of twips. Set the ScaleMode of the Form to pixels.
  • If you use the default ODBC-JDBC database driver, remember to setup an ODBC data source from the ODBC settings in windows control panel.
  • You need to install the Java 2 plugin in your browser in order to run your program as an applet.
  • Make sure you have a "" string for the connection argument. It cannot be a variable.
  • When calling Connection.Open or setting the connection string, pass the user id and password as separate arguments instead of embedding them in connection string if they are not making it properly to the database.
  • The VB command-line arg can be passed to an applet by using the param named "cmd". For application just pass the value to the command-line when starting the Java program.
  • If you specify an argument to your Sub or Function you should supply a default argument:
    Sub test(Optional op As String = "+")
  • With statement is only partial supported. If you get syntax errors during the conversion for lines inside a With statement try removing the With statement and expanding all of the expressions using the "With" expression.
  • All variables used inside an error handler must be declared before the On Error statement
      Dim op As String
      On Error GoTo ErrHandler
      Err = "Operation " & op & " failed."
  • Put as few statements inside the 'On Error Resume Next' and 'On Error GoTo 0'. Place the error checking code after the 'On Error GoTo 0'. This will improve the readablility of the Java code.
      On Error Resume Next
      x = 1 / 0
      On Error GoTo 0
      If Err Then ...
  • Conditional returns from Gosub are not supported. You may only have one Return statement per Gosub
  • If you have modified the java code generated by a previous version of AD, you will need to regenerate and redo the changes in order to take advantage of the later version of the AD library. You can use windiff to spot all of the changes you made.
  • You can use CDbl on a Date to manipulate it as a number of days then assign it back to a Date variable
  • You can use jdbc driver and jdbc url in connection string to programatically set them on db connection open
  • If you want a menu item to be checked or unchecked, you must make it checked at design-time then uncheck it on Form_Load
  • Java coordinates are in pixels, so you should set scalemode on forms, frames, and pictureboxes to pixel instead of twips to get maximum compatibility.
  • VB will allow you to use a property as if it were a function i.e. rs.EOF(). If you get a syntax error during conversion try removing the '()' in the VB code i.e. rs.EOF
  • VB will allow you to use a function that doesn't require arguments as if it were a property. If you get a syntax error during conversion try adding the '()' at the end of the function name in the VB code.
  • If you have written your own collection class that has elements other than Variants then you will need to add an extension rule to the custom.vb2java file in the <install dir>\Rules directory:

    For example, if you have a collection called collectionUser that you can add instances of the class clsUser to then you would add something like:
      class clsUser
      class collectionUser extends UserCollection
      attribute 1based
      default Item
      property clsUser Item
        get = $obj$.getItem( $index_var$ )
        set = $obj$.Add( $val$, $index_var$ )

Conversion Rule File Notes

  • Any forward declaration of a subclass of Collection must define it in the forward declaration for example:

    class Fields extends Collection

    not just: class Fields


  1. When Java code is being compiled it generates an error " Package diamondedge.vb not found in import"?

    This would indicate that your classpath environment variable is not correctly set. Many Java products will modify this variable when they are installed which may cause you problems. Our install program will set it but it may have been changed since then by installing other Java products. You can uninstall and then re-install VB Converter or you can modify the classpath variable by hand. To modify it by hand, make sure you have "." and "<installdir>\vbc.jar" in your classpath variable. The directory paths are separated by a ";". On NT, you set it from the System control panel on the environment tab. From Win95 you need to set it in the autoexec.bat file. For example, if you installed VB Converter in the default directory:
      set CLASSPATH=.;c:\Program Files\VB Converter\vbc.jar 
    On Win95 you need to reboot and on NT you need to close VB and re-run it.
    Once you have everything properly installed, all of the samples will compile without errors. If the above doesn't help, send us an email of your environment variables by typing "set" at a DOS prompt. Also, include the VBConverter.ini file located in your Windows directory.

  2. When Java code is being compiled it generates an error " Package diamondedge.swing not found in import"?

    This would indicate that your classpath environment variable is not correctly set (see previous explanation). This package is found in "<installdir>\dsuite_eval.jar". This is the optional Diamond Control Suite package.

  3. I get a "CreateProcess failed" error or no errors and a "Compilation failed" when trying to convert a sample program.

    The most common reason is due to the path name you specified for the Java Compiler in the VB Converter options (Environment tab) is not correct specified. Make sure you have specified the entire path name and that the file actually exists and that the file is actually a Java compiler (usually javac.exe).

    If you press the Browse button next to the place to enter the path, you can use a windows dialog to select the javac.exe and therefore be sure that what you have is correct.

  4. When I loaded my applet, it said "noninit" or "applet not initialized" in the browser's status bar. How can I identify the cause of the problem?

    The complete error message and cause will be listed in the Java Console. If you are using Java 2, the default option, you will need to activate the Java Console by running the "Java Plugin Control Panel" from the Start button inside the Programs folder. If you do not have this then you have not installed the Java 2 JRE or SDK. On the Java Plugin Control Panel check the Show Java Console checkbox. The Java Console will then display each time you run a Java 2 Applet in your browser.

    If you are running as a Java 1.1 Applet then it will use the built-in Java engine and you should launch the Java Console by clicking on the Communicator->Tools->Java Console menu item in Netscape or the View->Java Console menu item in Internet Explorer.

    If you see a class not found exception then you do not have the Java class library installed properly. See the deployment section of the documentation.

  5. My database application works fine when I launch it from VB Converter's "Run Java" button but doesn't work in IE.

    Microsoft changed the name of the JBDC driver. In order to get it to work for IE you will need to change the name of the driver in VB Converter.

    1. Go into VB Converter Options Dialog and switch to the Database tab.
    2. Press "Add Driver" and enter then OK
    3. Select the dmv(sun.jdbc.odbc.JdbcOdbcDriver) Data Source then press Setup.
    4. Select the "" from the combobox for the jdbc driver. Then press OK.
    5. Make sure you have the AWT (Java 1.1) option selected. Otherwise, you will need the Java 2 plug-in installed for IE.
    6. Hit Make Java button in the VB Converter toolbar and re-launch the generated .html file in IE.

  6. My application works fine when I launch it from VB Converter's "Run Java" button but doesn't work in IE or Netscape browsers.

    One possible reason is that you are using the Java 2 swing controls (set in VB Converter Options dialog). You will need to install the Java 2 plugin for your browser. VB Converter will generate the .html to use the Java 2 plugin. See the following for more information about the HTML for using the Java 2 plugin:

  7. I get a exception relating to security or a message about "access denied" in the Java Console when running an application in a browser.

    Most likely the applet has attempted to execute native code which Java will not allow applets to do. The most common native code is from the JDBC-ODBC driver. Since this driver uses Windows native code, the driver cannot be used in applets because it is a Java security violation. With Java 2 you can customize your security policy to allow this.

    Another common cause is that in Java 2, the security model became more flexible in that you can specify what you will and will not allow to happen. The default security permissions is much tighter and will not let many applets run without changing the security permissions. You might use one of the following:

    • If you are using the Java 2 plugin you can change the security options for your machine. Java has a tool called the policytool to do this. Or you can edit the java.policy file usually located in <JRE install dir>\lib\security. The following will allow any Java program loaded from your local hard disk to have full access to your computer. This is very similar to the sandbox security model of Java 1.0. Add the following lines to your java.policy file:
      grant codeBase "file:/-" {
    • Run it as a stand alone application from the command-line or from a desktop shortcut. Make sure you specify the "Start in" to be the directory that the html and java code resides in.
    • Make your applet a "signed applet" which a browser can be set up to trust it to do anything it pleases to and essentially turns off the security manager for that applet. To do this you would create a jar file using the jar tool and provide a digital signature using the jarsigner tool.
    • If you are using ODBC, make sure the Windows ODBC driver is setup properly in the Windows control panel. Also make sure you have setup the data source in the VB Converter Options dialog (Database Tab).
    • If using IE and Java 1.1 AWT option then you should see the note above.
    • Use a different JDBC driver that will work across a network (Type 3 or 4). We recommend using the JDBC driver written by the manufacturer of the database you are using. Most databases except those from Microsoft come with JDBC drivers. If the database you are using did not supply a JDBC driver you can use a 3rd party driver. The following web page lists many JDBC drivers that are available:

    Java Security Documentation: The following are additional documents will better help to describe the Java security model and its implications on running code in a browser.

       Java Security FAQ
       Java Security Guide 
       Java Security Home
       Java Security Restrictions
  8. I am having trouble with the JDBC-ODBC driver.

    Use a different driver. We recommend using the JDBC driver written by the manufacturer of the database you are using. If the database you are using did not supply a JDBC driver you can use a 3rd party driver. The following web page lists many JDBC drivers that are available:

  9. VB uses "pass by reference" as a default, while Java has no such capability.

    We suggest changing the data type of arguments that you would like to change the value inside the function and use the new value in the calling function to a Variant. For example,

    Sub CallingSub()
      Dim intRef as Integer
      test intRef
      Debug.Print intRef
    End Sub
    Sub test(i as Integer)
      i = 3
    End Sub
    Change to:
    Sub CallingSub()
      Dim intRef as Variant
      test intRef
      Debug.Print intRef
    End Sub
    Sub test(i as Variant)
      i = 3
    End Sub
    The following would be generated:
    void CallingSub()
      Variant intRef = new Variant();
      test( intRef );
      System.out.println( intRef );
    void test( Variant i )
      i.set( 3 );
  10. I am drawing on a Form/PictureBox and the drawing is not the same in Java.

    Switch the scale mode to Pixel.

  11. The generated form does not display in my Java IDE's screen builder or you get Java compilation errors from the Java IDE relating to the "import diamondedge.vb.*" statement.
    • Visual Cafe:
      1. Switch the "Java IDE" setting in the VB Converter Options dialog in the Environment Tab to Visual Cafe then regenerate the Java code.
      2. In Visual Cafe select the File->Add Component to Library. From the Open dialog select the .jar file located in the installation directory. This file has all of the components in the diamondedge.vb package.
    • JBuilder
      1. Switch the "Java IDE" setting in the VB Converter Options dialog in the Environment Tab to JBuilder then regenerate the Java code.
      2. In JBuilder select the File->Open file menu item. From the Open dialog select the .jpr file that was generated along with the Java source.
      3. Select the Project->Project Properties menu item. Then select the Required libraries tab.
      4. Select the diamondedge entry and press the Edit button.
      5. Press the Add button to add class files then select the vbc.jar file in the VB Converter installation directory. This file has all of the Java components in the diamondedge.vb and diamondedge.ado packages.
    • Others

      Look in the documentation of the Java IDE for how to add a class library. Adding the .jar file located in the installation directory to the IDE is usually the easiest way to get your project compiling and running in another IDE.

  12. When using VB Converter in non-Latin based languages such as Japanese, the text in the report window may not be readable.

    You can change the font used in the window to a different font by changing a setting in the VBConverter.ini file. Open the VBConverter.ini file found in your windows directory using Notepad. Add the following line underneath the line [VBConverter]:
    ReportFontName=MS Gothic