Jump to content
xisto Community
Sign in to follow this  
it01y2

Can Php Interact With A Visual Basic App On A Server

Recommended Posts

I've been programming in VB for ten years, can you describe what you are trying to do with a little more detail? I think it is possible to do. PM me or post back and I'll help you out.

Share this post


Link to post
Share on other sites

I was pretty sure that only ASP can interact with Visual Basic which would mean no unless you have a Windows Server for your hosting that supports ASP. I don't know really though I'm still relatively new to Visual Basic. Last I knew though it was only ASP.

Share this post


Link to post
Share on other sites

If what I think he is thinking about is right, its a simple enough concept. This is how I would approach it.

 

1. The PHP program writes some data to a file in some format.

2. The VB program constantly sees if a file is there for it to read.

3. The VB program processes it and puts the result back in another file.

4. The VB program deletes the original file. (so that the PHP program can create a new one later)

5. The PHP program opens the file the VB program wrote, and has the results.

6. The PHP program deletes the file.

 

Another way I could see this working is using a Winsock control in the VB program, and then using the socket functions of PHP to connect to it and process the request. This technique seems more practical now that I think about it. Here is how I would write this one.

 

1. The VB program is constantly listening for connections.

2. The PHP program connects to the IP address 127.0.0.1 (your computers IP) or localhost

3. The PHP program sends what needs to be done to the VB one.

4. The VB program returns the data and closes the connection.

 

The technique I wrote above seems more practical because it can handle multiple requests, instead of just one file. It probably is slightly faster (by a very small amount) because the computer doesn't need to write to the hard disk constantly.

 

The opposite, using VB and calling a PHP program can be done. I am currently writing a game that will use this technique for match making. It works like this.

 

1. You have a PHP program that does a certain function and accepts its data through GET

 

<?PHP$variable = $_GET['mode'];// if you have the url, whateversite.com/cgi-sys/suspendedpage.cgi?mode=1, the $variable = 1.PHP?>

2. The VB program uses the Inet control, and sends the request.

3. The PHP program would output its result using the print() or echo() variable.

 

 

I hope this helps you guys out a lot. I'll be happy to guide you along and answer any other questions you have.

Share this post


Link to post
Share on other sites

You might find this question strange, but well, i'm a noob.. So it is possible to write programs in C, VB, put them on server and make them "work" and intereact to PHP ?!Any good tutorials on that, or any good simple free programs that do the same? (open source possibly...)

Share this post


Link to post
Share on other sites

I also thought ASP was the only language that could interact with VB. I may be mistaken though.Have a great day!-Tom.

Share this post


Link to post
Share on other sites

ASP is written in a language that has BASIC as it's foundation...

Traditionaly, Microsoft IIS web server, was used to host ASP pages, and Apache was used to host PHP pages... There is a plugin (or module) for IIS and PWS that allows processing of PHP, but it's not that good, and it is very limiting in power, i believe PHP works only in CGI mode... Anyways, not to stray from the topic...

There are few ways to connect VB with PHP scripts...

Least efficient is through file, as ghostrider said... It's inefficient, since it consumes much CPU time, and thus we'll forget about it (I tried similar approach once, for connecting VB program, with QB program... Not good)

Second method is by using MySQL for exchange of information... Connect VB to MySQL server, connect PHP script to MySQL server, and voila... Easy setup of information... This could be a good method, I'm using it for displaying some info on my site... May be non-efficient though, if too frequent queries should occur...

Third method, again mentioned by ghostrider, involves using socket functions of PHP, to connect it directly to your VB application... A good method, probably the best option... The second part of it, transmitting data to PHP script, I would use POST method, not GET... First, GET metod has a limitation to its length (2K I believe), and POST is used to transfer large quantities of data...

Here, I'm including code used to send data via POST methid, using Microsoft Internet Controls OCX... Just add it to your project, and use the following code:

Public Sub SendData(ByRef wb As WebBrowser, ByVal Params As String)Dim vPost	 As VariantDim vFlags	As VariantDim vTarget   As VariantDim vHeaders  As VariantDim aByte()   As ByteDim i		 As Long' Params are in the following format <param-name>=<param-value>[&<param-name>=<param-value>[&...]]PackBytes aByte(), ParamsvPost = aBytevFlags = &H2 Or &H4 Or &H8 Or &H10vHeaders = "(anti-spam-(anti-spam-content-type:)) application/x-www-form-urlencoded" & vbCrLfwb.Navigate "http://your-server/php-script.php", vFlags, vTarget, vPost, vHeadersEnd SubPrivate Sub PackBytes(ByRef ByteArray() As Byte, ByVal PostData As String)Dim i As LongDim j As LongDim c As Stringj = Len(PostData) - 1If j < 0 Then Exit SubEnd IfReDim ByteArray(j)For i = 0 To j c = Mid(PostData, i + 1, 1) If c = Space(1) Then	c = "+" End If ByteArray(i) = Asc(c)NextEnd Sub

This code is sure to send data to your script, via POST methid. You can ofcourse parse resulting webpage, and control your VB application taht way too...

If you want, I can send you a DLL that you can use to connect with MySQL server, and read and write do MySQL databases, just PM me...

Hope this helped a bit...

Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do that (sadly ;)), and I'm sure you won't be setting up PHP support on IIS or PWS, your applicayion would have to run on a separate server, running Windows, probably the best method would be to use combination of socket functions in PHP, and, depending on update rate you need, MySQL, or POST method of returning data to your script...

Cheers ;)

Share this post


Link to post
Share on other sites

Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do that

i'm kinda noob programmer, but i found this post very interesting. i didn't remember that VB aps can be run only in windows environment so i posted this question. i won't learn Vb but C and C++ since it can be compiled both for linux and windows environments.
My logic suggests me that C programs could be written to interact with php, and it's kinda logical couse php is written in C (i guess). So if at any time of my life i want to make an application in C to interact with PHP what would be the right way to do that!? It is so soon to talk about that for me, but you don't need to answer right now, and maybe there is more ppl interested in this subject so you could writte anyway.
What is the difference between running PHP as Module or as CGI script, how is all of that conected with basic root program of PHP (what is root program of PHP, how can i start modifiying php, and is it smart to do that, just for fun, and for learning purposes)
thanks

Share this post


Link to post
Share on other sites

Dear it01y2 You can transfer Data between VisualBasic and PHP via URL Like this :

$Somename = $_GET['someurl name'];
or
$Somename = $_POST['someurl name'];
But its better make code with GET Method
In visualBasic You can generate one HTML page and form and make it for send data form game to server
i read Galahad's post You can use it him code for vb

Share this post


Link to post
Share on other sites

I've been programming in VB for ten years, can you describe what you are trying to do with a little more detail? I think it is possible to do. PM me or post back and I'll help you out.

hi Ghostrider,u seemed to be very experienced in programming, so let's straight to the point,
now i'm building a php webbased application, n thinkin about goin to integrate it with an sms feature,
got the device, and unfortunately the API provided by the device is written in VB, which is something new for me,
my question is, is it possible to call a VB module in php script? i know the most common answer is not possible,
because VB is on the server side, and php is on the client side, but i'm sure there is a way, i just dun know how.
a brief explanation about my program (pretty simple actually):
there is a php page, with the detailed info about a product (type, weight, price, etc). n down below, there is a button "Interested",
what i want the program do is, when the user click that button, the php store an information into DB (MySQL), and at the same time, it trigger the VB module, to retrieve the same data and initiate the GSM modem to send sms containing the data. so most likely the data is just goin to be a string sayin "this user is interested in this product , bla bla bla..".

i hope u could briefly imagine and eventually can help me with this.
many thanks in advance though,

Share this post


Link to post
Share on other sites

I am currently making a game. And I want to use a command through php to ineract with a visual basic app on my server. Is it possible? and how?

Hi!

It is indeed possible for PHP and Visual Basic to interact, but it is up to you to decide how you want to do it. Here are a couple of ways you can do this:
1. Write to a file using one language and read using the other
2. Create a webservice on one platform that you can call from the other
3. Use TCP/IP sockets for communication between the two
4. Use a message broker application or a message queue - MSMQ is available with MS Windows
5. Store and read values from a database

Most of the applications that I work with use a database for storage so I simply have to create a database trigger to copy the values across the applications' tables.

Regards,
Nitin
Edited by k_nitin_r (see edit history)

Share this post


Link to post
Share on other sites

hi Ghostrider,u seemed to be very experienced in programming, so let's straight to the point,
now i'm building a php webbased application, n thinkin about goin to integrate it with an sms feature,
got the device, and unfortunately the API provided by the device is written in VB, which is something new for me,
my question is, is it possible to call a VB module in php script? i know the most common answer is not possible,
because VB is on the server side, and php is on the client side, but i'm sure there is a way, i just dun know how.
a brief explanation about my program (pretty simple actually):
there is a php page, with the detailed info about a product (type, weight, price, etc). n down below, there is a button "Interested",
what i want the program do is, when the user click that button, the php store an information into DB (MySQL), and at the same time, it trigger the VB module, to retrieve the same data and initiate the GSM modem to send sms containing the data. so most likely the data is just goin to be a string sayin "this user is interested in this product , bla bla bla..".

i hope u could briefly imagine and eventually can help me with this.
many thanks in advance though,



Hi Guys...
I have a similar requirement to call VB applications through PHP pages...Please let me know if I can call VB or a .Net application using PHP web pages.

TIA
-Sam49-

Share this post


Link to post
Share on other sites

Sure you can! Most platforms support some way of getting method calls and data across the platform divide, and PHP and the .NET framework (Visual Basic, or any other language that can generate Microsoft Intermediate Language code and can make calls to the .NET framework classes).Web services can be used to communicate across different platforms. You can use PHP to create web services (perhaps using the nuSOAP?) and can then consume those web services using Visual Basic. Microsoft Visual Studio makes working with web services a breeze - it's just like making a method call to a regular class method. You can also do the reverse by creating a web service in Visual Basic and consume the service through PHP. There are different libraries/extensions that you can use within PHP to create and consume web service and there are trade-offs that you have to make for each one so you might want to take a look at which one is right for you. The nuSOAP library enables you to create and consume web services using PHP calls. In additional, you can also generate the web service descriptor (WSDL) automatically so the web service description always matches the service that you are building. The downside of using nuSOAP is that it is not as actively maintained. The PEAR-SOAP library is also PHP based and is comparable to nuSOAP. The SOAP extension for PHP requires server-side configuration/installation and therefore may not be an option if your web hosting service does not provide the extension, however the PHP SOAP extension is also the quickest since it is built using compiled C code.Making calls across different platforms generally involves overhead. In fact, if you are making web service calls, there's an overhead even if you are using the same platform on both ends due to the conversion to XML.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.