1

I would like a simple answer as to how to press a button on an Android (using basic4android), and get a VB6 program to accept the data and respond. Both the Android and the computer running the VB6 program are connected to the same WiFi.

Erel gives me a URL, but after reading for hours, I can't seem to find a SIMPLE example of the Android code and the VB6 code.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Dan Clark
  • 11
  • 1
  • 2
  • There are two examples provided with the [Network library](http://stackoverflow.com/q/1326258/62576). One (NetworkExample1) shows a client application; the other (NetworkExample2) shows a server application. That gives you both halves of the code for Android. Search StackOverflow for VB6 code for TCP/IP communication, and you should find lots of sample code for that side. – Ken White Nov 19 '12 at 02:15

2 Answers2

1

I don't know basic4android, but a simple VB6 project for on the computer can be as follows :

'1 form with :
'  1 textbox : name=Text1
'  1 winsock control : name=Winsock1

Option Explicit

Private Sub Form_Load()
  Text1.Move 0, 0, ScaleWidth, ScaleHeight 'position the textbox
  With Winsock1
    .LocalPort = 5001                      'set the port to listen on
    .Listen                                'start listening
  End With 'Winsock1
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
  With Winsock1
    If .State <> sckClosed Then .Close     'close the port when not closed (you could also use another winsock control to accept the connection)
    .Accept requestID                      'accept the connection request
  End With 'Winsock1
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim strData As String
  Winsock1.GetData strData                 'get the data
  ProcessData strData                      'process the data
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  MsgBox Description, vbCritical, "Error " & CStr(Number)
End Sub

Private Sub ProcessData(strData As String)
  Text1.SelText = strData                  'show the data
End Sub

Some remarks :

This project uses the listening winsock control to accept the connection, so after that you are not listening to new connection requests anymore. When you plan on sending large chunks of data you should probably buffer the data, and process it when it's complete.

Hrqls
  • 2,944
  • 4
  • 34
  • 54
  • Thanks so much. It seems that there a lot more details that I am missing, since I've spent a couple of days with Basic4Android, and I'm not even close to getting how to do (what I think should be) a simple task. I find the people on stackoverflow to be helpful, the people with Basic4Android . . . . well, let me sum it up, 5 messages to people there . . . . no responses. – Dan Clark Nov 21 '12 at 16:38
  • @DanClark : could you post what code you have so far with basic4android? and what results you got? – Hrqls Nov 22 '12 at 14:15
  • I always got this message from the Droid "these are not the droids you want." – Dan Clark Nov 23 '12 at 17:51
  • Sorry, different situation. This is the message that I got from the droid running the B4A software "server not available". The code won't fit here, I'll have to zip it and send it to your email. Thanks! – Dan Clark Nov 23 '12 at 18:08
0

On VB6 side use MSComm control serial communication via one of the COM ports. OnComm will trap the receive event. A blue tooth converter can be hooked up to the port to handle wireless communication. https://msdn.microsoft.com/en-us/library/aa259393(v=vs.60).aspx

On B4A side use the Serial library to connect with a Bluetooth device using RFCOMM, a virtual serial COM port. https://www.b4x.com/android/help/serial.html

Gina Kalani
  • 128
  • 1
  • 9