article

Do you know that you can call Java classes from Visual Basic ??

Email
Submitted on: 1/2/2015 7:53:00 PM
By: foxsermon (from psc cd)  
Level: Intermediate
User Rating: By 13 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2)
Views: 6314
 
     Do you know that you can call Java classes from Visual Basic ?? well, that's not a fair tale anymore, it's possible. let me guide you through this adventure. Firts at all, we need a Java class, Here you will find an example: Java Code //************************************************** public class MyTest { public int myfunction(int value1, int value2) { return value1+value2; } } //*************************************************** Compile it i.e. javac MyTest.java and when you get MyTest.class file, you must register it for this you will need Microsfot SDK for Java you can download from this link http://www.microsoft.com/java/download/dl_sdk40.htm when you have downloaded and installed. include it on Path variable enviroment just do it using Command Ms-DOS set path=%path%;C:\Program Files\Microsoft SDK for Java 4.0\bin(this path could change) then you must register our MyTest.class file. you should do it using javareg.exe file from Microsoft SDK for Java i.e. javareg /register /class:MyTest /progid:MyTest if everything is well-done then you should see a MessageBox displayed with Succesfull register Class message. Otherwise, you must check the correct spelling on the command line. Now, the next step, copy the new Java class file that was generated. MyTest.class and paste in C:\Winnt\Java\Trustlib\ folder if you have windows 98, this folder may change. And the last step, open a New Project on Visual Basic. And paste this brief code on the Form Load event for example and run it. Set x = CreateObject("MyTest") MsgBox x.myfunction(1, 1) Congratulations !!! you can use Java Class from Visual Basic. Please do not forget to vote for this article. =)

 
				Do you know that you can call Java classes from Visual Basic ??
well, that's not a fair tale anymore, it's possible.
let me guide you through this adventure.
Firts at all, we need a Java class, 
Here you will find an example:
Java Code 
//**************************************************
public class MyTest {
public int myfunction(int value1, int value2) {
return value1+value2;
}
}
//***************************************************
Compile it
i.e. javac MyTest.java
and when you get MyTest.class file, you must register it
for this you will need Microsfot SDK for Java
you can download from this link
http://www.microsoft.com/java/download/dl_sdk40.htm
when you have downloaded and installed. 
include it on Path variable enviroment
just do it using Command Ms-DOS
set path=%path%;C:\Program Files\Microsoft SDK for Java 4.0\bin(this path could change)
then you must register our MyTest.class file.
you should do it using javareg.exe file from Microsoft SDK for Java
i.e. javareg /register /class:MyTest /progid:MyTest
if everything is well-done then you should see a MessageBox displayed with 
Succesfull register Class message.
Otherwise, you must check the correct spelling on the command line.
Now, the next step, copy the new Java class file that was generated.
MyTest.class
and paste in C:\Winnt\Java\Trustlib\ folder
if you have windows 98, this folder may change.
And the last step, open a New Project on Visual Basic.
And paste this brief code on the Form Load event for example and run it.
 Set x = CreateObject("MyTest")
 MsgBox x.myfunction(1, 1)
Congratulations !!! 
you can use Java Class from Visual Basic. 
Please do not forget to vote for this article. =)


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/22/2015 1:52:31 PMTiago Lourenço

I tried but it did not work!
In createObject occurs the exception:
-2147221231
Automation error
ClassFactory cannot supply requested class

Any idea what might be happening?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.