-   Programming (
-   -   converting vb6 code to python (

mrobertson 05-31-2005 08:01 AM

converting vb6 code to python
I have the following server code wrote in vb6:

Option Explicit
Dim sServerMsg As String

Private Sub Form_Load()

'Address must be input as a string
Dim Address As String

'Set the address equal to the web address of the pickle line camera
Address = "http://pl7cam2/operator/image_test.shtml?camNo=1&squarepixel=0&resolution=4CIF&compression=35&color=yes&rotation=0&overlayim age=0&overlaypos=0x0&date=1&clock=1&text=1&textstring=%237%20Pickle%20Exit%20Camera&textcolor=white& textbackgroundcolor=black&textpos=top&duration=NaN&fps=0kkkkkkkkkkkkkkk"

'tells the browser window to display whatever is on the web page of the address
WebBrowser1.Navigate Address

'The port number is arbitrary.
' it's best to use a fairly high number
' because the low numbers are used for
' standard services: 21 for FTP, 23 for telnet,
' 80 for HTTP etc...
Winsock1(0).LocalPort = 10119

'start listening for a connection


'Define the message and show the connection in the list box
sServerMsg = "Listening to port: "
List1.AddItem (sServerMsg)
End Sub

Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)

'the winsock control has to be in a closed state
' before it can do anything else. (like accept a connection)

'Let the winsock close

'accept the connection request
Winsock1(Index).Accept requestID

'Define the message and display it in the list box
sServerMsg = "Serving client!"
List1.AddItem (sServerMsg)
End Sub

Private Sub Winsock1_Close(Index As Integer)

'When the other end has closed the connection,
' close server end too

'to continue listening for another connection

'show the connection in the list box
sServerMsg = "Listening to port: "
List1.AddItem (sServerMsg)
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)

Dim strTemp As String
'Dim strTemp2 As String
Dim a As Integer
'This event fires when the process on the other end of the connection(i.e the client)
'sends data

'retreive data from socket
Winsock1(Index).GetData strTemp
'Winsock1(Index).GetData strTemp2

'The following code separates each part of the string based on the comma
'that is present in the incoming string and parses it out into its
'respective textbox

a = InStr(strTemp, ",")
txtcoilid.Text = Left(strTemp, a - 1)

'after the first parse you must refine the string as everthing after the comma and
'repeat the process throughout the entire string
strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtwidth.Text = Left(strTemp, a - 1)

strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtlinespeed.Text = Left(strTemp, a - 1)

strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtexitcoillength.Text = Left(strTemp, a - 1)

End Sub

It has been suggested to me that python is the best anguage to write this program in being that it needs to be on a linux machine. Can anyone offer suggestions or information on translating this code to python or steps to rewrite in python. I have never used linux or python before and am open to any suggestions.

meonkeys 06-02-2005 01:17 PM

A good place to start would be the Python tutorial.

What does this VB code do? If you want someone to write the code for you, you probably have to pay them. :) I'd suggest Google Answers if this is the route you want to take.

azucaro 06-02-2005 01:27 PM

First and foremost, welcome to Linux and Python! Python is a great language, and very easy to learn if you've programmed before (in my opinion).

Since you are open to suggestions, I have a few:

-I don't know of any documents on translating code from VB to Python, so I apologize for not being able to help you there. Fortunately VB is pretty easy to read - I think that fact will help you greatly.

-I'd recommend for learning the basic ins and outs (it is a free book in many formats). If you want to jump into more deep stuff, I would just browse between the different reference manuals found on In particular, if you go to that site and look at the python library reference ( I think chapter 7, section 2 is what you are looking to imitate. That is the chapter on how to do socket stuff.

-I'd also recommend the eric3 IDE for python. It is pretty good. It can be found at

I hope I helped a little bit - good luck!

All times are GMT -5. The time now is 12:15 PM.