Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vb6 type to python

26 views
Skip to first unread message

luca72.b...@gmail.com

unread,
Nov 30, 2022, 6:56:56 AM11/30/22
to
Hello i have a byte file, that fill a vb6 type like:
Type prog_real
codice As String * 12 'hsg
denom As String * 24 'oo
codprof As String * 12 'ljio
note As String * 100
programmer As String * 11
Out As Integer
b_out As Byte 'TRUE = Sec FALSE= mm
asse_w As Byte '3.zo Asse --> 0=Z 1=W
numpassi As Integer 'put
len As Long 'leng
p(250) As passo_pg
vd(9) As Byte 'vel.
qUscita(9) As Integer 'quote
l_arco As Long 'reserved
AxDin As Byte 'dime
End Type

How i can convert to python

DFS

unread,
Nov 30, 2022, 1:07:39 PM11/30/22
to
You don't need to declare variable types in Python.

I don't do Python OO so someone else can answer better, but a simple
port of your VB type would be a python class definition:

class prog_real:
codice, denom, codprof, note, programmer
AxDin, b_out, asse_w, vd, Out, numpassi, qUscita
len, l_arco, p

important: at some point you'll have trouble with a variable named
'len', which is a Python built-in function.

For a visual aid you could label the variables by type and assign an
initial value, if that helps you keep track in your mind.

class prog_real:
# strings
codice, denom, codprof, note, programmer = '', '', '', '', ''

# bytes
AxDin, b_out, asse_w, vd = 0, 0, 0, 0

# ints
Out, numpassi, qUscita = 0, 0, 0

# longs
len, l_arco = 0, 0

# misc
p = ''

But it's not necessary.

To restrict the range of values in the variables you would have to
manually check them each time before or after they change, or otherwise
force some kind of error/exception that occurs when the variable
contains data you don't want.


# assign values
prog_real.codice = 'ABC'
print('codice: ' + prog_real.codice)
prog_real.codice = 'DEF'
print('codice: ' + prog_real.codice)
prog_real.codice = 123
print('codice: ' + str(prog_real.codice))


And as shown in the last 2 lines, a variable can accept any type of
data, even after it's been initialized with a different type.

b = 1
print(type(b))
<class 'int'>
b = 'ABC'
print(type(b))
<class 'str'>


Python data types:
https://www.digitalocean.com/community/tutorials/python-data-types

A VB to python program:
https://vb2py.sourceforge.net

DFS

unread,
Nov 30, 2022, 2:03:52 PM11/30/22
to
On 11/30/2022 1:07 PM, DFS wrote:
> On 11/30/2022 6:56 AM, luca72.b...@gmail.com wrote:
>


> I don't do Python OO so someone else can answer better, but a simple
> port of your VB type would be a python class definition:
>
> class prog_real:
>     codice, denom, codprof, note, programmer
>     AxDin, b_out, asse_w, vd, Out, numpassi, qUscita
>     len, l_arco, p


Sorry for bad advice - that won't work. The other class definition that
initializes the variables does work:

Weatherby,Gerard

unread,
Nov 30, 2022, 3:37:50 PM11/30/22
to
0 new messages